Skip to main content

Get a Python environment for a Python version and requirements.txt file

Project description

Get a Python environment for a Python version and requirements.txt file

env_cache manages a collection of Python environments. You request an environment for a specific Python version and a set of requirements (preferably with pinned versions, like from pip freeze). It can either create a new environment with these packages, or retrieve one it already made with the same arguments.

To get different versions of Python, env_cache can use pyenv, conda, or spack. It can also work with a single ‘fixed’ Python interpreter to create virtualenvs - in this case, only one Python version is available.

Usage (with pyenv):

import sys
from pathlib import Path

from env_cache import PyenvEnvMaker, EnvsManager

if len(sys.argv) != 3:
    sys.exit("Usage: eg-pyenv.py 3.8.11 path/to/requirements.txt")

py_version, reqs_path = sys.argv[1:]
reqs = Path(reqs_path).read_text('utf-8')

envmgr = EnvsManager(Path('my-envs'), PyenvEnvMaker())
env_dir = envmgr.get_env(py_version, reqs)

It returns a pathlib Path object (env_dir above) pointing to the environment directory. Python can be run from bin/python within this directory.

It also records each time an environment is requested in a crude usage.csv file in the environment directory. This is meant to help with cleaning up unused environments, but it may go away or change completely in a future version.

This package is written primarily for internal use at European XFEL, so it’s fairly rough, and we might make breaking changes without warning.

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

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

Source Distribution

env_cache-0.1.tar.gz (4.5 kB view hashes)

Uploaded Source

Built Distribution

env_cache-0.1-py2.py3-none-any.whl (4.7 kB view hashes)

Uploaded Python 2 Python 3

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