Skip to content
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

Error building source distributions when the filename does not match archive name #607

Closed
ofek opened this issue Apr 23, 2023 · 13 comments
Closed

Comments

@ofek
Copy link

ofek commented Apr 23, 2023

pypa/hatch#833 (comment)

bb

❯ python -m build
* Creating virtualenv isolated environment...
* Installing packages in isolated environment... (hatchling)
* Getting build dependencies for sdist...
* Building sdist...
ERROR Source C:\Users\ofek\AppData\Local\Temp\build-via-sdist-eu6in06u\github3.py-4.0.0 is not a directory

I think the filename should not be taken into account.

@layday
Copy link
Member

layday commented Apr 23, 2023

What do I have to do to reproduce this? I cloned github3.py's main branch and ran build on it and it seems to work fine.

@layday
Copy link
Member

layday commented Apr 23, 2023

Right, I needed to disable strict-naming.

@layday
Copy link
Member

layday commented Apr 23, 2023

I'm inclined to close this as won't fix. build follows PEP 625, which says that:

The name of an sdist should be {distribution}-{version}.tar.gz.

  • distribution is the name of the distribution as defined in PEP 345, and normalised as described in the wheel spec e.g. 'pip', 'flit_core'.

@ofek
Copy link
Author

ofek commented Apr 23, 2023

I think a frontend doing anything but invoking the backend is out of scope. It should be up to the backend what to name the file and wouldn't put any extra maintenance burden here as far as I can tell.

Do you know exactly why this error is happening? Is the source distribution being extracted and the inner directory is trying to be located to build the wheel based on the original filename?

@layday
Copy link
Member

layday commented Apr 23, 2023

Pretty much; build calls basename on the filename of the sdist to trim the extension, then once it unpacks the sdist, it attempts to access temp_dir/basename. The packed folder has an underscore where the sdist has a dot. I suppose we could grab the top-level folder's name from the contents of the sdist, but we didn't think that the filename and folder name would differ.

@ofek
Copy link
Author

ofek commented Apr 23, 2023

I think it would make sense to fix it here because building the source distribution separately from the wheel does indeed work properly

@ofek
Copy link
Author

ofek commented Apr 23, 2023

If you don't think so then I will fix in Hatchling today, just let me know!

@layday
Copy link
Member

layday commented Apr 23, 2023

But what is build expected to do if $(basename $filename .tar.gz) != $filename? Traverse the containing folder and pick the first unpacked folder it finds? What if there's multiple top-level directories? It just seems more sensible to assume that the above condition is always ==.

@offbyone
Copy link

offbyone commented Apr 23, 2023

I don't know how significant this is, but build has different behaviour in sdist construction depending on how it's invoked:

$ python -mbuild
* Creating virtualenv isolated environment...
* Installing packages in isolated environment... (hatchling)
* Getting build dependencies for sdist...
* Building sdist...
ERROR Source /var/folders/tc/mhq0tfws3s1bs5788hx6nhkc0000gn/T/build-via-sdist-6wbzvh9r/github3.py-3.2.0 is not a directory

$ python -mbuild -s
* Creating virtualenv isolated environment...
* Installing packages in isolated environment... (hatchling)
* Getting build dependencies for sdist...
* Building sdist...
Successfully built github3.py-3.2.0.tar.gz

edit Ah, I see @ofek already called this out.

@ofek
Copy link
Author

ofek commented Apr 23, 2023

Traverse the containing folder and pick the first unpacked folder it finds?

Yes I think

What if there's multiple top-level directories?

That would never happen, or at least that wouldn't be a source distribution

@ofek
Copy link
Author

ofek commented Apr 23, 2023

@layday
Copy link
Member

layday commented Apr 23, 2023

Sdists are not particularly well defined - I'm not sure that having multiple folders is disallowed, or that it would be any less surprising than the top-level folder having a different name from the archive itself. I'd suggest applying the principle of least surprise here - keeping the outer and inner names the same if there's no good reason that they should differ. PEP 517 does also mention that: "[the sdist format] is mostly undefined, but basically comes down to: a file named {NAME}-{VERSION}.{EXT}, which unpacks into a buildable source tree called {NAME}-{VERSION}/." I overlooked this earlier.

@ofek
Copy link
Author

ofek commented Apr 23, 2023

https://github.com/pypa/hatch/releases/tag/hatchling-v1.14.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants