Skip to main content

plugin for tox - run everything directly (tox creates no virtual env)

Project description

tox-direct

tox plugin: run tox envs directly in the same interpreter that tox was run in.

tox-direct is something that you usually shouldn't need, but that can be handy in certain situations. It is not recommended to use this approach as a normal part of a tox based automation workflow. The fact that tox creates isolated virtual environments for all automation activities is one of the main reasons for its reliability and is the key to unify command line based and CI automation.

Having said that: life is messy and sometimes you just want to run a certain environment in the host interpreter. For this there is tox-direct now.

TODO: maybe it makes sense to extend this to being able to run in the basepython rather than in the host environment (if they differ). This is not implemented as I have no need for it (yet).

installation

pip install tox-direct

concept

tox-direct is trying to be safe first and should also have the ability to degrade gracefully when tox-direct is not installed. To ensure this, no new key in tox.ini is introduced. It works purely over env name, command line parameters or environment variables.

To be safe the following activities will be deactivated by default in direct runs:

  • package build
  • deps installations
  • project installation

There are two ways to request envs being run in direct mode: static and on request. The on request variant also provides a YOLO option ((you only live once ;)) which means that everything is run in the host interpreter. This will change the host interpreter and is usually only safe and makes sense (or works at all) if tox is run in a virtual environment already.

static form

if the testenv name contains the word direct it will be run in direct mode if tox-direct is installed. If this is part of a project that is shared you should make sure that this also works as intended if tox-direct is not installed (a.k.a. degrades gracefully).

on request form

tox-direct adds command line arguments and checks environment variables to run arbitrary envs in direct mode.

With tox-direct installed:

$ tox --help
[...]

optional arguments:
  --direct        [tox-direct] deactivate venv, packaging and install steps - 
                  run commands directly (can also be achieved by setting
                  TOX_DIRECT) (default: False)
  --direct-yolo   [tox-direct] do everything in host environment that would
                  otherwise happen in an isolated virtual environment 
                  (can also be achieved by setting TOX_DIRECT_YOLO env var
                  (default: False)

WARNING: tox-direct does not consider different basepythons, which means that running environments with different basepythons makes no sense with tox-direct at the moment: they would all run in the same environment where tox is installed (effectively doing the same over and over again).

basic example

Let's assume you are working in some virtualenv already which looks like this:

$ which python
~/.virtualenvs/tmp/bin/python

$ pip list
pip list
Package            Version
------------------ -------
[...] 
tox                3.13.1 
tox-direct         0.2.2  
[...]  


$ tox --version
3.13.1 imported from ~/.virtualenvs/tmp/lib/python3.6/site-packages/tox/__init__.py
registered plugins:
    tox-direct-0.2.2 at ~/.virtualenvs/tmp/lib/python3.6/site-packages/tox_direct/hookimpls.py

You have a project with a tox.ini like this:

[tox]
; this is the default - put here to be explicit
skipsdist = False

[testenv:direct-action]
; also the default to be explicit
skip_install = False
deps = pytest
commands =
    pip list
    which python

[testenv:normal]
whitelist_externals = which
skip_install = False
usedevelop = True
commands = which python

tun tox:

$ tox -qr
Package            Version
------------------ -------
[...] 
tox                3.13.1 
tox-direct         0.2.2  
[...]  
/home/ob/.virtualenvs/tmp/bin/python
Package            Version
------------------ -------
[...]
pytest             4.6.3
example-project    1.3
[...]
/home/ob/oss/tox-dev/tplay/.tox/normal/bin/python
_________________ summary _______________________
  direct-action: commands succeeded
  normal: commands succeeded
  congratulations :)

The direct-action env shows the packages from the tmp virtual env and pytest was not installed, the project itself was also not installed.

WARNING: if something is installed in the commands (e.g. contains pip install calls) this will still happen as commands will be executed without further inspection.

tox still creates an envdir at .tox/direct-action but it does not contain a virutal environment - it is only used for internal bookkeeping and logging. The interpreter used throughout is ~/.virtualenvs/tmp - the host interpreter that tox was started from.

The normal env ran in the isolated environment provided by tox. pytest was installed and so was the project itself (because no package is needed to install the project in development mode). If usedevelop was set to False tox would crash with a note that you can't do this in direct mode (because sdist is not built in direct mode).

run the normal environment in direct mode:

tox -qre normal --direct
Package            Version Location                           
------------------ ------- --------
[...]  
tox                3.13.1  
tox-direct         0.2.2 
[...]   
/home/ob/.virtualenvs/tmp/bin/python
____________________ summary _______
  normal: commands succeeded
  congratulations :)

Thi time it ran in the host and nothing extra was installed.

And now the YOLO version:

tox -qre normal --direct-yolo
Package            Version    Location                           
------------------ ---------- --------
[...]   
example-project    1.3   
pytest             4.6.3      
[...]     
tox                3.13.1     
tox-direct         0.2.2
[...]      
/home/ob/.virtualenvs/tmp/bin/python
______________________ summary _________________________________
  normal: commands succeeded
  congratulations :)

pytest and the project where installed in the host environment.

NOTE: the YOLO option is called YOLO for a reason in case you run this as root in your system python :).

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

tox-direct-0.3.5.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

tox_direct-0.3.5-py2.py3-none-any.whl (6.4 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file tox-direct-0.3.5.tar.gz.

File metadata

  • Download URL: tox-direct-0.3.5.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

File hashes

Hashes for tox-direct-0.3.5.tar.gz
Algorithm Hash digest
SHA256 769d4b4e922ea18893b98ea3750ec9a8534ebc66a9c22597913f32f5aa5dbd58
MD5 4c3ef030f2739fb3c678b799d9017c1b
BLAKE2b-256 a63361495e5f7972b65b20445749a8055fc321233d9e4afcb6401d10ea63a409

See more details on using hashes here.

Provenance

File details

Details for the file tox_direct-0.3.5-py2.py3-none-any.whl.

File metadata

  • Download URL: tox_direct-0.3.5-py2.py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

File hashes

Hashes for tox_direct-0.3.5-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 5611bd86b7d55ccacca59738a2537ea4f05d054578c00548251d58bfc5162676
MD5 ebb1698bd5d32f6a6dfda05daf3aab52
BLAKE2b-256 55296b27779863fc42fcb8a339136741dcd66f6aad23b5da00233b27dad2fd17

See more details on using hashes here.

Provenance

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