Skip to content
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

Package resolution fails if the package name contains a dot #6206

Open
oz123 opened this issue Jul 18, 2024 · 4 comments
Open

Package resolution fails if the package name contains a dot #6206

oz123 opened this issue Jul 18, 2024 · 4 comments
Assignees
Labels
ai-triaged Type: Documentation 📖 This issue relates to documentation of pipenv.

Comments

@oz123
Copy link
Contributor

oz123 commented Jul 18, 2024

Issue description

I am trying to install mach.py with pipenv but it fails:

Expected result

The package mach.py should not raise an exception.

Actual result

$pipenv install mach.py
Installing mach.py...
Resolving mach.py...
Added mach.py to Pipfile's [packages] ...
✔ Installation Succeeded
Pipfile.lock (eae6ec) out of date: run `pipfile lock` to update to (7a1a8e)...
Running $ pipenv lock then $ pipenv sync.
Locking [packages] dependencies...
Building requirements...
Resolving dependencies...
✘ Locking Failed!
⠧ Locking packages...False
ERROR:pip.subprocessor:python setup.py egg_info exited with 1
[ResolutionFailure]:   File "/usr/lib/python3.12/site-packages/pipenv/resolver.py", line 651, in _main
[ResolutionFailure]:       resolve_packages(
[ResolutionFailure]:   File "/usr/lib/python3.12/site-packages/pipenv/resolver.py", line 618, in resolve_packages
[ResolutionFailure]:       results, resolver = resolve(
[ResolutionFailure]:       ^^^^^^^^
[ResolutionFailure]:   File "/usr/lib/python3.12/site-packages/pipenv/resolver.py", line 598, in resolve
[ResolutionFailure]:       return resolve_deps(
[ResolutionFailure]:       ^^^^^^^^^^^^^
[ResolutionFailure]:   File "/usr/lib/python3.12/site-packages/pipenv/utils/resolver.py", line 932, in resolve_deps
[ResolutionFailure]:       results, hashes, internal_resolver = actually_resolve_deps(
[ResolutionFailure]:       ^^^^^^^^^^^^^^^^^^^^^^
[ResolutionFailure]:   File "/usr/lib/python3.12/site-packages/pipenv/utils/resolver.py", line 700, in actually_resolve_deps
[ResolutionFailure]:       resolver.resolve()
[ResolutionFailure]:   File "/usr/lib/python3.12/site-packages/pipenv/utils/resolver.py", line 457, in resolve
[ResolutionFailure]:       raise ResolutionFailure(message=str(e))
[pipenv.exceptions.ResolutionFailure]: Warning: Your dependencies could not be resolved. You likely have a mismatch in your sub-dependencies.
  You can use $ pipenv run pip install <requirement_name> to bypass this mechanism, then run $ pipenv graph to inspect the versions actually installed in the virtualenv.
  Hint: try $ pipenv lock --pre if it is a pre-release dependency.
ERROR: metadata generation failed

Traceback (most recent call last):
  File "/usr/lib/python-exec/python3.12/pipenv", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File "/usr/lib/python3.12/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/pipenv/cli/options.py", line 58, in main
    return super().main(*args, **kwargs, windows_expand_args=False)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/click/decorators.py", line 92, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/pipenv/cli/command.py", line 209, in install
    do_install(
  File "/usr/lib/python3.12/site-packages/pipenv/routines/install.py", line 234, in do_install
    raise e
  File "/usr/lib/python3.12/site-packages/pipenv/routines/install.py", line 209, in do_install
    do_init(
  File "/usr/lib/python3.12/site-packages/pipenv/routines/install.py", line 635, in do_init
    do_update(
  File "/usr/lib/python3.12/site-packages/pipenv/routines/update.py", line 61, in do_update
    do_lock(
  File "/usr/lib/python3.12/site-packages/pipenv/routines/lock.py", line 66, in do_lock
    venv_resolve_deps(
  File "/usr/lib/python3.12/site-packages/pipenv/utils/resolver.py", line 873, in venv_resolve_deps
    c = resolve(cmd, st, project=project)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/pipenv/utils/resolver.py", line 737, in resolve
    raise RuntimeError("Failed to lock Pipfile.lock!")
RuntimeError: Failed to lock Pipfile.lock!

$ pipenv --support

Pipenv version: '2024.0.1'

Pipenv location: '/usr/lib/python3.12/site-packages/pipenv'

Python location: '/usr/bin/python3.12'

OS Name: 'posix'

User pip version: '24.0'

user Python installations found:

PEP 508 Information:

{'implementation_name': 'cpython',
 'implementation_version': '3.12.3',
 'os_name': 'posix',
 'platform_machine': 'x86_64',
 'platform_python_implementation': 'CPython',
 'platform_release': '6.9.2-gentoo-nvidia-bachefs-r3',
 'platform_system': 'Linux',
 'platform_version': '#1 SMP PREEMPT_DYNAMIC Thu May 30 21:03:18 CEST 2024',
 'python_full_version': '3.12.3',
 'python_version': '3.12',
 'sys_platform': 'linux'}

If you're on macOS, run the following:

$ pipenv --support | pbcopy

If you're on Windows, run the following:

> pipenv --support | clip

If you're on Linux, run the following:

$ pipenv --support | xclip
@oz123 oz123 self-assigned this Jul 21, 2024
@matteius
Copy link
Member

Works if you put quotes around package name.

matte@LAPTOP-N5VSGIBD MINGW64 ~/Projects/pipenv-triage/issue-6206
$ pipenv  install "mach.py"
Creating a virtualenv for this project
Pipfile: C:\Users\matte\Projects\pipenv-triage\issue-6206\Pipfile
Using default python from C:\Users\matte\AppData\Local\Programs\Python\Python311\python.exe3.11.2 to create virtualenv...
[=== ] Creating virtual environment...created virtual environment CPython3.11.2.final.0-64 in 4810ms
  creator CPython3Windows(dest=C:\c\users\matte\.virtualenvs\issue-6206-mx6QrnoR, clear=False, no_vcs_ignore=False, global=False)
  seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy,
app_data_dir=C:\Users\matte\AppData\Local\pypa\virtualenv)
                         pip[ ===]== Creating virtual environment...24.0, setuptools==70.0.0, wheel==0.43.0
  activators BashActivator,BatchActivator,FishActivator,NushellActivator,PowerShellActivator,PythonActivator

Successfully created virtual environment!
Virtualenv location: C:\c\Users\matte\.virtualenvs\issue-6206-mx6QrnoR
Creating a Pipfile for this project...
Installing mach.py...
Resolving mach.py...
Added mach.py to Pipfile's [packages] ...
Installation Succeeded
Pipfile.lock not found, creating...
Locking [packages] dependencies...
Building requirements...
Resolving dependencies...
Success!
Locking [dev-packages] dependencies...
Updated Pipfile.lock (ab150dbf003deb8b02a8be19a9ee420c8bd61bb3bb168dea8f8c357d67528ea2)!
To activate this project's virtualenv, run pipenv shell.
Alternatively, run a command inside the virtualenv with pipenv run.
Installing dependencies from Pipfile.lock (528ea2)...

matte@LAPTOP-N5VSGIBD MINGW64 ~/Projects/pipenv-triage/issue-6206
$ cat Pipfile
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
"mach.py" = "*"

[dev-packages]

[requires]
python_version = "3.11"

matte@LAPTOP-N5VSGIBD MINGW64 ~/Projects/pipenv-triage/issue-6206
$ cat Pipfile.lock
{
    "_meta": {
        "hash": {
            "sha256": "ab150dbf003deb8b02a8be19a9ee420c8bd61bb3bb168dea8f8c357d67528ea2"
        },
        "pipfile-spec": 6,
        "requires": {
            "python_version": "3.11"
        },
        "sources": [
            {
                "name": "pypi",
                "url": "https://pypi.org/simple",
                "verify_ssl": true
            }
        ]
    },
    "default": {
        "mach.py": {
            "hashes": [
                "sha256:a06b596331d5a9d23a9430dc52449b5699ed55559407e9467696bad492bf19f6"
            ],
            "version": "==0.4.4"
        }
    },
    "develop": {}
}

@oz123
Copy link
Contributor Author

oz123 commented Jul 27, 2024

Does fixing this really requires code intervention or just documentation?

@matteius
Copy link
Member

I am not sure we can fix it with code, because the shell command is what gets confused by the dot. Unless you know of a way ...

@matteius matteius added the Type: Documentation 📖 This issue relates to documentation of pipenv. label Aug 28, 2024
@matteius
Copy link
Member

Analysis of Issue #6206

1. Problem Summary

The core issue is that Pipenv fails to resolve and install packages if the package name contains a dot (".") without being enclosed in quotes. This is because the shell interprets the dot as a path separator, leading to confusion during package resolution.

2. Comment Discussion Analysis

  • matteius demonstrates that enclosing the package name in quotes ("mach.py") successfully resolves the issue, suggesting the problem lies in the shell command parsing.
  • oz123 raises a valid question: whether the solution lies in code changes or simply updating the documentation to guide users on using quotes for such packages.
  • matteius acknowledges the limitation of fixing it solely through code, as the shell's interpretation of the dot is the root cause.

3. Proposed Resolution

While a complete code-based solution to prevent the shell from misinterpreting dots may be challenging, the following steps can effectively address the issue:

  • Update Documentation: The Pipfile documentation should be updated to explicitly state that package names containing dots need to be enclosed in quotes during installation. This clarifies the expected syntax for users and prevents confusion.
  • Improve Error Handling: Pipenv could implement a check to detect package names containing dots that are not enclosed in quotes. Instead of a generic resolution error, Pipenv could provide a more specific error message, guiding the user to use quotes.

4. Potential Code Changes

Improved error handling in pipenv/utils/resolver.py:

	      for package_name, dep in deps.items():
	          if not dep:
	              continue
	          # Check if package name contains a dot and is not enclosed in quotes
	          if "." in package_name and not (
	              package_name.startswith('"') and package_name.endswith('"')
	          ):
	              raise exceptions.ResolutionFailure(
	                  message=f"Package name '{package_name}' contains a dot (.) and must be enclosed in quotes."
	              )
	          canonical_package_name = canonicalize_name(package_name)

This modification will catch the problematic package name before resolution, raising a specific error message instructing the user to enclose the name in quotes.

5. Additional Steps/Investigations

  • Thorough Testing: After implementing the documentation and error handling changes, rigorous testing should be conducted with various package names containing dots to ensure the issue is fully resolved.
  • Alternative Solutions: Explore potential solutions to sanitize or escape the dot character during shell command construction, if feasible without introducing other issues or complexities. This could provide a more robust code-based solution.
  • User Feedback: Encourage users to report similar issues and provide feedback on the updated documentation to ensure clarity and ease of use.

By combining clear documentation and improved error handling, Pipenv can effectively address this issue, making the package installation process smoother for users dealing with packages containing dots in their names.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ai-triaged Type: Documentation 📖 This issue relates to documentation of pipenv.
Projects
None yet
Development

No branches or pull requests

2 participants