Skip to main content

This project aims to create a single library for run-time initiation tasks that are often duplicated across many projects.

Project description

Python 3.8 | 3.9 | 3.10 | 3.11 Code style: black pre-commit

pre-commit.ci status Python tests

runtime-yolk

Requirements

Load your local .env file to environ, load your application.ini which can be environment specific, and setup basic logging behavior all with a single call. Designed to be low effort, runtime-yolk works well in the initial entry point of a project and doesn't add additional requires to downstream libraries.

  • Environment variables are loaded from the .env file, or specified source, directly to os.environ. This allows other processes to pull directly from the environ and reduces library coupling.

  • Configuration files are loaded as ConfigParser objects. The loading layers each consecutive file allowing flexible environment specific configs to be leveraged. A custom {{key}} string interpolation is used when loading config files to allow environ vars to be injected into the config. If the requested key cannot be interpolated the literal value is kept instead of raising exceptions. % is also safe for all api-token/key needs.

  • Set logging levels and format initially from the configuration. Helper methods for creating a logger for the entry script, define logging level, or add FileHandlers make setup easier.


Installation

From github:

$ python -m pip install git+https://github.com/Preocts/runtime-yolk@#.#.#

Replace the #.#.# with the desired version or @main for the latest (unstable).

From pypi:

$ python -m pip install runtime-yolk

Usage Examples

Loading runtime setup manually

Loading runtime setup automatically

Setup of application.ini

The default configuration file looked for loading is application.ini. This can be change on call of .load_config() if desired. There are no required fields in the configuration file. However, a few will impact runtime-yolk's behavior directly when present in the [DEFAULT] section:

  • logging_level : When set, .set_logging() will use this logging level
  • logging_format : Allow overriding the default logging format template used.
    • Default is %(asctime)s - %(levelname)s - %(name)s - %(message)s
  • environment : When defined the value will be used to load additional application-[environment].ini configuration files. These can be chained however will break the loading loop on a file that has already been loaded.

Sample:

[DEFAULT]
logging_level = DEBUG
logging_format = %(asctime)s - %(levelname)s - %(name)s - %(message)s
environment = {{YOLK_ENVIRONMENT}}

.env file loading

.env files are loaded with the expectation of key = value pairs. # comments are allowed as well as blank lines.

Current format for the .env file supports strings only and is parsed in the following order:

  1. Each separate line is considered a new possible key/value set
  2. Each set is delimited by the first = found
  3. Leading and trailing whitespace are removed
  4. Removes leading 'export ' prefix, case agnostic
  5. Matched leading/trailing single quotes or double quotes will be stripped from values (not keys).

Sample:

# OAuth token goes here, do not commit this Glenn
SAMPLE_TOKEN=somesecrettokenforuse
ENVIRONMENT=sandbox


Local developer installation

It is strongly recommended to use a virtual environment (venv) when working with python projects. Leveraging a venv will ensure the installed dependency files will not impact other python projects or any system dependencies.

The following steps outline how to install this repo for local development. See the CONTRIBUTING.md file in the repo root for information on contributing to the repo.

Windows users: Depending on your python install you will use py in place of python to create the venv.

Linux/Mac users: Replace python, if needed, with the appropriate call to the desired version while creating the venv. (e.g. python3 or python3.8)

All users: Once inside an active venv all systems should allow the use of python for command line instructions. This will ensure you are using the venv's python and not the system level python.


Installation steps

Clone this repo and enter root directory of repo:

$ git clone https://github.com/Preocts/runtime-yolk
$ cd runtime-yolk

Create the venv:

$ python -m venv venv

Activate the venv:

# Linux/Mac
$ . venv/bin/activate

# Windows
$ venv\Scripts\activate

The command prompt should now have a (venv) prefix on it. python will now call the version of the interpreter used to create the venv

Install editable library and development requirements:

# Update pip and tools
$ python -m pip install --upgrade pip

# Install editable version of library
$ python -m pip install --editable .[dev]

Install pre-commit (see below for details):

$ pre-commit install

Misc Steps

Run pre-commit on all files:

$ pre-commit run --all-files

Run tests:

$ tox [-r] [-e py3x]

Build dist:

$ python -m pip install --upgrade build

$ python -m build

To deactivate (exit) the venv:

$ deactivate

Note on flake8:

flake8 is included in the requirements-dev.txt of the project. However it disagrees with black, the formatter of choice, on max-line-length and two general linting errors. .pre-commit-config.yaml is already configured to ignore these. flake8 doesn't support pyproject.toml so be sure to add the following to the editor of choice as needed.

--ignore=W503,E203
--max-line-length=88

pre-commit

A framework for managing and maintaining multi-language pre-commit hooks.

This repo is setup with a .pre-commit-config.yaml with the expectation that any code submitted for review already passes all selected pre-commit checks. pre-commit is installed with the development requirements and runs seemlessly with git hooks.


Makefile

This repo has a Makefile with some quality of life scripts if the system supports make. Please note there are no checks for an active venv in the Makefile.

PHONY Description
install-dev install development/test requirements and project as editable install
coverage Run coverage and output console report
docker-test Run coverage and tests in a docker container.
build-dist Build source distribution and wheel distribution
clean Deletes build, tox, coverage, pytest, mypy, cache, and pyc artifacts

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

runtime-yolk-1.2.3.tar.gz (13.7 kB view details)

Uploaded Source

Built Distribution

runtime_yolk-1.2.3-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file runtime-yolk-1.2.3.tar.gz.

File metadata

  • Download URL: runtime-yolk-1.2.3.tar.gz
  • Upload date:
  • Size: 13.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.10

File hashes

Hashes for runtime-yolk-1.2.3.tar.gz
Algorithm Hash digest
SHA256 db955fba877a94e46f7484a1923c894a093bd41cd8b6bdda3123ab5e64a69d6e
MD5 53f5ae02564061a5e474831beb810a04
BLAKE2b-256 5e5c6889ac80d96731567b1d60d1e4cc85a23fcbaec0e0eec5602d4a4c89fae5

See more details on using hashes here.

File details

Details for the file runtime_yolk-1.2.3-py3-none-any.whl.

File metadata

File hashes

Hashes for runtime_yolk-1.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 5f7467c1cf1dfb1bb9c179962f01d28390b4f1395362372e56c1bf4847d11db9
MD5 9bedca9cd7277b8b8175a4b092fbb57e
BLAKE2b-256 4c20f632689c4d87bff021479f57a7b85713e135ffbe601b3edc0fa2d4db0553

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page