Skip to content

Installing an editable package can result in using the wrong canonical package name in Pipfile #6409

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

Open
stewartmiles opened this issue May 21, 2025 · 2 comments · May be fixed by #6411
Open
Labels
Type: Bug 🐛 This issue is a bug.

Comments

@stewartmiles
Copy link
Contributor

Issue description

Create a local Python package called mypackage with a mypackage/mypackage/tests/test_setup.py file (see mypackage.zip):

import unittest

class TestNothing(unittest.TestCase):
    def setup(**kwargs):
        pass

    def test_nada(self):
        _ = setup(name='foo')
  • Create a pipenv virtual environment using say
    ( export PIPENV_NO_INHERIT=1; pipenv run echo )
  • Install the package as editable using pipenv install -e ./mypackage
  • See the package installed in the Pipfile uses the name in inferred from test file not the top level setup.py, i.e: grep mypackage Pipfile shows foo = {file = "mypackage"} not mypackage = {file = "mypackage"} as expected.

Expected result

The package should be named correctly in Pipfile.

Actual result

The package name is incorrectly parsed from a test file.

Steps to replicate

See above.


Please run $ pipenv --support, and paste the results here. Don't put backticks (`) around it! The output already contains Markdown formatting.

$ pipenv --support

Pipenv version: '2025.0.2'

Pipenv location: '/home/stewart/.local/share/pipx/venvs/pipenv/lib/python3.10/site-packages/pipenv'

Python location: '/home/stewart/.local/share/pipx/venvs/pipenv/bin/python'

OS Name: 'posix'

User pip version: '25.0.1'

user Python installations found:

  • 3.10.12: /usr/bin/python3
  • 3.10.12: /usr/bin/python
  • 3.10.12: /bin/python3
  • 3.10.12: /bin/python
  • 3.8.20: /usr/bin/python3.8
  • 3.8.20: /bin/python3.8

PEP 508 Information:

{'implementation_name': 'cpython',
 'implementation_version': '3.10.12',
 'os_name': 'posix',
 'platform_machine': 'x86_64',
 'platform_python_implementation': 'CPython',
 'platform_release': '6.8.0-59-generic',
 'platform_system': 'Linux',
 'platform_version': '#61~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue Apr 15 '
                     '17:03:15 UTC 2',
 'python_full_version': '3.10.12',
 'python_version': '3.10',
 'sys_platform': 'linux'}

System environment variables:

  • SHELL
  • PIPENV_VENV_IN_PROJECT
  • TERMCAP
  • SSH_AUTH_SOCK
  • WINDOW
  • SSH_AGENT_PID
  • PWD
  • LOGNAME
  • XDG_SESSION_TYPE
  • MOTD_SHOWN
  • HOME
  • LANG
  • LS_COLORS
  • SSH_CONNECTION
  • LESSCLOSE
  • XDG_SESSION_CLASS
  • TERM
  • LESSOPEN
  • USER
  • XLA_FLAGS
  • SHLVL
  • XDG_SESSION_ID
  • LD_LIBRARY_PATH
  • XDG_RUNTIME_DIR
  • SSH_CLIENT
  • XDG_DATA_DIRS
  • PATH
  • STY
  • DBUS_SESSION_BUS_ADDRESS
  • SSH_TTY
  • OLDPWD
  • _
  • PIP_DISABLE_PIP_VERSION_CHECK
  • PYTHONDONTWRITEBYTECODE
  • PIP_FIND_LINKS
  • PIP_NO_BUILD_ISOLATION
  • PIPENV_SKIP_LOCK

Pipenv–specific environment variables:

  • PIPENV_VENV_IN_PROJECT: true
  • PIPENV_SKIP_LOCK: true

Debug–specific environment variables:

  • PATH: /home/stewart/bin/node/bin:/usr/local/cuda/bin:/usr/local/nvidia/bin:/home/stewart/bin/cmake/bin:~/.local/bin:/home/stewart/.local/bin:/home/stewart/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/opt/halyard/bin
  • SHELL: /bin/bash
  • LANG: en_US.UTF-8
  • PWD: /home/stewart/src/agentic/service/tmp

Contents of Pipfile ('/home/stewart/src/agentic/service/tmp/Pipfile'):

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

[packages]
foo = {file = "mypackage", editable = true}

[dev-packages]

[requires]
python_version = "3.10"
@stewartmiles
Copy link
Contributor Author

This code is incorrectly treating any filename that ends with setup.py as a potential setuptools setup.py file:

if filename.endswith("setup.py"):
content = file.read().decode()
possible_name = parse_setup_file(content)
if possible_name:
return possible_name

The filename argument to this function is the basename file being checked so - if I'm following this correctly - it should be possible to perform a direct comparison rather than using .endwith such that setup.py matches and test_setup.py does not.

@stewartmiles
Copy link
Contributor Author

Oh also, the following will search leaf directories before checking parent directories for files as directories are searched before files within a directory:

directory_contents = sorted(
directory_path.iterdir(), key=lambda x: (x.is_file(), x.name)
)
for path in directory_contents:
if path.is_file():
if path.name.endswith(RELEVANT_PROJECT_FILES):
with path.open("rb") as file:
possible_name = find_package_name_from_filename(path.name, file)
if possible_name:
return possible_name
elif path.is_dir():
possible_name = find_package_name_from_directory(str(path))
if possible_name:
return possible_name

i.e:

given:

mypackage/setup.py
mypackage/tests/setup.py

it looks like this will search in the order:

mypackage/tests/setup.py
mypackage/setup.py

@matteius matteius added the Type: Bug 🐛 This issue is a bug. label May 21, 2025
stewartmiles added a commit to stewartmiles/pipenv that referenced this issue May 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug 🐛 This issue is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants