@@ -25,6 +25,46 @@ def __init__(self):
25
25
self .parent = sys .exc_info ()
26
26
27
27
28
+ def write_installed_files_from_setuptools_record (
29
+ record_lines : List [str ],
30
+ root : Optional [str ],
31
+ req_description : str ,
32
+ ) -> None :
33
+ def prepend_root (path ):
34
+ # type: (str) -> str
35
+ if root is None or not os .path .isabs (path ):
36
+ return path
37
+ else :
38
+ return change_root (root , path )
39
+
40
+ for line in record_lines :
41
+ directory = os .path .dirname (line )
42
+ if directory .endswith ('.egg-info' ):
43
+ egg_info_dir = prepend_root (directory )
44
+ break
45
+ else :
46
+ message = (
47
+ "{} did not indicate that it installed an "
48
+ ".egg-info directory. Only setup.py projects "
49
+ "generating .egg-info directories are supported."
50
+ ).format (req_description )
51
+ raise InstallationError (message )
52
+
53
+ new_lines = []
54
+ for line in record_lines :
55
+ filename = line .strip ()
56
+ if os .path .isdir (filename ):
57
+ filename += os .path .sep
58
+ new_lines .append (
59
+ os .path .relpath (prepend_root (filename ), egg_info_dir )
60
+ )
61
+ new_lines .sort ()
62
+ ensure_dir (egg_info_dir )
63
+ inst_files_path = os .path .join (egg_info_dir , 'installed-files.txt' )
64
+ with open (inst_files_path , 'w' ) as f :
65
+ f .write ('\n ' .join (new_lines ) + '\n ' )
66
+
67
+
28
68
def install (
29
69
install_options , # type: List[str]
30
70
global_options , # type: Sequence[str]
@@ -88,38 +128,5 @@ def install(
88
128
with open (record_filename ) as f :
89
129
record_lines = f .read ().splitlines ()
90
130
91
- def prepend_root (path ):
92
- # type: (str) -> str
93
- if root is None or not os .path .isabs (path ):
94
- return path
95
- else :
96
- return change_root (root , path )
97
-
98
- for line in record_lines :
99
- directory = os .path .dirname (line )
100
- if directory .endswith ('.egg-info' ):
101
- egg_info_dir = prepend_root (directory )
102
- break
103
- else :
104
- message = (
105
- "{} did not indicate that it installed an "
106
- ".egg-info directory. Only setup.py projects "
107
- "generating .egg-info directories are supported."
108
- ).format (req_description )
109
- raise InstallationError (message )
110
-
111
- new_lines = []
112
- for line in record_lines :
113
- filename = line .strip ()
114
- if os .path .isdir (filename ):
115
- filename += os .path .sep
116
- new_lines .append (
117
- os .path .relpath (prepend_root (filename ), egg_info_dir )
118
- )
119
- new_lines .sort ()
120
- ensure_dir (egg_info_dir )
121
- inst_files_path = os .path .join (egg_info_dir , 'installed-files.txt' )
122
- with open (inst_files_path , 'w' ) as f :
123
- f .write ('\n ' .join (new_lines ) + '\n ' )
124
-
131
+ write_installed_files_from_setuptools_record (record_lines , root , req_description )
125
132
return True
0 commit comments