-
-
Notifications
You must be signed in to change notification settings - Fork 82
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
Add direct_url.json content to distribution #429
Conversation
@jaraco Here is a small PoC how the parsing could work. Please let me know what you think since there are multiple options, e.g.
In addition, what happens with |
Thanks for the contrib. I see now that you're going for a lot more than to provide access to the I'm slightly reluctant for importlib_metadata to own this behavior, as it's not obvious to me how stable the data structure is. As I review the bug again, I'm reminded that this file is defined in PEP 660, so is likely fairly stable. But if I compare the direct_url.json parsing to other parts of importlib_metadata, where things like the What I recommend - let's get feedback from the packaging community (forum or discord) as to where this behavior should reside. If it should be here (importlib metadata), then we'll move forward with getting this proposal merged.
It does. New features like this will land in the next Python release, which is currently 3.12, but the cutoff for new features is quickly approaching, so it likely won't land until 3.13 (another advantage of supplying the behavior in a third party package is speed of availability for older Pythons). |
@jaraco seems like I forgot to reply. Here is the post: https://discuss.python.org/t/place-for-a-direct-url-json-parser/26266 |
I was thinking instead of hard-coding the whole type hierarchy to simply reflect what's in JSON with something like this: diff --git a/importlib_metadata/__init__.py b/importlib_metadata/__init__.py
index 857c9198..4a33b2dc 100644
--- a/importlib_metadata/__init__.py
+++ b/importlib_metadata/__init__.py
@@ -3,8 +3,10 @@ import re
import abc
import csv
import sys
+import json
import zipp
import email
+import types
import inspect
import pathlib
import operator
@@ -618,6 +620,16 @@ class Distribution(DeprecatedNonAbstract):
space = url_req_space(section.value)
yield section.value + space + quoted_marker(section.name)
+ @property
+ def origin(self):
+ return self._load_json('direct_url.json')
+
+ def _load_json(self, filename):
+ return pass_none(json.loads)(
+ self.read_text(filename),
+ object_hook=lambda data: types.SimpleNamespace(**data),
+ )
+
class DistributionFinder(MetaPathFinder):
""" This approach would generalize to any json field with much less code, but provide a similar interface ( How do you see these tradeoffs? |
Separately, would you be willing to write some tests to capture the expected use-cases? In particular, I'd like some (all?) of the fixtures to expose |
@jaraco personally I'm a big typing fan. Maybe we could use a TypedDict here? |
|
Based on the discussion here, the feature was moved to pypa/packaging#701 |
Closes #404