Skip to content

Package complains about attr.__version__ but the alternative does not work #1136

@timj

Description

@timj

Consider:

>>> import attr
>>> attr.__version__
<stdin>:1: DeprecationWarning: Accessing attr.__version__ is deprecated and will be removed in a future release. Use importlib.metadata directly to query for attrs's packaging metadata.
'23.1.0'

But the code wanting to get the version number from attr can't do this:

>>> import importlib.metadata as M
>>> M.version("attr")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/timj/work/lsstsw/miniconda/envs/lsst-scipipe-6.0.0/lib/python3.10/importlib/metadata/__init__.py", line 996, in version
    return distribution(distribution_name).version
  File "/Users/timj/work/lsstsw/miniconda/envs/lsst-scipipe-6.0.0/lib/python3.10/importlib/metadata/__init__.py", line 969, in distribution
    return Distribution.from_name(distribution_name)
  File "/Users/timj/work/lsstsw/miniconda/envs/lsst-scipipe-6.0.0/lib/python3.10/importlib/metadata/__init__.py", line 548, in from_name
    raise PackageNotFoundError(name)
importlib.metadata.PackageNotFoundError: No package metadata was found for attr

This is fundamentally because there is no metadata for the attr package because it's all in the attrs package but the attrs 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 of attrs and realizes that importlib.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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions