package_script¶
Package a script together with all its dependencies.
For example, on a remote computer I know for a fact that numpy and scipy are available, but I cannot or cannot easily gaurantee that module x will be installed. I want to run script MyScript.py on this remote machine, but it depends on module x. package_script() will recurse through MyScript.py and prepend module x (and all of module x’s dependencies down to numpy, scipy, and default python modules, assuming I’ve set existing_modules=[‘numpy’, ‘scipy’]).
-
mr_utils.utils.package_script.
get_imports
(filename, existing_modules=None)[source]¶ Removes import statements and gets filenames of where imports are.
-
mr_utils.utils.package_script.
get_std_lib
()[source]¶ Get list of all Python standard library modules.
-
mr_utils.utils.package_script.
package_script
(filename, existing_modules=None)[source]¶ Package a script together with all dependencies.
Parameters: - filename (str) – Path to Python script we wish to package.
- existing_modules (list, optional) – List of terminating modules.
Returns: Bundled python script with only existing_modules dependencies.
Return type: str
Notes
“Terminating module” is a module we assume is available on the machine we want to run the packaged script on. These are python’s built-in modules plus all existing_modules specified by caller.