Package: scrim
Ascrimis a piece of cloth that’s opaque until lit from behind. Like a scrim,Scrimprovides opaque scripts to wrap python command line tools and a transparent python api to send shell commands up to the user’s shell.Why would I need Scrim?When writing command line tools in python, changes to–let’s say–environment variables, don’t persist when the python process exits. This means we can’t write certain types of tools in pure python, we need to revert to our shell’s scripting language instead. That’s why tools like virtualenvwrapper are written in shell scripting languages instead of pure python.Scrimprovides opaque shell scripts that wrap your python cli, so you can continue writing the interfaces for your python programs in python.How does it work?In this diagram theScrim Scriptis the opaque shell script provided by the scrim package. Following along with the diagram, theUsercalls the cli command. This invokes theScrim Scriptwhich sets these environment variables:SCRIM_SHELL- name of the shell process (powershell.exe, cmd.exe)SCRIM_PATH- path to temp script which python will writeSCRIM_SCRIPT- full path to the Scrim ScriptSCRIM_AUTO_WRITE- whether or not to automatically write the temp script when python exits.Then theScrim Scriptinvokes the actualPython CLIpassing all arguments from theUser. ThePython CLIcan now use the scrim api to append commands to a list. When the python program exits, the list of commands is written to a temporary script file. TheScrim Scriptnow continues and executes the temporary script file if it exists. Finally theScrim Scriptremoves any temporary files and unsets the above environment variables.QuickstartFirst addScrimscripts to your project usingScrim’scli.> cd mytool
> scrim add --entry_point pymytool

Creating scripts for: pymytool
    Created bin/mytool.bat
    Created bin/mytool.ps1
    Created bin/mytool.sh

Add the following section to your package setup:

scripts=[
    'bin/mytool.bat',
    'bin/mytool.ps1',
    'bin/mytool.sh'
],Assume thatmytoolis a python project containing a setup.py file. Here we’ve providedscrim addwith the name of the entry_point to our python cli. If you’ve got multiple entry_points already defined in your package you can use:> scrim add --all_entry_points
...This will addScrim Scriptsto each console_script you’ve defined in entry_points.Now that you’re project has Scrim added to it let’s take a look at the python side.import click
from scrim import get_scrim
scrim = get_scrim()

@click.command()
def mytool():
    scrim.set_env('MYTOOL', "Hello World!")

if __name__ == '__main__':
    mytool()We useget_scrimto get an instance ofScrim. Then we append commands to the scrim and those will be written to a shell script when python exits. After python exits thescrim scriptwill check to see if a shell script exists and execute it. In this case the environment variableMYTOOLwill be set toHello World!.Installing a library that uses ScrimWindowsA simplepip installwill do you. The scrim scripts
will be picked up normally from your command line, you won’t even know they
are there!Unix SystemsIn addition to your standardpip installyou also have to source the scrim
script after installation. It usually ends up in one of these locations:{virtualenv_path}/bin/{entry_point}.sh/usr/local/bin/{entry_point}.shSupported ShellsbashcmdpowershellTo DoMore tests…Support more shells: fish, csh, zsh…Add more commands to theScrimExtend scrim cli to better support a variety of entry_points scenariosCurrently we only capturesetupentry_points when defined as a
dict.We also only support entry_points beginning with py.Parse setup.cfg in addition to setup.pyTestsUse nose to manually run the scrim test suite.> nosetests -v -s --with-doctest