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
WARNING: be aware though that the commands are run as is. If you install things in commands they will be installed in the host environment.
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).
if the testenv name contains the word direct or the attribute direct = True
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:env-attribute]
direct = True
; 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
------------------ -------
[...]
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file tox-direct-0.4.tar.gz
.
File metadata
- Download URL: tox-direct-0.4.tar.gz
- Upload date:
- Size: 9.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 33bb6627db50c1c1760f889410bf77107e4858cf15a0f4532442fd690b6284c8 |
|
MD5 | e2d7240f119d66e376cf0ae76c33f004 |
|
BLAKE2b-256 | e1a7910d5a3e1daec54743cb614c33d3c81aa1c13163ee132a3fea411f8107fd |
File details
Details for the file tox_direct-0.4-py2.py3-none-any.whl
.
File metadata
- Download URL: tox_direct-0.4-py2.py3-none-any.whl
- Upload date:
- Size: 6.6 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d80968dfbaf99198d7fa77fb2c20786f6bcf584000be96217a4ffd74dd4b3699 |
|
MD5 | cb25081691564b529701e76d604a3e2a |
|
BLAKE2b-256 | bc94ded16798e5a4481fae77e0fb5626e019d264b9d3ebcbc9380f6fa3c8a2ad |