Skip to content

Change preservation behaviour for PYTHONPATH (backwards compatible) #457

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jarshwah opened this issue Feb 15, 2017 · 9 comments
Closed

Comments

@jarshwah
Copy link

I help to maintain https://github.com/django/django-box which is a vagrant machine setup with all of the dependencies needed to test Django. Django provides a tox file with explicit configuration to support the django-box vagrant machine. See: https://github.com/django/django/blob/3d14cbc86781ea1051af7f0c421bee3ecf2f9842/tox.ini

# relevant section
[testenv]
usedevelop = true
passenv = DJANGO_SETTINGS_MODULE PYTHONPATH HOME DISPLAY
setenv =
    PYTHONDONTWRITEBYTECODE=1
deps =
    py{3,34,35,36}: -rtests/requirements/py3.txt
    postgres: -rtests/requirements/postgres.txt
    mysql: -rtests/requirements/mysql.txt
    oracle: -rtests/requirements/oracle.txt
changedir = tests
commands =
    {envpython} runtests.py {posargs}

Various aliases are configured to run the test suite such as:

alias runtests36-postgres='PYTHONPATH=/home/vagrant/djangodata/ tox -c /django/tox.ini -e py36-postgres -- --settings=test_postgres'

The /home/vagrant/djangodata/ contains a bunch of python configuration files that define database connections. This directory is added to PYTHONPATH to make the configuration files available to the --settings= argument. Note the passenv in the tox configuration.

This worked perfectly fine in tox 2.3.0. Unfortunately, (after much debugging), I discovered that 2.4.0 removed support for PYTHONPATH entirely, even when explicitly defined in passenv.

remove PYTHONPATH from environment during the install phase because a tox-run should not have hidden dependencies and the test commands will also not see a PYTHONPATH. If this causes unforeseen problems it may be reverted in a bugfix release.

Our goals:

  1. Avoid poluting django test directory with unrelated settings files. The settings files are related to the system doing the testing, and are passed to django.

  2. Avoid hardcoding paths in the tox file, which isn't designed to only be used with this virtual machine.

If there's a way forward to make the settings directory available to the environment without PYTHONPATH, I'm all ears.

For me though, if I've explicitly configured PYTHONPATH in the passev configuration, then please, let me pass it through. Tox shouldn't be blessing or blocking environment variables with no work arounds.

I'd like to see this change reverted, but once again, I'm open to discussions on how best to fix this problem.

@nicoddemus
Copy link
Member

As an aside, tox should emit a warning if the user is passing PYTHONPATH in passenv but tox is removing it implicitly.

@jarshwah
Copy link
Author

#367 was what removed the ability to pass PYTHONPATH. I understand that this was supposed to fix a number of issues. To work around this, what about adding an option to the tox command line in the vein of --preserve-pythonpath? That would make it explicitly opt-in.

@obestwalter obestwalter changed the title Removing PYTHONPATH from the environment when explicitly defined breaks setups Add opt-in for preservation of PYTHONPATH Feb 17, 2017
@obestwalter
Copy link
Member

Quote from 2.4.0 changelog:

remove PYTHONPATH from environment during the install phase because a
tox-run should not have hidden dependencies and the test commands will also
not see a PYTHONPATH. If this causes unforeseen problems it may be
reverted in a bugfix release. Thanks Jason R. Coombs.

This makes sense to me and I don't think we should revert this as it did not cause unforeseen issues as such.

I guess we would merge a PR that would make it opt-in as suggested by @jarshwah?

@obestwalter
Copy link
Member

As an aside, tox should emit a warning if the user is passing PYTHONPATH in passenv but tox is removing it implicitly.

@nicoddemus - definitely. I created an issue for that: #458

@nicoddemus
Copy link
Member

Hmm instead of adding a new option, how about:

  • If the user's environment has $PYTHONPATH set and passenv does not have PYTHONPATH: discard PYTHONPATH in the tox run, but warn the user (in yellow):

    Discarding $PYTHONPATH from environment, to override specify PYTHONPATH in 'passenv' in your environment.

  • If user explicitly adds PYTHONPATH to passenv, it is not discarded and no warning is produced.

Seems to cover the use case presented here and also preserve the solution to the problems in #367.

@obestwalter
Copy link
Member

Great idea. No option clutter and this would also squash #458.

@jarshwah
Copy link
Author

jarshwah commented Feb 17, 2017 via email

@obestwalter
Copy link
Member

obestwalter commented Feb 17, 2017

For potential PRs: this should be explained in the docs as well ...

@obestwalter obestwalter changed the title Add opt-in for preservation of PYTHONPATH Change preservation behaviour for PYTHONPATH (backwards compatible) Feb 17, 2017
@jarshwah
Copy link
Author

I'll put together a PR in the next couple of days.

jarshwah added a commit to jarshwah/tox that referenced this issue Feb 18, 2017
@hpk42 hpk42 closed this as completed in 7159d38 Feb 23, 2017
hpk42 added a commit that referenced this issue Feb 23, 2017
passenv respects PYTHONPATH. Fixes #457 and #458
@tox-dev tox-dev locked and limited conversation to collaborators Jan 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants