Skip to content

Commit c98ba01

Browse files
committed
Self suggested changes
1 parent 236699b commit c98ba01

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

.actions/assistant.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import logging
21
import os
32
import re
43
import shutil
@@ -9,7 +8,6 @@
98

109
import pkg_resources
1110

12-
_PATH_ROOT = dirname(dirname(__file__))
1311
REQUIREMENT_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
6866
def 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(
172166
if __name__ == "__main__":
173167
import jsonargparse
174168

175-
logging.basicConfig(level=logging.INFO)
176169
jsonargparse.CLI(AssistantCLI, as_positional=False)

0 commit comments

Comments
 (0)