New submission from Gregory Szorc <gregory.sz...@gmail.com>:

As I was attempting to implement the find_distributions() interface for 
PyOxidizer, I got confused by importlib.metadata's documentation.

The documentation for this module states:

```
What this means in practice is that to support finding distribution package
metadata in locations other than the file system, you should derive from
``Distribution`` and implement the ``load_metadata()`` method. Then from
your finder, return instances of this derived ``Distribution`` in the
``find_distributions()`` method.
```

The reference to `load_metadata()` is the only occurrence of the string 
`load_metadata` in the CPython and importlib_metadata code bases. I therefore 
believe the documentation in both CPython and the importlib_metadata standalone 
package are wrong because they are referring to a method that is never 
implemented nor called.

Looking at the documentation and source code for importlib.metadata, I'm also a 
bit confused about how exactly I'm supposed to implement a custom Distribution 
which isn't based on filesystems. For example, I see that certain APIs return 
Path-like objects (which I will need to implement). But it isn't clear exactly 
which attributes are mandated to exist! Am I expected to implement the full 
pathlib.Path interface or just a subset?

Regarding how find_distributions() is called, I also don't understand why the 
Context is optional and how Context could be used in some situations. For 
example, the implementation of discover() can construct Context instances with 
no arguments, which is then fed into find_distributions(). So I guess 
context=None or context.name=None implies "return Distribution's for every 
known package?" If so, this behavior is undocumented.

I'm also not sure what Context.path is for. I /think/ it is only used for the 
path-based finder/distribution. But the way it is documented implies it should 
always exist, which doesn't seem appropriate for cases like PyOxidizer which 
will retrieve metadata from in-memory without filesystem I/O.

I think what I'm trying to say is that the existing documentation for 
importlib.metadata is not sufficient to robustly implement a custom 
find_distributions() + Distribution type. I would kindly request that a domain 
expert revise the documentation such that a 3rd party can implement a custom 
solution. My preferred solution would be for there to be formal interfaces in 
importlib.abc like there are for everything else in the importlib realm. (The 
interfaces for finders and loaders are super useful when implementing a 
finder/loader from scratch.)

FWIW I think I like the new metadata API and I think it is flexible enough to 
allow tools like PyOxidizer to do crazy things like divorce resources from the 
filesystem! But it is hard to say for sure since the interfaces aren't clearly 
defined at present.

----------
assignee: docs@python
components: Documentation
messages: 355402
nosy: barry, docs@python, indygreg, jaraco
priority: normal
severity: normal
status: open
title: importlib.metadata documentation deficiencies
type: enhancement
versions: Python 3.8, Python 3.9

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue38594>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to