python-main-wrapper
Set up global environment and run another script within, ala pdb, profile, etc
Use main-wrapper either as a command-line script or as a library to make Python scripts that set up or change some global Python environment and then run another script within that environment. It seeks to combine into one library all the gloss and polish of other Python software that does this, such as using python -m with pdb and profile in the standard library or the coverage package’s command-line run command.
Installation
Install using any tool for installing standard Python 3 distributions such as pip:
$ sudo pip3 install main-wrapper
Usage
You may use this package either as a library in your code that needs to wrap another script or as a command-line script.
To use as a library, use the provided decorator to wrap your function that sets up the global environment you need the script to be run in:
import logging
import argparse
import mainwrapper
parser = argparse.ArgumentParser()
parser.add_argument(
"--level",
default="INFO",
help="The level of messages to log at or above",
)
@mainwrapper.wrap_main(parser)
def main(level=parser.get_default("level")):
"""
As an example, this function will set up logging at level INFO.
"""
logging.basicConfig(level=getattr(logging, level))
The changes to Python’s global execution environment that support running the wrapper function and the final script are also cleaned up upon completion, so it should be possible to use this library to execute multiple scripts in the same process as if they were run independently.
See the command-line help for details the options and arguments for using this package as a command-line script:
$ usage: python-main-wrapper [-h] wrapper script Set up global environment and run another script within, ala pdb, profile, etc.. Both script arguments may either be a path to a Python script, a Python module or package to be run in the same manner as Python's `-m` option, or a setuptools `path.to.import:callable` entry-point. positional arguments: wrapper A Python script that sets up the environment script The Python script to run within the wrapper's environment optional arguments: -h, --help show this help message and exit
Note that this package uses argparse.ArgumentParser.parse_known_args under the hood and as such be sure to use it’s support for the -- convention to separate arguments and options to be passed to the wrapped script:
$ python-main-wrapper site site:_script --help
...
site.py [--user-base] [--user-site]
Without arguments print some useful information
With arguments print the value of USER_BASE and/or USER_SITE separated
by ':'.
Exit codes with --user-base or --user-site:
0 - user site directory is enabled
1 - user site directory is disabled by user
2 - user site directory is disabled by super user
or for security reasons
>2 - unknown error
Motivation
I found myself writing such wrapper scripts repeatedly over the years and kept struggling to remember how I did it last time. I made this package to capture all that knowledge and to have one place to put improvements as I discover them.
Metadata
Release files for main-wrapper 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| main-wrapper-0.1.1.tar.gz | 8.7 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| main_wrapper-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 16.6 kB
Release files / main-wrapper-0.1.1.tar.gz
| Download URL | main-wrapper-0.1.1.tar.gz |
|---|---|
| Size | 8.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
73e9b9311baf2c80a54a62fcf40dfb8a960290afe40da7927066adb97d53034b
|
|
BLAKE2b-256 checksum How to use checksums |
58b99747f029c3afe704be9d47a80f22c4e2bf601ffafac72b9913b6654130dd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7
|
Release files / main_wrapper-0.1.1-py3-none-any.whl
| Download URL | main_wrapper-0.1.1-py3-none-any.whl |
|---|---|
| Size | 7.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
46f338144ccaf6e7035c93d8cd2e950e11b4d2118b551f8148611e6d73ba1d9c
|
|
BLAKE2b-256 checksum How to use checksums |
b32f7a7d13d2f9f84a82b46fb11f69292968696781c7167e6824c79fcfe7bf77
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7
|
Security for main-wrapper 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.