pythonfinder icon indicating copy to clipboard operation
pythonfinder copied to clipboard

ValueError if the interpreter path starts with a dot

Open hansingt opened this issue 3 years ago • 0 comments

As recorded in https://github.com/pypa/pipenv/issues/4588 and https://github.com/tox-dev/tox-pipenv/issues/68, pythonfinder seems to have problems, when the path to the interpeter starts with a dot.

Using the followin tox.ini:

[tox]
requires = tox-pipenv
envlist = py310

[testenv]
skip_install = true

and this Pipfile

[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]

[dev-packages]
pytest = "*"

[requires]
python_version = "3.10"

a call to tox -e py310 raises the following traceback:

tox -e py310
.tox create: /home/tha/test/.tox/.tox
.tox installdeps: tox-pipenv, tox >= 3.25.0
py310 create: /home/tha/test/.tox/py310
ERROR: invocation failed (exit code 1), logfile: /home/tha/test/.tox/py310/log/py310-0.log
================================================================= log start ==================================================================
Traceback (most recent call last):
  File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/home/tha/test/.tox/.tox/lib/python3.10/site-packages/pipenv/__main__.py", line 4, in <module>
    cli()
  File "/home/tha/test/.tox/.tox/lib/python3.10/site-packages/pipenv/vendor/click/core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
  File "/home/tha/test/.tox/.tox/lib/python3.10/site-packages/pipenv/cli/options.py", line 56, in main
    return super().main(*args, **kwargs, windows_expand_args=False)
  File "/home/tha/test/.tox/.tox/lib/python3.10/site-packages/pipenv/vendor/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "/home/tha/test/.tox/.tox/lib/python3.10/site-packages/pipenv/vendor/click/core.py", line 1637, in invoke
    super().invoke(ctx)
  File "/home/tha/test/.tox/.tox/lib/python3.10/site-packages/pipenv/vendor/click/core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/tha/test/.tox/.tox/lib/python3.10/site-packages/pipenv/vendor/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/home/tha/test/.tox/.tox/lib/python3.10/site-packages/pipenv/vendor/click/decorators.py", line 84, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/home/tha/test/.tox/.tox/lib/python3.10/site-packages/pipenv/vendor/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/home/tha/test/.tox/.tox/lib/python3.10/site-packages/pipenv/vendor/click/decorators.py", line 26, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/tha/test/.tox/.tox/lib/python3.10/site-packages/pipenv/cli/command.py", line 193, in cli
    ensure_project(
  File "/home/tha/test/.tox/.tox/lib/python3.10/site-packages/pipenv/core.py", line 553, in ensure_project
    ensure_virtualenv(
  File "/home/tha/test/.tox/.tox/lib/python3.10/site-packages/pipenv/core.py", line 473, in ensure_virtualenv
    python = ensure_python(project, three=three, python=python)
  File "/home/tha/test/.tox/.tox/lib/python3.10/site-packages/pipenv/core.py", line 362, in ensure_python
    path_to_python = find_a_system_python(python)
  File "/home/tha/test/.tox/.tox/lib/python3.10/site-packages/pipenv/core.py", line 333, in find_a_system_python
    python_entry = find_python(finder, line)
  File "/home/tha/test/.tox/.tox/lib/python3.10/site-packages/pipenv/utils/shell.py", line 309, in find_python
    result = finder.find_python_version(line)
  File "/home/tha/test/.tox/.tox/lib/python3.10/site-packages/pipenv/vendor/pythonfinder/pythonfinder.py", line 262, in find_python_version
    version_dict = self.parse_major(major, minor=minor, patch=patch, arch=arch)
  File "/home/tha/test/.tox/.tox/lib/python3.10/site-packages/pipenv/vendor/pythonfinder/pythonfinder.py", line 209, in parse_major
    int(version_dict["major"]) if version_dict.get("major") is not None else major
ValueError: invalid literal for int() with base 10: '.tox/bin/python'

================================================================== log end ===================================================================
ERROR: InvocationError for command /home/tha/test/.tox/.tox/bin/python -m pipenv --python .tox/bin/python (exited with code 1)

According to https://github.com/tox-dev/tox/issues/1339 the root of this particular problem seems to be a behaviour change in tox 3.8 where pathes got relative.

But the main issue is, that pythonfinder seems to try to parse the version number from the filename and this fails if the path starts with a dot.

hansingt avatar Jun 15 '22 05:06 hansingt