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 3
3
import abc
4
4
import csv
5
5
import sys
6
+ import json
6
7
import zipp
7
8
import email
9
+ import types
8
10
import inspect
9
11
import pathlib
10
12
import operator
@@ -625,6 +627,16 @@ def url_req_space(req):
625
627
space = url_req_space (section .value )
626
628
yield section .value + space + quoted_marker (section .name )
627
629
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
+
628
640
629
641
class DistributionFinder (MetaPathFinder ):
630
642
"""
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 1
1
import os
2
2
import sys
3
3
import copy
4
+ import json
4
5
import shutil
5
6
import pathlib
6
7
import tempfile
@@ -131,6 +132,27 @@ def make_uppercase(self):
131
132
build_files (files , self .site_dir )
132
133
133
134
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
+
134
156
class DistInfoPkgWithDot (OnSysPath , SiteBuilder ):
135
157
files : FilesSpec = {
136
158
"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):
457
457
# sources_fallback-pkg has one import ('sources_fallback') inferred from
458
458
# SOURCES.txt (top_level.txt and installed-files.txt is missing)
459
459
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