Skip to content

Commit 4b94d77

Browse files
committed
Better glob handling #143
1 parent c490500 commit 4b94d77

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

src/sasctl/pzmm/write_json_files.py

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,22 +1129,23 @@ def find_imports(cls, file_path):
11291129
"""
11301130
import ast
11311131

1132-
file_text = open(file_path).read()
1133-
# Parse the file to get the abstract syntax tree representation
1134-
tree = ast.parse(file_text)
1135-
modules = []
1136-
1137-
# Walk through each node in the ast to find import calls
1138-
for node in ast.walk(tree):
1139-
# Determine parent module for from * import * calls
1140-
if isinstance(node, ast.ImportFrom):
1141-
for name in node.names:
1142-
if not name.asname:
1143-
modules.append(node.module)
1144-
elif isinstance(node, ast.Import):
1145-
for name in node.names:
1146-
if not node.names[0].asname:
1147-
modules.append(node.names[0].name)
1132+
with open(file_path, "r") as file:
1133+
file_text = file.read()
1134+
# Parse the file to get the abstract syntax tree representation
1135+
tree = ast.parse(file_text)
1136+
modules = []
1137+
1138+
# Walk through each node in the ast to find import calls
1139+
for node in ast.walk(tree):
1140+
# Determine parent module for from * import * calls
1141+
if isinstance(node, ast.ImportFrom):
1142+
for name in node.names:
1143+
if not name.asname:
1144+
modules.append(node.module)
1145+
elif isinstance(node, ast.Import):
1146+
for name in node.names:
1147+
if not node.names[0].asname:
1148+
modules.append(node.names[0].name)
11481149

11491150
modules = list(set(modules))
11501151
try:
@@ -1169,10 +1170,7 @@ def get_pickle_file(cls, pickle_folder=Path.cwd()):
11691170
list
11701171
A list of pickle files.
11711172
"""
1172-
1173-
file_names = []
1174-
file_names.extend(sorted(Path(pickle_folder).glob("*.pickle")))
1175-
return file_names
1173+
return [p for p in Path(pickle_folder).iterdir() if p.suffix in [".pickle", ".pkl"]]
11761174

11771175
@classmethod
11781176
def get_pickle_dependencies(cls, pickle_file):

0 commit comments

Comments
 (0)