Skip to content
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

Don't warn when PYTHONPATH is present but empty. #1092

Closed
wants to merge 3 commits into from

Conversation

Julian
Copy link

@Julian Julian commented Nov 26, 2018

Some users (e.g. me :) have an always set [but empty] PYTHONPATH
(for reasons like supporting zsh's typeset -T). Since Python's own
behavior is the same in this case as having the env var unset,
tox shouldn't warn.

Thanks for contributing a pull request!

If you are contributing for the first time or provide a trivial fix don't worry too
much about the checklist - we will help you get started.

Contribution checklist:

(also see CONTRIBUTING.rst for details)

  • wrote descriptive pull request text
  • added/updated test(s)
  • updated/extended the documentation
  • added relevant issue keyword
    in message body
  • added news fragment in changelog folder
    • fragment name: <issue number>.<type>.rst for example (588.bugfix.rst)
    • <type> is must be one of bugfix, feature, deprecation,breaking, doc, misc
    • if pr has no issue: consider creating one first or change it to the pr number after creating the pr
    • "sign" fragment with "by @"
    • please use full sentences with correct case and punctuation, for example: "Fix issue with non-ascii contents in doctest text files - by :user:superuser."
    • also see examples
  • added yourself to CONTRIBUTORS (preserving alphabetical order)

Some users (e.g. me :) have an always set [but empty] PYTHONPATH
(for reasons like supporting zsh's typeset -T). Since Python's own
behavior is the same in this case as having the env var unset,
tox shouldn't warn.
@@ -387,7 +387,7 @@ def ensure_pip_os_environ_ok(self):
os.environ.pop(key, None)
if "PYTHONPATH" not in self.envconfig.passenv:
# If PYTHONPATH not explicitly asked for, remove it.
if "PYTHONPATH" in os.environ:
if os.environ.get("PYTHONPATH"):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note that this is a behavior change allowing the empty variable to pass trough

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I considered that (and popping it out) but couldn't think of a decent reason why it'd matter.

Happy to change if someone does though.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, at least it will make the env larger, and therefore I think it should not be added in the first place - it is nicer to have less in env etc.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's err on the side of caution and remove it anyway. can dedent line 395 and change it to os.environ.pop('PYTHONPATH', None)

@gaborbernat
Copy link
Member

zsh typeset support? feels to me like you're trying to fix a zsh bug in tox.

@Julian
Copy link
Author

Julian commented Nov 26, 2018 via email

@gaborbernat
Copy link
Member

Without context, I'm tempted to reject this. Setting the env var as empty is likely to confuse users so warning on it seems a best practice (even if python silently swallows this kind of odd usage).

@Julian
Copy link
Author

Julian commented Nov 26, 2018

Sorry, what? Which users is this confusing? A user has set PYTHONPATH to be empty. This is valid, has documented behavior equivalent to not having it set at all. I gave a reason why someone might be doing this, but equally well a user could be writing export PYTHONPATH= somewhere earlier in a terminal session and forgotten about it.

All this does is silence a warning for the case that it isn't needed. The purpose of the warning is to let the user know that their environment variable is being ignored (which by the way tox isn't even consistent about, but fine). In this case, it's not ignored, they're getting the same behavior, so don't pollute their stdout with red messages.

Probably should have written all that elaboration earlier I guess, but if you still disagree it's really not worth pursuing such a small fix so feel free to close.

@gaborbernat
Copy link
Member

Can you please link to This is valid, has documented behavior equivalent to not having it set at all.? 👍

@blueyed
Copy link

blueyed commented Dec 1, 2018

It appears the behavior for an empty PYTHONPATH changed in Python 3.4 for the python interpreter, previously it behaved like PYTHONPATH=. according to https://github.com/blueyed/cpython/blame/a346266c87c8f4bd2343bea1bbacd357d2ae435f/Doc/whatsnew/3.4.rst#L2249-L2255. Therefore it would make sense to have the warning with earlier versions there still I suppose?!

GitHub
The Python programming language. Contribute to blueyed/cpython development by creating an account on GitHub.

Copy link
Member

@gaborbernat gaborbernat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah agreed. Please only remove for newer ones only, and refer the documentation why it's redundant.

@Julian
Copy link
Author

Julian commented Dec 5, 2018

Sorry, lucky me caught the flu and has been completely out of commission for the last week. Will have to catch up with whatever comments here.

@gaborbernat
Copy link
Member

@Julian do you plan to finish this?

@Julian
Copy link
Author

Julian commented Dec 18, 2018

Seemingly unlikely at the minute unfortunately, too many other things. Will close and send a new PR if I do get a moment to get back to it.

@Julian Julian closed this Dec 18, 2018
@gaborbernat gaborbernat reopened this Dec 18, 2018
@gaborbernat
Copy link
Member

Let's keep it open then, I might finish it.

@Aareon
Copy link

Aareon commented Jan 4, 2019

So the forth going goal for this PR is to only warn on versions >= 3.4? Just looking for a summary of what we've established as the best function for this PR

@gaborbernat
Copy link
Member

Yes 👍

@Aareon
Copy link

Aareon commented Jan 4, 2019

Excellent! Thank you, @gaborbernat 😊

@gaborbernat
Copy link
Member

superseded with #1189

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants