1
- import logging
2
1
import os
3
2
import re
4
3
import shutil
9
8
10
9
import pkg_resources
11
10
12
- _PATH_ROOT = dirname (dirname (__file__ ))
13
11
REQUIREMENT_FILES = {
14
12
"pytorch" : (
15
13
"requirements/pytorch/base.txt" ,
@@ -68,12 +66,8 @@ def _replace_imports(lines: List[str], mapping: List[Tuple[str, str]]) -> List[s
68
66
def copy_replace_imports (
69
67
source_dir : str , source_imports : List [str ], target_imports : List [str ], target_dir : Optional [str ] = None
70
68
) -> None :
71
- """Copy package content with import adjustments.
72
-
73
- >>> _ = copy_replace_imports(os.path.join(
74
- ... _PATH_ROOT, "src"), ["lightning_app"], ["lightning.app"], os.path.join(_PATH_ROOT, "src", "lightning"))
75
- """
76
- logging .info (f"Replacing imports: { locals ()} " )
69
+ """Copy package content with import adjustments."""
70
+ print (f"Replacing imports: { locals ()} " )
77
71
assert len (source_imports ) == len (target_imports ), (
78
72
"source and target imports must have the same length, "
79
73
f"source: { len (source_imports )} , target: { len (target_imports )} "
@@ -98,7 +92,7 @@ def copy_replace_imports(
98
92
lines = fo .readlines ()
99
93
except UnicodeDecodeError :
100
94
# a binary file, skip
101
- logging . warning (f"Skipped replacing imports for { fp } " )
95
+ print (f"Skipped replacing imports for { fp } " )
102
96
continue
103
97
lines = _replace_imports (lines , list (zip (source_imports , target_imports )))
104
98
os .makedirs (os .path .dirname (fp_new ), exist_ok = True )
@@ -145,7 +139,7 @@ def _prune_packages(req_file: str, packages: Sequence[str]) -> None:
145
139
req = list (pkg_resources .parse_requirements (ln_ ))[0 ]
146
140
if req .name not in packages :
147
141
final .append (line )
148
- logging . info (final )
142
+ print (final )
149
143
path .write_text ("\n " .join (final ))
150
144
151
145
@staticmethod
@@ -163,7 +157,7 @@ def replace_oldest_ver(requirement_fnames: Sequence[str] = REQUIREMENT_FILES_ALL
163
157
def copy_replace_imports (
164
158
source_dir : str , source_import : str , target_import : str , target_dir : Optional [str ] = None
165
159
) -> None :
166
- """Recursively replace imports in given folder ."""
160
+ """Copy package content with import adjustments ."""
167
161
source_imports = source_import .strip ().split ("," )
168
162
target_imports = target_import .strip ().split ("," )
169
163
copy_replace_imports (source_dir , source_imports , target_imports , target_dir = target_dir )
@@ -172,5 +166,4 @@ def copy_replace_imports(
172
166
if __name__ == "__main__" :
173
167
import jsonargparse
174
168
175
- logging .basicConfig (level = logging .INFO )
176
169
jsonargparse .CLI (AssistantCLI , as_positional = False )
0 commit comments