1- import logging
21import os
32import re
43import shutil
98
109import pkg_resources
1110
12- _PATH_ROOT = dirname (dirname (__file__ ))
1311REQUIREMENT_FILES = {
1412 "pytorch" : (
1513 "requirements/pytorch/base.txt" ,
@@ -68,12 +66,8 @@ def _replace_imports(lines: List[str], mapping: List[Tuple[str, str]]) -> List[s
6866def copy_replace_imports (
6967 source_dir : str , source_imports : List [str ], target_imports : List [str ], target_dir : Optional [str ] = None
7068) -> 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 ()} " )
7771 assert len (source_imports ) == len (target_imports ), (
7872 "source and target imports must have the same length, "
7973 f"source: { len (source_imports )} , target: { len (target_imports )} "
@@ -98,7 +92,7 @@ def copy_replace_imports(
9892 lines = fo .readlines ()
9993 except UnicodeDecodeError :
10094 # a binary file, skip
101- logging . warning (f"Skipped replacing imports for { fp } " )
95+ print (f"Skipped replacing imports for { fp } " )
10296 continue
10397 lines = _replace_imports (lines , list (zip (source_imports , target_imports )))
10498 os .makedirs (os .path .dirname (fp_new ), exist_ok = True )
@@ -145,7 +139,7 @@ def _prune_packages(req_file: str, packages: Sequence[str]) -> None:
145139 req = list (pkg_resources .parse_requirements (ln_ ))[0 ]
146140 if req .name not in packages :
147141 final .append (line )
148- logging . info (final )
142+ print (final )
149143 path .write_text ("\n " .join (final ))
150144
151145 @staticmethod
@@ -163,7 +157,7 @@ def replace_oldest_ver(requirement_fnames: Sequence[str] = REQUIREMENT_FILES_ALL
163157 def copy_replace_imports (
164158 source_dir : str , source_import : str , target_import : str , target_dir : Optional [str ] = None
165159 ) -> None :
166- """Recursively replace imports in given folder ."""
160+ """Copy package content with import adjustments ."""
167161 source_imports = source_import .strip ().split ("," )
168162 target_imports = target_import .strip ().split ("," )
169163 copy_replace_imports (source_dir , source_imports , target_imports , target_dir = target_dir )
@@ -172,5 +166,4 @@ def copy_replace_imports(
172166if __name__ == "__main__" :
173167 import jsonargparse
174168
175- logging .basicConfig (level = logging .INFO )
176169 jsonargparse .CLI (AssistantCLI , as_positional = False )
0 commit comments