setuptools: [BUG] Wheel naming is not following PEP 491 convention

setuptools version

setuptools==66.0.0

Python version

python 3.8

OS

macOS

Additional environment information

No response

Description

I am building a wheel for a python package using setuptools and it seems that the naming of my wheel file is not respecting the PEP 491 convention.

For external reasons, I need to name my package with the structure {namespace}.{package-name}. If I follow the convention, I would expect that my wheel file is named: namespace_package_name-0.1.0-py2.py3-none-any.whl.

However, I get this name for my wheel: namespace.package_name-0.1.0-py2.py3-none-any.whl, which is not respecting the convention.

Expected behavior

I expect the “.” in the package name to be replaced with a “_” in the wheel name.

How to Reproduce

  1. create a hello_world package structure:
    hello_world
    |- my_package
    |    |- __init__.py
    |    |- hello_world.py
    |- pyproject.toml
    |- setup.cfg
    
  2. in setup.cfg, write:
    [metadata]
    name = namespace.my-package
    version = 0.1.0
    
    [options]
    zip_safe = False
    include_package_data = True
    packages = find:
    
  3. in project.toml, write:
    [build-system]
    requires = ["setuptools==66.0.0", "wheel"]
    build-backend = "setuptools.build_meta"
    
  4. run pipx run build at the root of your hello_world package
  5. inspect the dist directory which was created

Output

in the dist folder, you find:

  • namespace.my_package-0.1.0-py3-none-any.whl

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 2
  • Comments: 19 (13 by maintainers)

Commits related to this issue

Most upvoted comments

Took a shot at fixing this bug, I think https://github.com/pypa/setuptools/pull/4766 will resolve it but there’s one failing test that I haven’t been able to figure out.

Hi @jaraco, there was a discussion recently on the Python discourse about the normalisation of the distribution file names https://discuss.python.org/t/change-in-pypi-upload-behavior-intentional-accidental-pebkac/27707. I will try to summarise the key takeaways I found on why most of the community seems to be in favour of the normalisation. Hopefully this answers the question “What was the motivation for mangling them?”:

  1. PyPI (as a public package index) has very strong reasons for enforcing strict uniqueness checks (security reasons, competition between publishers that might confuse users, etc…). Therefore it is not viable to differentiate between distributions named after “normal packages” and namespace packages on PyPI.
  2. pip, whose primary use case is to download from PyPI, prefers to rule out the possibility of treating distributions named after namespace packages and “normal packages” as two different distributions. This is compatible with PyPI and also helps users to fix unintentional typing errors and avoid downloading wrong/malicious distributions.
  3. Members of the community defend that having one normalisation rule to be applied everywhere would be simpler.
  4. There is some advantage in normalising the .dist-info/.egg-info directory (faster lookup), and if I understood correct this would also help to optimise the checks for conflicting distributions already installed (since .dist-info serves as a database).
  5. Private indexes have to follow PEP 503 and do name normalisation. So it is not possible for distributions named a.b and a_b to coexist in the same private index.
  6. There is some level of agreement that Name in the PKG-INFO/METADATA files should not be normalised and reflect the user’s input.

So it seems that the name change unlocks optimisations and simplifications.

@bastienqb, if you would like you can chip in the discussion on https://discuss.python.org/t/change-in-pypi-upload-behavior-intentional-accidental-pebkac/27707 to explain why keeping the names in the format {namespace}.{package-name} is important. Otherwise there seems to be a push in the community for a strict standard that normalises the file name (as a mean to unlock the optimisations and simplifications I mentioned before).

Fixed the failing test in #4766, so there shouldn’t be any other blockers here.

FYI, we’d like to start warning about this on PyPI, but don’t want to do that until users have an upgrade path to a setuptools version which produces the correct filenames: https://github.com/pypi/warehouse/issues/17377

I concede. It doesn’t matter what the motivation was to consider . and _ equivalent, but they are now by consensus.