Skip to content

Commit 58a190f

Browse files
committed
don't pass through -p if using the default version
1 parent 7162a3d commit 58a190f

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

pre_commit/languages/python.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,11 @@ def _sys_executable_matches(version: str) -> bool:
132132
return sys.version_info[:len(info)] == info
133133

134134

135-
def norm_version(version: str) -> str:
136-
if version == C.DEFAULT:
137-
return os.path.realpath(sys.executable)
138-
139-
# first see if our current executable is appropriate
140-
if _sys_executable_matches(version):
141-
return sys.executable
135+
def norm_version(version: str) -> Optional[str]:
136+
if version == C.DEFAULT: # use virtualenv's default
137+
return None
138+
elif _sys_executable_matches(version): # virtualenv defaults to our exe
139+
return None
142140

143141
if os.name == 'nt': # pragma: no cover (windows)
144142
version_exec = _find_by_py_launcher(version)
@@ -194,8 +192,10 @@ def install_environment(
194192
additional_dependencies: Sequence[str],
195193
) -> None:
196194
envdir = prefix.path(helpers.environment_dir(ENVIRONMENT_DIR, version))
195+
venv_cmd = [sys.executable, '-mvirtualenv', envdir]
197196
python = norm_version(version)
198-
venv_cmd = (sys.executable, '-mvirtualenv', envdir, '-p', python)
197+
if python is not None:
198+
venv_cmd.extend(('-p', python))
199199
install_cmd = ('python', '-mpip', 'install', '.', *additional_dependencies)
200200

201201
with clean_path_on_failure(envdir):

tests/languages/python_test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,14 @@ def test_norm_version_expanduser():
3636

3737

3838
def test_norm_version_of_default_is_sys_executable():
39-
assert python.norm_version('default') == os.path.realpath(sys.executable)
39+
assert python.norm_version('default') is None
4040

4141

4242
@pytest.mark.parametrize('v', ('python3.6', 'python3', 'python'))
4343
def test_sys_executable_matches(v):
4444
with mock.patch.object(sys, 'version_info', (3, 6, 7)):
4545
assert python._sys_executable_matches(v)
46+
assert python.norm_version(v) is None
4647

4748

4849
@pytest.mark.parametrize('v', ('notpython', 'python3.x'))

0 commit comments

Comments
 (0)