Skip to content

Commit 4a1d10e

Browse files
committed
_default_python method added
1 parent aa63728 commit 4a1d10e

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

conan/tools/system/pip_manager.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,13 @@ def generate(self):
2424
env.prepend_path("PATH", self.bin_dir)
2525
env.vars(self._conanfile).save_script(self.env_name)
2626

27-
def _create_venv(self):
27+
@staticmethod
28+
def _default_python():
2829
default_python = shutil.which('python') if platform.system() == "Windows" else shutil.which('python3')
29-
python_interpreter = self._conanfile.conf.get("tools.system.pipenv:python_interpreter",
30-
default=os.path.realpath(default_python) if default_python else None)
30+
return os.path.realpath(default_python) if default_python else None
31+
32+
def _create_venv(self):
33+
python_interpreter = self._conanfile.conf.get("tools.system.pipenv:python_interpreter") or self._default_python()
3134
if not python_interpreter:
3235
raise ConanException("PipEnv could not find a Python executable path."
3336
"Please set 'tools.system.pipenv:python_interpreter' to '</your/python/full/path>' "

test/integration/tools/system/pip_manager_test.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
from conan.test.utils.mocks import ConanFileMock
99

1010

11-
def test_pipenv_conf():
11+
@patch('shutil.which')
12+
def test_pipenv_conf(mock_shutil_which):
1213
# https://github.com/conan-io/conan/issues/11661
1314
conanfile = ConanFileMock()
1415
conanfile.settings = Settings()
16+
mock_shutil_which.side_effect = Exception()
1517
conanfile.conf.define("tools.system.pipenv:python_interpreter", "/python/interpreter/from/config")
1618
result = "/python/interpreter/from/config -m venv"
1719
pipenv = PipEnv(conanfile, "testenv")

0 commit comments

Comments
 (0)