-
-
Notifications
You must be signed in to change notification settings - Fork 522
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow user to inject specific Pythons to try as step 1 during discovery
At the moment it's unecessarily hard to specify a specific python executable to use for a given spec. While mangling with the path might work for environments for tox environments that require a python differing the host tox python version; for environments matching the host tox interpreter it's impossible to use any other interpreter than what tox uses. Here we add a CLI argument (fallback to some environment variable for CI usage) that allows the user to inject custom python interpreters as step 1 of the discovery mechanism. Signed-off-by: Bernat Gabor <bgabor8@bloomberg.net>
- Loading branch information
1 parent
ff6368b
commit 1c5c716
Showing
5 changed files
with
49 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Add ``--discover`` (fallback to ``TOX_DISCOVER`` environment variable via path separator) to inject python executables | ||
to try as first step of a discovery - note the executable still needs to match the environment by :user:`gaborbernat`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import os | ||
|
||
from tox.interpreters.py_spec import CURRENT, PythonSpec | ||
from tox.interpreters.via_path import exe_spec | ||
|
||
|
||
def base_discover(envconfig): | ||
base_python = envconfig.basepython | ||
spec = PythonSpec.from_name(base_python) | ||
|
||
# 1. check passed in discover elements | ||
discovers = envconfig.config.option.discover | ||
if not discovers: | ||
discovers = os.environ.get(str("TOX_DISCOVER"), "").split(os.pathsep) | ||
for discover in discovers: | ||
if os.path.exists(discover): | ||
cur_spec = exe_spec(discover, envconfig.basepython) | ||
if cur_spec is not None and cur_spec.satisfies(spec): | ||
return spec, cur_spec.path | ||
|
||
# 2. check current | ||
if spec.name is not None and CURRENT.satisfies(spec): | ||
return spec, CURRENT.path | ||
|
||
return spec, None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters