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

When basepython is pythonX and is missing, try to use various pythonX.Y #854

Closed
pradyunsg opened this issue Jun 23, 2018 · 9 comments
Closed

Comments

@pradyunsg
Copy link

pradyunsg commented Jun 23, 2018

Coming from pypa/pip#5526 (comment)

Sometimes, a project does not care about which minor version of an interpreter is being used. So, they may specify python2 or python3 as a basepython. In these cases, if there is no python3 on PATH, tox should try searching for other matching interpreters with minor version -- python3.7 then python3.6 and so on instead of just failing.

@pradyunsg
Copy link
Author

This would translate to using py -X.Y on Windows, based on the same logic as today.

def locate_via_py(v_maj, v_min):

@pfmoore
Copy link

pfmoore commented Jun 23, 2018

I'd rather see a cross-platform means of saying "python 2" or "python 3" (so the user's intent is explicit) than have tox search for all the possible minor versions.

Suggested solution (which covers both this and #855):

  1. Add aliases py2 and py3 directly parallel to pyXY. These should work similarly to the existing aliases and fall back to py -X on Windows, when the python2 or python3 executable is unavailable.
  2. Make pythonX.Y and pythonX executable names work cross-platform by falling back to py -X.Y or py -X on Windows when the executables don't exist.

That's an unfortunately confusing duplication, but it simply completes the existing set of options and makes them all work cross-platform. A more radical fix, for example to deprecate either pyXY or pythonX.Y would remove the duplication, but IMO is out of scope for this issue, as it would involve users needing to change their tox configurations.

@rpkilby
Copy link
Member

rpkilby commented Jun 23, 2018

I would be -1 on this. There are enough differences between the various minor versions of Python such that I can imagine this leading to confusion when debugging across environments.

As a trivial example, one user has Python 3.7 installed, while another has Python 3.3 installed. Without realizing it, tests are failing for the latter user due to the tests implicitly assuming Python 3.6's dict ordering behavior. Again, a trivial example, but it might be confusing for a relatively new Python developer.

@pfmoore
Copy link

pfmoore commented Jun 23, 2018

If the user explicitly says they want "python3" without specifying which minor version, surely they are saying they don't care about the minor version? So it's hardly "without realising it" that the tests depend on what minor version is installed. If they cared, they should have specified python3.7 explicitly.

Having said that, I'm not keen on this request as it stands. Tox shouldn't be hunting out a suitable Python version itself, it should simply run "python 3" and let the OS sort it out. The only proviso is that on Unix, running the python3 command does that, whereas on Windows, the correct command is py -3 so tox should (IMO) run the appropriate OS-dependent command. (At the moment, it fails on Windows because there's no python3 executable there and it doesn't know about the py launcher).

@asottile
Copy link
Contributor

Also -1 on this, tox shouldn't be guessing at possible executables. I also think that the current behaviour works fine on posix. and the improvements made in #856 should be sufficient for windows.

Any unixlike machine which doesn't have python2 / python3 executables isn't compliant with PEP394 so I don't think it's worth bending over backwards for that situation

@gaborbernat
Copy link
Member

gaborbernat commented Jun 23, 2018

In case of linters I see reasonable request for some support of this. I mean unit tests are bound for one given environment, however linters are more a case of need some environment.

@rpkilby
Copy link
Member

rpkilby commented Jun 24, 2018

@pfmoore, I'm suggesting that a user may do this unintentionally. e.g., they think they're writing code that is compatible across all minor versions of Python 3, but are unintentionally relying on the specifics of one version. Another user comes along, running an older version on their system, and hits unexpected bugs. Realistically, I don't think this would be a huge issue, but it could be a potential point of confusion for relatively new Python developers.

Either way, I don't have a very strong opinion over this. Just sharing my thoughts.

@pfmoore
Copy link

pfmoore commented Jun 24, 2018

The motivating example for this is something like https://github.com/pypa/pip/blob/master/tox.ini#L48 where we want to run our linter against the code using Python 3. We don't care which Python 3, as pylint should report the same errors whatever version is in use, and we don't want to force people to install a specific version of Python 3 just to do lint checks.

But nevertheless, I do agree it's not tox that should be doing the guessing here - tox should just call the pythonX command on Unix or the py -X command on Windows, and let the standard "pick a minor version" logic do its work.

@gaborbernat
Copy link
Member

With #858 this is now solved, so I'll close this now. Wait for https://github.com/tox-dev/tox/milestone/3 and 🎉

@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

5 participants