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

importlib.metadata fails to read version in the 'hatchling' package #100602

Closed
yurivict opened this issue Dec 29, 2022 · 14 comments
Closed

importlib.metadata fails to read version in the 'hatchling' package #100602

yurivict opened this issue Dec 29, 2022 · 14 comments
Labels
topic-importlib type-bug An unexpected behavior, bug, or error

Comments

@yurivict
Copy link

yurivict commented Dec 29, 2022

Bug report

This code fails to read version in the 'hatchling' package:

name="hatchling"
import importlib.metadata as importlib_metadata
dist = importlib_metadata.distribution(name)
print(f"dist.version={dist.version}")

it prints:

dist.version=None

Your environment

  • CPython versions tested on: 3.9.16
  • py39-hatchling-1.11.0
  • Operating system and architecture: FreeBSD 13.1 STABLE amd64
@yurivict yurivict added the type-bug An unexpected behavior, bug, or error label Dec 29, 2022
@ericvsmith
Copy link
Member

I don't see this on 3.9.10 on Cygwin with hatchling 1.11.0 or 1.11.1, or with 3.10.6 on Ubuntu with hatchling 1.11.1.

I don't 3.9.16 handy, but I'll see if I can install it.

How did you install hatchling? Is this in a virtual environment? Is this a --user install?

@yurivict
Copy link
Author

hatchling was installed from the FreeBSD package/port.
It isn't in a virtual environment and isn't a user install.

@ned-deily
Copy link
Member

Try pip install-ing a version of hatchling directly from pypi using a venv as an experiment. It may be that the FreeBSD package of hatchling is stripping some files. If so, you should take it up with the FreeBSD project.

@ericvsmith
Copy link
Member

I agree with @ned-deily : this is probably an issue with how the FreeBSD port installs hatchling.

@yurivict
Copy link
Author

But what is wrong with how it is installed?
By default it uses setup.py - and the result has this problem.
I also tried to build it with build (into a wheel), and then install the wheel with 'install' - and it still has the same problem.

@ned-deily
Copy link
Member

ned-deily commented Dec 30, 2022

It could also be an issue with FreeBSD modifications to Python. You could try bulding a vanilla Python 3.9.x and installing with it. I don't have a FreeBSD installation available at the moment but your test worked ok on a Python 3.9.x on macOS.

@eli-schwartz
Copy link
Contributor

Surely the simplest solution to debugging the problem is to stop theorizing about what might be wrong with how it is installed or what FreeBSD does to modify python, and simply... upload the relevant files which FreeBSD has (i.e. the contents of the py39-hatchling-1.11.0 package). :) Then anyone can take a look at them and see what importlib.metadata doesn't like about them... :)

@yurivict
Copy link
Author

here

@eli-schwartz
Copy link
Contributor

The only files this contains are the python files inside usr/local/lib/python3.9/site-packages/hatchling/. There's no metadata here.

$ cd /tmp/hatchling-files/usr/local/lib/python3.9/site-packages; PYTHONPATH=$PWD python3.9
Python 3.9.16 (main, Jan  1 2023, 03:08:33) 
[GCC 11.1.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import importlib.metadata
>>> dist = importlib.metadata.distribution('hatchling')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.9/importlib/metadata.py", line 542, in distribution
    return Distribution.from_name(distribution_name)
  File "/usr/lib/python3.9/importlib/metadata.py", line 196, in from_name
    raise PackageNotFoundError(name)
importlib.metadata.PackageNotFoundError: hatchling

I don't know how you got a distribution with no version, but you "should" actually have significantly bigger errors.

@yurivict
Copy link
Author

yurivict commented Jan 1, 2023

Sorry, that was an incomplete archive.
The complete package file is here.

@eli-schwartz
Copy link
Contributor

eli-schwartz commented Jan 1, 2023

This one does work for me:

$ cd /tmp/py39-hatchling-1.11.0~8f3b9491eb/usr/local/lib/python3.9/site-packages; PYTHONPATH=$PWD python3.9
Python 3.9.16 (main, Jan  1 2023, 03:08:33) 
[GCC 11.1.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import importlib.metadata
>>> dist = importlib.metadata.distribution('hatchling')
>>> dist.version
'1.11.0'

If that doesn't work on FreeBSD, then it would indeed seem to be an issue with something other than the metadata...

@eli-schwartz
Copy link
Contributor

eli-schwartz commented Jan 1, 2023

@yurivict https://builds.sr.ht/~eschwartz/job/914998

On a FreeBSD 13.1-RELEASE-p3 GENERIC image, I was able to successfully install python39, load your tarball and get dist.version to print 1.11.0, and then repeat the experience with pkg install py39-hatchling.

I'm not sure how you got the results you got, but this isn't an importlib.metadata bug and it isn't a FreeBSD bug either, and the example which fails for you, works for my reproducible FreeBSD test job after following the exact instructions you gave.

I think the problem is likely in your own local installation which has something other than a FreeBSD port installed in addition to the test case you uploaded. The tarball you uploaded appears to be the port tarball itself, so it's not actually taken from your local environment, which means that there may still be a discrepancy there.

@eli-schwartz
Copy link
Contributor

This is probably a duplicate of #91216 and you have an additional, but broken, metadata directory for hatchling, which does NOT come from the FreeBSD port.

@yurivict
Copy link
Author

You are right, some stray file caused this.

File:

/usr/local/lib/python3.9/site-packages/hatchling-1.6.0-py3.9.egg-info

@yurivict yurivict closed this as not planned Won't fix, can't repro, duplicate, stale Jan 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-importlib type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

5 participants