File tree Expand file tree Collapse file tree 4 files changed +42
-0
lines changed
Expand file tree Collapse file tree 4 files changed +42
-0
lines changed Original file line number Diff line number Diff line change 33import abc
44import csv
55import sys
6+ import json
67import zipp
78import email
9+ import types
810import inspect
911import pathlib
1012import operator
@@ -625,6 +627,16 @@ def url_req_space(req):
625627 space = url_req_space (section .value )
626628 yield section .value + space + quoted_marker (section .name )
627629
630+ @property
631+ def origin (self ):
632+ return self ._load_json ('direct_url.json' )
633+
634+ def _load_json (self , filename ):
635+ return pass_none (json .loads )(
636+ self .read_text (filename ),
637+ object_hook = lambda data : types .SimpleNamespace (** data ),
638+ )
639+
628640
629641class DistributionFinder (MetaPathFinder ):
630642 """
Original file line number Diff line number Diff line change 1+ Added ``Distribution.origin `` supplying the ``direct_url.json `` in a ``SimpleNamespace ``.
Original file line number Diff line number Diff line change 11import os
22import sys
33import copy
4+ import json
45import shutil
56import pathlib
67import tempfile
@@ -131,6 +132,27 @@ def make_uppercase(self):
131132 build_files (files , self .site_dir )
132133
133134
135+ class DistInfoPkgEditable (DistInfoPkg ):
136+ """
137+ Package with a PEP 660 direct_url.json.
138+ """
139+
140+ some_hash = '524127ce937f7cb65665130c695abd18ca386f60bb29687efb976faa1596fdcc'
141+ files : FilesSpec = {
142+ 'distinfo_pkg-1.0.0.dist-info' : {
143+ 'direct_url.json' : json .dumps (
144+ {
145+ "archive_info" : {
146+ "hash" : f"sha256={ some_hash } " ,
147+ "hashes" : {"sha256" : f"{ some_hash } " },
148+ },
149+ "url" : "file:///path/to/distinfo_pkg-1.0.0.editable-py3-none-any.whl" ,
150+ }
151+ )
152+ },
153+ }
154+
155+
134156class DistInfoPkgWithDot (OnSysPath , SiteBuilder ):
135157 files : FilesSpec = {
136158 "pkg_dot-1.0.0.dist-info" : {
Original file line number Diff line number Diff line change @@ -457,3 +457,10 @@ def import_names_from_package(package_name):
457457 # sources_fallback-pkg has one import ('sources_fallback') inferred from
458458 # SOURCES.txt (top_level.txt and installed-files.txt is missing)
459459 assert import_names_from_package ('sources_fallback-pkg' ) == {'sources_fallback' }
460+
461+
462+ class EditableDistributionTest (fixtures .DistInfoPkgEditable , unittest .TestCase ):
463+ def test_origin (self ):
464+ dist = Distribution .from_name ('distinfo-pkg' )
465+ assert dist .origin .url .endswith ('.whl' )
466+ assert dist .origin .archive_info .hashes .sha256
You can’t perform that action at this time.
0 commit comments