Skip to content
/ invenv Public

A tool to automatically create and run your Python scripts in a virtual environment with installed dependencies

License

Notifications You must be signed in to change notification settings

jsnjack/invenv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

78 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

invenv

invenv is a tool to run your Python scripts in an automatically created virtual environment with installed dependencies.

It tries to simplify running Python scripts (or even applications!) by taking from you the burden of creating and maintaining virtual environments.

Description

Usage:
  invenv [invenv-flags] -- [VAR=val] python-script.py [flags]
  invenv [command]

Examples:
invenv -- somepath/myscript.py
invenv -n -- somepath/myscript.py --version
invenv -r req.txt -- DEBUG=1 somepath/myscript.py

Available Commands:
  completion  Generate the autocompletion script for the specified shell
  help        Help about any command
  init        initialize a virtual environment in the current directory

Flags:
  -d, --debug                      enable debug mode with verbose output
  -h, --help                       help for invenv
  -n, --new-environment            create a new virtual environment even if it already exists
  -p, --python string              use specified Python interpreter
  -r, --requirements-file string   use specified requirements file. If not provided, it
                                   will try to guess the requirements file name:
                                   requirements_<script_name>.txt, <script_name>_requirements.txt or
                                   requirements.txt
  -s, --silent                     silence progress output. --debug flag overrides this
  -v, --version                    print version and exit
  -w, --which                      print the location of virtual environment folder and exit. If
                                   the virtual environment does not exist, it will be created with
                                   installed requirements

Details

When you run invenv the first time it will:

  • detect python interpreter which should be used to run your script (by analyzing shebang)
    • in case if python interpreter is not found in your PATH, it will try to use default python interpreter in your system
    • it is possible to specify a custom interpreter with -p flag
  • create a virtual environment in ~/.local/invenv/ folder
  • try to automatically install all dependencies from requirements_<script_name>.txt, <script_name>_requirements.txt or requirements.txt files (it is possible to specify a custom requirements file with -r flag)
  • run your script with all the arguments you passed

Next time you run invenv it will try to use the existing virtual environment and install dependencies only if they are changed.

Installation

  • Using grm
    grm install jsnjack/invenv
  • Download binary from Release page
  • One liner:
    curl -s https://api.github.com/repos/jsnjack/invenv/releases/latest | jq -r .assets[0].browser_download_url | xargs curl -LOs && chmod +x invenv && sudo mv invenv /usr/local/bin/
  • From COPR repository (Fedora, CentOS, RHEL and etc.)
    dnf copr enable surfly/invenv
    dnf install invenv

Credits

  • qguv for the original idea

About

A tool to automatically create and run your Python scripts in a virtual environment with installed dependencies

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published