Skip to main content

Simple script to help create and use pyenv virtualenvs

Project description

pyenv-mkenv

Simplify pyenv environment creation; script requires python 3.6+.

Do you use pyenv?

When you check out a new repository, the workflow looks something like this:

pyenv virtualenv $MY_PY_VERSION $MY_REPO_NAME
pyenv local $MY_REPO_NAME
pip install -U pip
pip install -r requirements.txt

There has to be a better way!

Now there is:

mkenv -r requirements.txt

This script does a number of things:

  • Pick a python version (by preference, the most recent installed CPython version; see below)
  • Create a pyenv-virtualenv using the directory name by default (controlled by -n / --name)
  • Update pip
  • Install requirements (multiple paths can be given)

Installation

  • From PyPI: pip install pyenv-mkenv
  • From github: pip install git+git://github.com/clbarnes/pyenv-mkenv.git
  • For development: git clone git@github.com:clbarnes/pyenv-mkenv.git && cd pyenv-mkenv && pip install -e .

Or just copy mkenv.py; it's dependency-free.

Usage

usage: mkenv [-h] [-p] [-n NAME] [-r [REQUIREMENTS]] [-v] [--version]
             [py_version]

positional arguments:
  py_version            Python version. If this option starts with '/', the
                        rest will be interpreted as a regex; otherwise, a
                        simple match to the start of the version name will be
                        used. Empty string by default. By default, mkenv will
                        try to find the highest version matching the string
                        (use -p to see priority and pick) manually)

optional arguments:
  -h, --help            show this help message and exit
  -p, --pick            Prompt to select from matching versions
  -n NAME, --name NAME  Name for the environment (defaults to directory name)
  -r [REQUIREMENTS], --requirements [REQUIREMENTS]
                        Requirements files to install from. If option is used
                        with no path given, user will be prompted.
  -v, --verbose
  --version             show program's version number and exit

Python version

pyenv-mkenv lists available python versions (i.e. non-symlink directories in $PYENV_HOME/versions/), and sorts them. The sort order is intended to be somewhat intuitive:

  • Prefer standard CPython distributions (i.e. starts with a digit)
  • Prefer higher versions (i.e. substrings which look like versions are parsed and sorted descending)
  • Non-standard distributions are sorted lexicographically without version numbers, and then by their version number (multiple version numbers, e.g. pypy3.6-7.3.0, are addressed left to right)

If no py_version argument is given, the first item on the list is chosen. If a string is given, the first item on the list which starts with that string is chosen (e.g. 3.8 -> 3.8.1). If the given string starts with a /, treat the remainder as a regex which is searched for within each version name; the first matching name is used.

To make sure which version you're getting, use the -p / --pick option. This will show versions which match the py_version argument (in sorted order), and allow you to select which one you want.

Requirements

By default, mkenv does not install any requirements. However, any number of requirements files can be added by using the -r option. If -r is supplied without an argument, mkenv searches down into the directory tree, looking for anything matching the glob requirements*.txt, ignoring hidden directories, and prompts the user to select which ones they want to install.

Disclaimer

This is not a pyenv plugin; it is a python script which assumes you have pyenv installed.

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

pyenv-mkenv-1.0.0.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

pyenv_mkenv-1.0.0-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file pyenv-mkenv-1.0.0.tar.gz.

File metadata

  • Download URL: pyenv-mkenv-1.0.0.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.8.1

File hashes

Hashes for pyenv-mkenv-1.0.0.tar.gz
Algorithm Hash digest
SHA256 64bfead7a971c48e5553949ffe98500eb44ee82088f96e9c13dd8d309c5a0952
MD5 793f52c486fb1cde7b8efeae859786ed
BLAKE2b-256 822503e89415937595df5ea319906fb862e520dc67b4924b6573c4e7b04c772d

See more details on using hashes here.

File details

Details for the file pyenv_mkenv-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pyenv_mkenv-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.8.1

File hashes

Hashes for pyenv_mkenv-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 16c67f4619057e2f93d2930377aefa664417c96576899174c4786445db2289a4
MD5 c61b0e02afc05e5194eb874901978a0a
BLAKE2b-256 05950df958683695786a593ef95cdc70fe0961cb12db102fffdd6bd61a60893f

See more details on using hashes here.

Supported by

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