-
-
Notifications
You must be signed in to change notification settings - Fork 531
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
Specify default Python(s) #2846
Comments
Thanks for explaining the use case. This is a bit of historic artifice, and not defining base python means I don't care about the python version. They are some cases where this is useful, e.g., when calling
For those envs where the python version does matter, this was the recommended path ahead; and what I'd prefer people to do until today.
This solution happened to work, but not by design, and not our recommended way to do it, nor do we plan to encourage/support this. With some concrete use cases for this, I'm open to adding a |
Sure. If you're doing typing then it is desirable/necessary to install all dependencies. This isn't possible if one or more of the dependencies doesn't support the recent version of Python found on your host. This is particularly an issue for Fedora users due to the frequent updates there.
You say that, but I did explicitly call out the desire for this kind of thing when merging the Out of curiosity, what is the expected use case of
That sounds exactly like If I was going to redefine this, I'd add a new Edit One additional bonus of the new global value is that it provides an opportunity to explicitly document how |
Not entirely; I have many projects, especially web applications, where I'm using a single python version and don't use [tox]
env_list = test,format,lint,type_check
[testenv]
basepython = python3.11
There's a semantic difference; one is used if base_python is not specified, and the other is always on. This solution also keeps backwards compatibility nice, without needing to ignore the option selectively for some envs (like py38, py39, etc).
My first thought was also the core section, but then I thought you might want groups of envs where the default is different. E.g. for a,b,c default should be 3.11 but for c,d,e you don't care and happy to remain sys.executable. So putting it in env offers the config file more flexibility.
This should happen here https://tox.wiki/en/latest/config.html#base_python, not sure why it's not done today. It really should say that if not will try to extract the spec from a factor in the env name, and if that fails fallbacks to tox host pythons spec. |
There's still an implied priority though. [*] Admittedly it's not quite a simple as this. [testenv:py311]
base_python = python3.11-64
YAGNI? As I noted, my main use case for this is to insist that no environment use a new version of Python if the project under test doesn't support it. Personally, I think if I could do this: [tox]
default_base_python = python3.10,python3.9,python3.8,python3.7 I'd be happy, since that would allow us to run all envs against some version of Python that the project explicitly supports without stating a specific version (which could cause conflicts between different environments).
Yeah, definitely need docs here. |
[tox]
default_base_python = 3.10, 3.9, 3.8, 3.7 It would suffice, but I'll need to insist on adding this to I consider |
'[tox] skipsdist' behaves differently in tox 4 [1]. In addition, setting '[testenv] basepython' with '[tox] ignore_basepython_conflict' has been the cause of a few tox 4 bugs (most since fixed, thankfully) and might be deprecated [2]. Remove it since we don't need it in any of our environments. [1] tox-dev/tox#2730 [2] tox-dev/tox#2846 Signed-off-by: Stephen Finucane <[email protected]>
'[tox] skipsdist' behaves differently in tox 4 [1]. In addition, setting '[testenv] basepython' with '[tox] ignore_basepython_conflict' has been the cause of a few tox 4 bugs (most since fixed, thankfully) and might be deprecated [2]. Remove it since we don't need it in any of our environments. [1] tox-dev/tox#2730 [2] tox-dev/tox#2846 Signed-off-by: Stephen Finucane <[email protected]>
@stephenfin do you plan to put in a PR for this? |
Can do, but I'm on PTO this week so it'll be a while |
'[tox] skipsdist' behaves differently in tox 4 [1]. In addition, setting '[testenv] basepython' with '[tox] ignore_basepython_conflict' has been the cause of a few tox 4 bugs (most since fixed, thankfully) and might be deprecated [2]. Remove it since we don't need it in any of our environments. [1] tox-dev/tox#2730 [2] tox-dev/tox#2846 Conflicts: tox.ini NOTE(stephenfin): Conflicts are due to lack of support for Django 4.1. Signed-off-by: Stephen Finucane <[email protected]> (cherry picked from commit a03a0a5)
I reached this soon after I installed I guess that tox finds all versions and decides to use the one that seems to be the newest. Obviously that makes it a real problem for those that work on multiple projects, as they can no longer rely on using the easy |
What's the problem this feature will solve?
tox
defaults to using the Python version thattox
itself is installed under (retrieved viasys.executable
) for testenvs that do not contain a Python factor (e.g.py38
) or have not defined abase_python
/basepython
setting. This version varies depending on the user's environment: a contributor using Ubuntu 22.04 will have a default Python version of 3.10, while a contributor using Fedora 37 would have a default Python version of 3.11. This means a test run on one environment may result in different results that a test run in another. This harms reproducibility and leads to confusion. Worse, this can result in failures for users in environments with recent Python versions (e.g. Fedora users) as the package under test or one of its dependencies may not yet support newer Python versions.Currently, there are a few separate ways to resolve this.
tox
so that the call tosys.executable
returns the Python version(s) you want it to default to. This is obviously not something you should do.functional
becomesfunctional{-py37,-py38,-py39,-py310}
. This results in rather uglytox.ini
files and is tedious to use (tox -e functional
>tox -e functional-py310
).base_python
for every environment that does not contain a Python factor. Again, this is rather tedious (particularly for projects with a large number of testenvs) and prone to mistakes when writing yourtox.ini
file, but at least it's nicer to use for the end user.[testenv] base_python
and set the[tox] ignore_base_python_conflict
setting totrue
. This results in the simplesttox.ini
file and is easy to run.Currently,
5.
provides the nicest blend betweentox.ini
simplicity and end-user usability. Unfortunately though, there is talk of the[tox] ignore_base_python_conflict
setting being removed meaning this option might not be available in the future.Describe the solution you'd like
I would like to be able to specify a global default Python version to be used when a Python version is not already defined via a factor. Put another way, I want a user-configurable way to override the default version derived
sys.executable
.Alternative Solutions
ignore_base_python_conflict
.ignore_base_python_conflict
but make itstrue
behaviour the default (so Python version specified via a factor always trumpsbase_python
, without warning, if there's a conflict)tox
- use containers (tbc, this is not a realistic solution 😄)Additional context
The text was updated successfully, but these errors were encountered: