python-runner (part of python-commons) is a configuration management utility designed to simplify application setup by aggregating configurations from multiple sources.
The core of python-runner is the Application class, which automates the following process:
- Argument Parsing: It uses a custom
ConfigandArgumentstructure to parse command-line arguments (usingargparseunder the hood). - Configuration Discovery: It searches for configuration files (
application.json,application.yml,application.yaml) in a prioritized list of paths:- Static paths:
./test/resources,./resources. - Environment variables: Defined in
SMI_CONFIG_PATHS. - Command line: Provided via
--smi-config-paths.
- Static paths:
- Profile Support: It supports profiles (e.g.,
dev,prod). If profiles are active, it also looks for profile-specific files likeapplication-dev.yaml. Profiles are loaded from environment variableSMI_PROFILESor command line--smi-profiles. - Hierarchical Merging: All discovered configuration files are parsed (JSON or YAML) and merged into a single
merged_configdictionary. Files found later in the search order (CLI > Env > Default) override values from earlier ones. - Placeholder Interpolation: It automatically replaces placeholders like
${MY_VAR}in configuration files with values from environment variables. - Application Naming: It determines the application name based on CLI arguments, environment variables, or the merged configuration itself.
- Centralized Configuration: Provides a unified way to manage settings across different environments without hardcoding values.
- Environment Awareness: Seamlessly integrates with environment variables for secrets and environment-specific overrides.
- Flexibility: Supports multiple formats (JSON, YAML) and multiple source types (Files, Env, CLI).
- Boilerplate Reduction: Eliminates the need to manually write code for parsing arguments, reading files, and merging nested dictionaries for every new project.
# Win
py -3.14 -m venv ./.venv
# *nix
python -m venv ./.venv
# Win
.\.venv\Scripts\activate
# *nix
source ./.venv/bin/activate
python -m pip install --upgrade pip
pip install -r requirements.txtFor developing depending on the project / module, dependency can be added into requirements.txt as:
python-commons @ file:///C:/sources/setmy.info/submodules/python-commons
pip install --upgrade behave pyyaml wheel twine pip_audit bandit"File" → "Settings" → Python Integrated Tools → Default test runner: Unittest
Running tests has a problem: a working directory has to be set for tests.
python -m unittest discover -s ./test/info/setmypython -m unittest discover -s ./test/info/setmy -p it_*.pybehavepython -m unittest discover -s ./test/info/setmy && python -m unittest discover -s ./test/info/setmy -p it_*.py && behaveThe project uses popular Python security tools to ensure dependency safety and code quality.
This tool checks installed packages against known vulnerability databases (PyPI Advisory Database). It is the Python equivalent of Java's dependency check.
Run check:
pip-audit -r requirements.txtBandit is a tool designed to find common security issues in Python code.
Run check:
bandit -r smi_python_commons# Win
set NAME=smi_python_commons
set VERSION=0.4.0
# *nix
NAME=smi_python_commons
VERSION=0.4.0
# Win
python smi_python_commons/scm_version.py %NAME% %VERSION%
# *nix
python smi_python_commons/scm_version.py ${NAME} ${VERSION}
git add ./${NAME}/project.py
git commit -m "project.py updated"
git pushsetup.py is the package distribution configuration file. It makes this project an installable Python package that
can be:
- Built into a distributable artifact (
.whl/.tar.gz) - Installed locally via
pip install . - Published to PyPI (or a private registry)
| Field | Value | Meaning |
|---|---|---|
name |
NAME from project.py |
Package name on PyPI |
version |
VERSION from project.py |
Package version |
packages=find_packages() |
auto-detected | Includes all sub-packages |
install_requires |
pyyaml |
Runtime dependency |
extras_require[dev] |
bandit, behave, pip_audit, wheel, twine |
Dev/build tools (from requirements.txt) |
Build the package:
python setup.py sdist bdist_wheel
# or with modern tooling:
pip install build && python -m buildInstall locally (editable/dev mode):
pip install -e .Install locally with dev dependencies:
pip install -e .[dev]Install normally:
pip install .Publish to PyPI:
twine upload dist/*Note:
setup.pyis the legacy way (pre-PEP 517). Modern projects usepyproject.tomlwith[build-system]+[project]sections instead, butsetup.pystill works fine and is widely supported.
python setup.py sdist bdist_wheel
twine upload dist/*
git tag -a ${VERSION} -m "${VERSION}"
git push --tags- Update version info
- Deploy
python setup.py sdist bdist_wheel && twine upload dist/*