Skip to content

Displayed path in error message contains additional leading slash #6515

@edmorley

Description

@edmorley

Issue description

When this Python version compatibility error message is displayed:

err.print(
f"[red][bold]Warning[/bold][/red]: Your Pipfile requires "
f'[bold]"python_version"[/bold] [cyan]{project.required_python_version}[/cyan], '
f"but you are using [cyan]{python_version(path_to_python)}[/cyan] "
f"from [green]{shorten_path(path_to_python)}[/green]."
)

...it prints paths with an additional leading forward slash like so:

Warning: Your Pipfile requires "python_version" 3.11, but you are using 3.13.10 
from //usr/local/bin/python3.

ie: It should print the path /usr/local/bin/python3 not //usr/local/bin/python3.

I'm presuming this is a bug in shorten_path():

def shorten_path(location, bold=False):
"""Returns a visually shorter representation of a given system path."""
path = Path(location) if not isinstance(location, Path) else location
path_parts = list(path.parts)
short_parts = [p[0] if len(p) > len("2long4") else p for p in path_parts[:-1]]
short_parts.append(path_parts[-1])
if bold:
short_parts[-1] = f"[bold]{short_parts[-1]}[/bold]"
return os.sep.join(short_parts)

Expected result

Warning: Your Pipfile requires "python_version" 3.11, but you are using 3.13.10 
from /usr/local/bin/python3.

Actual result

Warning: Your Pipfile requires "python_version" 3.11, but you are using 3.13.10 
from //usr/local/bin/python3.

Steps to replicate

Create this Dockerfile:

FROM python:3.13.10-slim
WORKDIR /testcase

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

[packages]
typing-extensions = "*"

[requires]
python_version = "3.11"
EOF

COPY <<EOF Pipfile.lock
{
    "_meta": {
        "hash": {
            "sha256": "5a5846099fd5ceb0291e704a94f49cf0b8a226109fdae915a61253b56eaf3ed6"
        },
        "pipfile-spec": 6,
        "requires": {
            "python_version": "3.11"
        },
        "sources": [
            {
                "name": "pypi",
                "url": "https://pypi.org/simple",
                "verify_ssl": true
            }
        ]
    },
    "default": {
        "typing-extensions": {
            "hashes": [
                "sha256:a439e7c04b49fec3e5d3e2beaa21755cadbbdc391694e28ccdd36ca4a1408f8c",
                "sha256:e6c81219bd689f51865d9e372991c540bda33a0379d5573cddb9a3a23f7caaef"
            ],
            "index": "pypi",
            "markers": "python_version >= '3.8'",
            "version": "==4.13.2"
        }
    },
    "develop": {}
}
EOF

RUN pip install pipenv==v2026.0.3 --disable-pip-version-check --quiet --root-user-action ignore
RUN pipenv install --deploy --system

Then run it with:
docker build . --progress plain --no-cache

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions