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

Fix VIRTUALENV_PYTHON environment lookup #1998

Merged
merged 5 commits into from
Oct 28, 2020
Merged

Conversation

pneff
Copy link
Contributor

@pneff pneff commented Oct 28, 2020

The previous change which introduced the fallback discovery (#1995) broke this behaviour.

I originally thought to change the ListType class which uses self.as_type to cast the individual list values into the target value. At the moment the default for that type is a list which means the default behaviour for the class is to return a list of lists. But that became a bigger change than I'm comfortable doing on this code base, so I came up with this simpler change.

Thanks for contributing, make sure you address all the checklists (for details on how see development documentation)!

  • ran the linter to address style issues (tox -e fix_lint)
  • wrote descriptive pull request text
  • ensured there are test(s) validating the fix
  • added news fragment in docs/changelog folder
  • updated/extended the documentation

The previous change which introduced the fallback discovery (pypa#1995)
broke this behaviour.
@codecov
Copy link

codecov bot commented Oct 28, 2020

Codecov Report

Merging #1998 into main will decrease coverage by 0.01%.
The diff coverage is 88.88%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1998      +/-   ##
==========================================
- Coverage   94.26%   94.25%   -0.02%     
==========================================
  Files          86       86              
  Lines        4274     4280       +6     
==========================================
+ Hits         4029     4034       +5     
- Misses        245      246       +1     
Flag Coverage Δ
#tests 94.25% <88.88%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/virtualenv/discovery/builtin.py 85.21% <ø> (ø)
src/virtualenv/config/convert.py 90.19% <88.88%> (-0.92%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0a5009a...4f891ef. Read the comment docs.

@@ -31,6 +32,13 @@ def test_value_bad(monkeypatch, caplog, empty_conf):
assert "invalid literal" in caplog.messages[0]


def test_python_via_env_var(monkeypatch):
options = VirtualEnvOptions()
monkeypatch.setenv(str("VIRTUALENV_PYTHON"), str("python3"))
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a test to validate that python2,python3 works as expected too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I extended the code to provide that functionality. Multi-value was split with newline so far, though it seems the only other multi-value field is extra-search-dir.

Let me know if you are happy with the approach taken or would prefer a different way to do this.

Unlike `VIRTUALENV_EXTRA_SEARCH_DIR` where the values are separated by
newline, a comma is used for this value.
@@ -39,6 +39,13 @@ def test_python_via_env_var(monkeypatch):
assert options.python == ["python3"]


def test_python_multi_value_via_env_var(monkeypatch):
options = VirtualEnvOptions()
monkeypatch.setenv(str("VIRTUALENV_PYTHON"), str("python3,python2"))
Copy link
Contributor

Choose a reason for hiding this comment

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

Wait, I did not realize that VIRTUALENV_EXTRA_SEARCH_DIR accepts newlines. Can we instead make this one use the same logic, and perhaps alter the logic for that to also accept the comma, not just newlines?

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, what we have is correct, but instead of having different split character depending on the type, let's always accept both. I don't expect people to use comma in paths, so IMHO, this is alright.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am pushing a commit which implements this change. I opted for only accepting one split option at a time - so if the environment variable contains newlines, then we don't also accept commas. Do you agree with that decision?

I quickly went back to the legacy code as well, and it seems that newline support has only been added with the rewrite. The previous version had space separation for path names. Thus I would expect the backwards compatibility impact of this change to be minimal.

Copy link
Contributor

Choose a reason for hiding this comment

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

That makes sense. Can you add a test demonstrating/validating this? Also, the documentation should explicitly state that only of the two will be accepted, and not both at the same time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Those tests have been added now.

@@ -39,6 +39,13 @@ def test_python_via_env_var(monkeypatch):
assert options.python == ["python3"]


def test_python_multi_value_via_env_var(monkeypatch):
options = VirtualEnvOptions()
monkeypatch.setenv(str("VIRTUALENV_PYTHON"), str("python3,python2"))
Copy link
Contributor

Choose a reason for hiding this comment

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

That makes sense. Can you add a test demonstrating/validating this? Also, the documentation should explicitly state that only of the two will be accepted, and not both at the same time.

Copy link
Contributor

@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.

@gaborbernat gaborbernat merged commit d89f976 into pypa:main Oct 28, 2020
@pneff pneff deleted the fix-python-env branch October 28, 2020 16:20
@pneff
Copy link
Contributor Author

pneff commented Oct 28, 2020

Thank you @gaborbernat!

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.

2 participants