Package: setupext
setupext========This module contains utility methods for easing writing pythoninstallation scripts (setup.py).Building C extensions: See setupext/doc/setup-sample.py-  Specify location of C sources-  Specify shared library name-  Specify specific C source files to be compiledBundle additional files with package - using get\_dir\_tree()-  Include and INSTALL C sources under python module directory-  Include README, LICENSE ando ther files under python module directoryAdd a LIST of shell commands or python callables to execute at differentstages of installation:-  build-  build\_clib-  build\_ext-  build\_py-  build\_scripts-  install\_data-  install\_lib-  install\_headers| By setting values in setupext.config, a LIST of shell commands and/orpython code (callables) can be run before or after each ofthese stages.Note that you need to include this package within your package if youwant| to use the trigger functionality.To only use get\_dir\_tree(), just copy that function into your setup.pyASSUMPTIONS AND PACKAGE LAYOUT==============================| This setup.py assumes following layout.| toplevel --> python package name::This directory├── setup.py - this file├── setupext.py - required in this directory├── LICENSE - typical for github etc but not required│       Hard-link to a file under data_dirX to keep at top level│       and also install the same file│├── README.rst - typical for github etc but not requiredt│       Hard-link to a file under data_dirX to keep at top level│       and also install the same file│└── toplevel - python package name├── toplevel.__init__.py├── toplevel.module1.py├── toplevel.module2py│├── subpkg1│   ├── subpkg1.module1.py│   ├── subpkg1.__init__.py│   └── subpkg1.module2.py│├── data_dir1 - e.g. c_files│   ├── data_dir1_file1│   ├── data_dir1_file2│   └── data_dir1_file3│└── data_dir2 - e.g. doc├── data_dir2_file1 - e.g. LICENSE└── data_dir2_file2 - e.g. README.rstIf your layout is different, you may need to make changes to thefollowing:-  Under PACKAGE DATA:-  Set toplevel to module (dir) under which:-  C Extension shared lib if any will be installed-  Additional data if any (data\_dirs) will be installed-  Setting packages-  Under ADDITIONAL keyword args to setup()-  Add py\_modules=[] to ADDL\_KWARGS-  Under C EXTENSION DETAILS - IFF your package includes a C extension:-  Setting libpath-  Setting c\_src\_list-  Setting ext\_modulesC EXTENSION DETAILS===================Put the C files in a dir under toplevel so that the C files can also beinstalled using data\_dirs (see ADDITIONAL DATA FILES)For simple cases with a single extension, you should only need to set:::c_dir-->str: directorylibname-->str: shared library filename without '.so'c_src_files-->list of str: C source filenames within c_dirADDITIONAL DATA FILES=====================I use package\_dir and package\_data to specify installing additionalfiles that are:-  Files in directories under toplevel-  Wouldn't be AUTOMATICALLY included or installed because of:-  py\_modules directive-  packages=find\_packages() directive-  C source required for an extensionExamples:-  Ship and INSTALL C source under the module directory-  Ship and INSTALL any other files - e.g:-  Documentation-  LICENSEWith this method, we get following features:-  Do NOT require MANIFEST.in-  Do NOT require include\_package\_data directive-  No code required in setupext.CustomInstallData classPreparatory steps:-  | If package includes a C-source extension:|  - Put C source in a dir under toplevel|  - Set c\_dir above to the name of the dir UNDER toplevel-  Create other directories with data under toplevel-  If you want files in TOP-LEVEL (above toplevel) included, HARD LINKthose FILES to directories under toplevel - e.g.:-  LICENSE-  README.rst-  Alternatively, hard-link these files FROM the directory undertoplevel to the top-level so that these files can be visible at toplevel (e.g. in github)-  set data\_dirs to LIST of directories under toplevel that you want toincludeCUSTOM STEPS============To add a LIST of shell commands or python callables to execute atdifferent steps during installation, modify setupext.config as follows:::- setupext.config is a DICT with keys representing installation steps- The steps supported are in setupext.known_steps (list of str)- Each element of setupext.config is itself a DICT with following keys:- 'pre': dict- 'post': dict'pre' and 'post' dicts can optionally contain the following keys:cmdlist-->listeach element must be one of:str: A shell command to execute with subprocess.callThe command is executed with shell=TrueNo additional cmdline parameters are addedcallable: Will be called with following parametersargs=(caller): caller is instance of calling classTypically instance of distutils.cmd.Commandpre_post=x: x in ['pre', 'post']callable can retrieve step name usingargs[0].get_command_name()if cmdlist is not set or is [] or None, the correspondingpre / post dict is ignoredsee pydoc setupext.run_in_ordershow_output-->boolean: Display stdout of shell commandsignored for callablesDefault: trueshow_err-->boolean: Display stderr of shell commands (on stderr)ignored for callablesDefault: trueignore_err-->boolean: Continue to next element of cmdlist ifshell command or callable raises an exception orshell command returns a non-zero return codeDefault is stop processing cmdlist (False)show_output, show_err and ignore_err apply to ALL elementsof cmdlistcmdlist under 'pre' key is executed BEFORE the correspondinginstallation stepcmdlist under 'post' key is executed AFTER the correspondinginstallation stepcallables must be defined at time of executing setup.pyNote that cmdlist will be executed ONLY IF correspondingstep is executed - e.g.:- if byte-compiling is disabled, install_lib won't run- If package doesn't define a C extension, build_ext  won't runEXAMPLE:========| Assume you want to do the following:|  - Run shell\_command\_1 and callable\_1 BEFORE|  installation build (step: build) begins|  - Ignore and hide errors running command at build.pre step|  but show outputs|  - Run shell\_command\_2 after build\_ext step is completedSteps:------.. code:: python# Set to True to get DEBUG on stderr when each step is called# Debug messages will appear even if you do not setup custom commands# to execute for the stepsetupext.trace_triggers = False# Set shell_command_1, shell_command_2# shell_command_1 Will return a non-zero return codeshell_command_1 = 'echo "Starting build"; uname --nosuchoption'shell_command_2 = 'echo "build_ext completed"'# define a callabledef mycallable(*args, **kwargs):sys.stderr.write('%s %s\n' % (args[0].get_command_name(),kwargs.get('pre_post', 'Unknown')))# Now setup setupext.configsetupext.config['build']['pre']['cmdlist'] = [shell_command_1, mycallable]setupext.config['build']['post']['ignore_err'] = Truesetupext.config['build']['post']['show_err'] = False# shell_command_1 will produce stderr output and return non-zero code# but stderr will be suppressed and mycallable will still be executedsetupext.config['build_ext']['post']['cmdlist'] = [shell_command_2]# stderr if any from shell_command_2 will be shown (on stderr)