File tree Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -21,3 +21,16 @@ class ABC(object): # type: ignore
21
21
FileNotFoundError = FileNotFoundError # type: ignore
22
22
except NameError :
23
23
FileNotFoundError = OSError
24
+
25
+
26
+ class PackageSpec (object ):
27
+ def __init__ (self , ** kwargs ):
28
+ vars (self ).update (kwargs )
29
+
30
+
31
+ def package_spec (package ):
32
+ return getattr (package , '__spec__' , None ) or \
33
+ PackageSpec (
34
+ origin = package .__file__ ,
35
+ loader = getattr (package , '__loader__' , None ),
36
+ )
Original file line number Diff line number Diff line change 3
3
import abc
4
4
import zipp
5
5
6
- from ._compat import ABC , Path
6
+ from ._compat import ABC , Path , package_spec
7
7
8
8
9
9
class Traversable (ABC ):
@@ -40,9 +40,10 @@ def is_file(self):
40
40
41
41
def from_package (package ):
42
42
"""Return a Traversable object for the given package"""
43
- package_directory = Path (package .__spec__ .origin ).parent
43
+ spec = package_spec (package )
44
+ package_directory = Path (spec .origin ).parent
44
45
try :
45
- archive_path = package . __spec__ .loader .archive
46
+ archive_path = spec .loader .archive
46
47
rel_path = package_directory .relative_to (archive_path )
47
48
return zipp .Path (archive_path , str (rel_path ) + '/' )
48
49
except Exception :
You can’t perform that action at this time.
0 commit comments