I have following in my tox.ini :
[tox]
skipsdist = true
envlist = py27, py36, lint
[testenv]
whitelist_externals=flake8
commands =
version: python setup.py --version
When I run
tox -e version
I get the following output :
tox -e version 2>version
version runtests: PYTHONHASHSEED='3264081464'
version runtests: commands[0] | python setup.py --version
0.2.0
__________________________________________________________________________________________________________________________________________________________ summary ___________________________________________________________________________________________________________________________________________________________
version: commands succeeded
congratulations :)
I need to capture just the version (0.2.0) from tox -e version output, what the most elegant/pythonic way of doing it ? Also is there anyway I can have tox just output the output to the command and not the rest ?
Save the version into a file. In tox.ini:
[testenv]
whitelist_externals = /bin/sh
commands =
version: /bin/sh -c "python setup.py --version >version"
In shell:
tox -e version
cat version
rm version
Including -qq in the tox command should reduce the output to just 0.2.0.
Related
Introduction
I would like to install some dependencies (local-package1 and local-package2) into a virtualenv using Tox. Those dependencies are packages that only exist on my local Python Package Index (inside of an Artifactory instance).
Attempts
Here's my tox.ini:
[tox]
envlist = py27
indexserver =
LOCAL = https://me:abc123#artifactory.example.com/api/pypi/pypi-local/simple
[testenv]
deps =
:LOCAL:local-package1
mock
pykwalify
:LOCAL:local-package2
xlrd
XlsxWriter
xlwt
yamllint
commands =
make.sh
Here's the output from tox -v:
using tox.ini: repo/tox.ini
using tox-3.7.0 from /usr/local/lib/python2.7/site-packages/tox/__init__.pyc
GLOB sdist-make: ~/repo/setup.py
~/repo$ /usr/local/opt/python#2/bin/python2.7 ~/repo/setup.py sdist --formats=zip --dist-dir ~/repo/.tox/dist >~/repo/.tox/log/tox-0.log
package .tmp/package/1/example-0.0.0.zip links to dist/example-0.0.0.zip (~/repo/.tox)
py27 cannot reuse: no previous config ~/repo/.tox/py27/.tox-config1
py27 create: ~/repo/.tox/py27
~/repo/.tox$ /usr/local/opt/python#2/bin/python2.7 -m virtualenv --python /usr/local/opt/python#2/bin/python2.7 py27 >~/repo/.tox/py27/log/py27-0.log
py27 installdeps: :LOCAL:local-package1, mock, pykwalify, :LOCAL:local-package2, xlrd, XlsxWriter, xlwt, yamllint
~/repo$ ~/repo/.tox/py27/bin/python -m pip install -i https://me:abc123#artifactory.example.com/api/pypi/pypi-local/simple local-package1 local-package2 >~/repo/.tox/py27/log/py27-1.log
And doing a tail -f ~/repo/.tox/py27/log/py27-1.log yields the following:
actionid: py27
msg: getenv
cmdargs: 'repo/.tox/py27/bin/python -m pip install -i https://me:abc123#artifactory.example.com/api/pypi/pypi-local/simple local-package1 local-package2'
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Looking in indexes: https://me:****#artifactory.example.com/api/pypi/pypi-local/simple, https://artifactory.example.com/api/pypi/pypi-local/simple
Collecting local-package1
and it seems to hang indefinitely.
If I run the command:
repo/.tox/py27/bin/python -m pip install -i https://me:abc123#artifactory.example.com/api/pypi/pypi-local/simple local-package1 local-package2
outside of the virtualenv, I can install these packages without any issues.
Question
How can I properly install dependencies with Tox which includes authentication to a Python Package Index?
In the example below, the python version is 2.7.6.
Why is it 2.7.6, and not the latest 2.7.15?
How do I specify 2.7.15?
Set up
$ tox --version
2.7.0 imported from /home/obk/anaconda3/lib/python3.6/site-packages/tox/__init__.py
$ ls
tox.ini
$ cat tox.ini
[tox]
envlist = py27
skipsdist = True
[testenv]
commands = python -V
Running it:
$ tox -r
py27 recreate: /home/obk/repos/test/.tox/py27
py27 installed:
py27 runtests: PYTHONHASHSEED='4191112007'
py27 runtests: commands[0] | python -V
Python 2.7.6
___________________________________ summary ___________________________________________
py27: commands succeeded
congratulations :)
The reason why I want the latest 2.7.15 is because my project has a dependency (my_foo -> nbconvert -> tornado) that is now using ssl.create_default_context which was added in 2.7.9.
Why is it 2.7.6, and not the latest 2.7.15?
Because the version of Python 2.7 on your computer is 2.7.6.
How do I specify 2.7.15?
Specify basepython = /path/to/python2.7.15 under [testenv], where /path/to/python2.7.15 is a path to a local copy of exactly version 2.7.15.
I am trying to simplify the console output of tox and to hide the list of installed packages, ideally to hide them if there are no errors installing them.
Here is the current output
tox -e py27
py27 installed: alabaster==0.7.9,...<VERY LONG LIST..
py27 runtests: ...
I tried to add install_command = pip install -q {opts} {packages} but it did had no effect.
With tox >= 2.4 you can use the list_dependencies_command parameter (http://tox.readthedocs.io/en/latest/config.html#confval-list_dependencies_command).
[testenv]
whitelist_externals=echo
list_dependencies_command=echo
It seems that at this moment this is a tox bug https://github.com/tox-dev/tox/issues/601
While working in an virtualenv [3.4] I was trying to run tox for running the tests when I got the error:
py34 develop-inst-nodeps: /home/horcrux/dir-sub/dir
py34 runtests: commands[0] | python -m nose2 -v
/home/horcrux/dir-sub/dir/.tox/py34/bin/python: No module named nose2
ERROR: InvocationError: '/home/horcrux/dir-sub/dir/.tox/py34/bin/python -m nose2 -v'
_____________________________ summary ______________________________________
ERROR: py34: commands failed
I've already tried to install nose2 using pip install nose2 but still the problem remains the same.
sudo clears the environment. You have to invoke the virtualenv inside of the sudo execution environment. Try:
sudo bash -c ". [venv/bin/activate] ; [tox]"
Replace [venv/bin/activate] with the path to your virtualenv activate script and replace [tox] with whatever command you are using to invoke it.
Trying to use tox to run tests before pushing, but I keep running into errors like:
ERROR: py26: InterpreterNotFound: python2.6
ERROR: py32: InterpreterNotFound: python3.2
ERROR: py34: InterpreterNotFound: python3.3
apt-cache search isn't offering any packages that look like they will help. How do you load all these versions of the interpreter for ubuntu14.04?
Obviously, Ubuntu doesn't ship all historic versions of Python. But you can use deadsnakes PPA which has everything from 2.3 to 3.4.
For one project I used drone.io CI service with, I had the following tox section I ran before actual test envs.
[testenv:setupdrone]
whitelist_externals = /bin/bash
commands =
bash -c "echo 'debconf debconf/frontend select noninteractive' | sudo debconf-set-selections"
bash -c "sudo add-apt-repository ppa:fkrull/deadsnakes &> /dev/null"
bash -c "sudo apt-get update &> /dev/null"
bash -c "sudo apt-get -y install python2.6 python3.4 &> /dev/null"