pdm-project / pdm-backend

The build backend used by PDM that supports latest packaging standards.
https://backend.pdm-project.org
MIT License
70 stars 34 forks source link

Different names generated for sdist and wheel #111

Closed lelit closed 2 years ago

lelit commented 2 years ago

Sorry to bother you, but I'm getting crazy trying to understand modern packaging rules, and here I'm asking an opinion/confirmation.

I'm trying to modernize this aspect of several projects of mine, replacing setup.py with pyproject.toml, and I had different issues with every build system I tried, maybe due to the peculiar name scheme I followed for them, or instead because the specifications are imprecise and everyone interprets them in different ways.

I found your project the less problematic as of now (read, I did not have any issue), and I'm taking the opportunity to say "thank you!".

Today I converted another project, whose distribution name is metapensiero.sphinx.autodoc_sa: everything went smooth, except that I noticed a difference in the name of the generated file for sdist and wheel:

$ ls -rt1 dist/
...
metapensiero.sphinx.autodoc_sa-1.7.tar.gz
metapensiero.sphinx.autodoc_sa-2.0.tar.gz
metapensiero.sphinx.autodoc_sa-2.1.tar.gz
metapensiero.sphinx.autodoc-sa-2.2.dev0.tar.gz
metapensiero.sphinx.autodoc_sa-2.2.dev0-py3-none-any.whl

The latest version, 2.2.dev0, is the one converted to use pdm-pep517: as you can see, the sdist contains autodoc-sa (with an hypen) while the wheel has autodoc_sa (with underscore). Previous versions were generated by setuptools (that is, by python setup.py sdist).

I tried uploading those new archives to test.pypi.org and they were accepted: at first I expected a rejection due to different name, as it happened for one other project when I used flit as build system, but I was wrong :-)

To satisfy my curiosity, I tried to find references to the file name conventions, and I found this section on PyPA:

The file name of a sdist is not currently standardised, although the de facto form is {name}-{version}.tar.gz, where {name} is the canonicalized form of the project name (see PEP 503 for the canonicalization rules) with - characters replaced with _

That makes me wonder: it seems rather contradictory that it first suggests to replace runs of invalid characters with a single hyphen, but then says to replace that hyphen with an underscore.

So the question is: should I relax and accept the apparent confusion, or is there an issue in the way pdm-pep517 generates the sdist (using metadata.project_name) vs the wheel (that instead uses metadata.project_filename)?

Thanks again!

frostming commented 2 years ago

I think sdist just has no opinion on this, while wheel will convert the hyphens to underscores, because hyphens are used to separate parts in the filename. I just borrow this part from setuptools and they should have the same behavior. See Flask-SQLAlchemy for example, note the name normalization.

AFAIK, different build backends treat this differently. hatchling lowercases the distribution name and replaces . to _ as well, but setuptools and pdm-pep517 keep the dots. But due to PEP 503, the index server will normalize the name when storing packages so they are the same. I think flit complains from the client side.

Some useful links

lelit commented 2 years ago

Thank you. It's just a matter of handling the difference in my twine-based upload rule.