-
-
Notifications
You must be signed in to change notification settings - Fork 386
Package complains about attr.__version__
but the alternative does not work
#1136
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
Comments
Hmm, how would your approach work with packages that are fundamentally named differently than the import name? Like the whole generation of packages that prepended their name with |
We don't know anything about PyPI distributions. We are scanning It does sound like it's a fool's errand though. Python shifting to asking people to use |
If the problem is not wanting to have to keep from importlib.metadata import PackageNotFoundError, version
__version__: str
try:
__version__ = version("attrs")
except PacakgeNotFoundError:
# package is not installed
__version__ = "0.0.0" |
I'm afraid you're a bit on a lost cause here, since looking at Whether or not attrs removes it is one thing, but newer projects are less likely to have that attribute increasingly. Also how do you handle name-spaced packages like Have tried coming up with a solution that lists installed packages (i.e. the equivalent of |
Okay. I can't find a PEP deprecating For namespaced packages I look for the version in |
I'm sorry if I'm being obnoxious but the thing is: there's no PEP for As far as I know, it's mentioned en passant in PEP 8 and was part of a PEP that got ultimately rejected: https://peps.python.org/pep-0396/ I'm not trying to be difficult here and postponing the removal is literally no work for me at all. It just seems to me that you're running on borrowed time here. I'll remove the |
Thanks. I see that |
If you have a import name and want to get the distribution package metadata (i.e. the actually versioned entity), you can use this API or its backport in [project]
...
dependencies = [
+ 'importlib_metadata; python_version < "3.10"',
] try:
from importlib.metadata import packages_distributions
except ImportError:
from importlib_metadata import packages_distributions As said: |
Consider:
But the code wanting to get the version number from
attr
can't do this:This is fundamentally because there is no metadata for the
attr
package because it's all in theattrs
package but theattrs
package installs code into two separate namespaces and has no way of registering that fact with the installer.The reason this is a problem for me is that we have some code that gathers version information for our running scientific pipeline code so that we can recreate the environment and have provenance information. The code doing this can't tell that
attr
is actually part ofattrs
and realizes thatimportlib.metadata
does not work, so it falls back to__version__
. This then results in a warning. I'm not sure what the solution is but thought I should mention the problem.The text was updated successfully, but these errors were encountered: