Skip to content

Pipfile: dev-packages cause an error if main dependencies use a custom index repo #6237

@stokito

Description

@stokito

Issue description

I have a Pipfile with two sources: pypi and internal for a company. In packages declared dependencies from the internal index. Additionally there is the dev-packages that declares one dep:

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

[[source]]
name = "internal"
url = "https://artifactory.example.net/artifactory/api/pypi/internal/simple"
verify_ssl = true


[requires]
python_version = "3.11"

[packages]
internal-dependency = { version = "1.0.0", index = "internal" }

[dev-packages]
tox = "*"

Expected result

When making the pipenv lock it resolves deps and creates the Pipfile.lock.

Actual result

  File "~/project/venv/lib/python3.11/site-packages/pipenv/patched/pip/_vendor/packaging/requirements.py", line 113, in __init__
    raise InvalidRequirement(
pipenv.patched.pip._vendor.packaging.requirements.InvalidRequirement: Parse error at ""'1.0.0'"": Expected string_end

The exception thrown in the code:

        try:
            req = REQUIREMENT.parseString(requirement_string)
        except ParseException as e:
            raise InvalidRequirement(
                f'Parse error at "{ requirement_string[e.loc : e.loc + 8]!r}": {e.msg}'
            )

The requirement_string is internal-dependency=={'version': '1.0.0', 'index': 'internal'}.
It looks like the regexp REQUIREMENT doesn't expect the index at all:

NAMED_REQUIREMENT = NAME + Optional(EXTRAS) + (URL_AND_MARKER | VERSION_AND_MARKER) + Optional(INDEX_NAME)
REQUIREMENT = stringStart + NAMED_REQUIREMENT + stringEnd

But here it comes the most strange part: when I removed all deps from the dev-packages it started working well.

Anyway, let's add the requirement_string to the exception message because it's very complicated to figure out the problem because the temp file is removed and a user has nothing to see at all.


$ pipenv --support

Pipenv version: '2024.0.1'

OS Name: 'posix'

User pip version: '24.0'

user Python installations found:

PEP 508 Information:

{'implementation_name': 'cpython',
 'implementation_version': '3.11.10',
 'os_name': 'posix',
 'platform_machine': 'x86_64',
 'platform_python_implementation': 'CPython',
 'platform_release': '6.8.0-41-generic',
 'platform_system': 'Linux',
 'platform_version': '#41-Ubuntu SMP PREEMPT_DYNAMIC Fri Aug  2 20:41:06 UTC '
                     '2024',
 'python_full_version': '3.11.10',
 'python_version': '3.11',
 'sys_platform': 'linux'}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions