File tree Expand file tree Collapse file tree 2 files changed +11
-12
lines changed Expand file tree Collapse file tree 2 files changed +11
-12
lines changed Original file line number Diff line number Diff line change @@ -124,15 +124,14 @@ def finalise(self) -> Dict[str, FoundModule]:
124
124
return result
125
125
126
126
127
- def pyfiles (root : str ) -> Generator [str , None , None ]:
128
- root_path = Path (root )
129
- if root_path .is_file ():
130
- if root_path .suffix == ".py" :
131
- yield str (root_path .absolute ())
127
+ def pyfiles (root : Path ) -> Generator [str , None , None ]:
128
+ if root .is_file ():
129
+ if root .suffix == ".py" :
130
+ yield str (root .absolute ())
132
131
else :
133
- raise ValueError (f"{ root_path } is not a python file or directory" )
134
- elif root_path .is_dir ():
135
- for item in root_path .rglob ("*.py" ):
132
+ raise ValueError (f"{ root } is not a python file or directory" )
133
+ elif root .is_dir ():
134
+ for item in root .rglob ("*.py" ):
136
135
yield str (item .absolute ())
137
136
138
137
@@ -143,7 +142,7 @@ def find_imported_modules(
143
142
) -> Dict [str , FoundModule ]:
144
143
vis = _ImportVisitor (ignore_modules_function = ignore_modules_function )
145
144
for path in paths :
146
- for filename in pyfiles (path ):
145
+ for filename in pyfiles (Path ( path ) ):
147
146
if ignore_files_function (filename ):
148
147
log .info ("ignoring: %s" , os .path .relpath (filename ))
149
148
continue
Original file line number Diff line number Diff line change @@ -66,15 +66,15 @@ def test_import_visitor(stmt: str, result: List[str]) -> None:
66
66
def test_pyfiles_file (tmp_path : Path ) -> None :
67
67
python_file = tmp_path / "example.py"
68
68
python_file .touch ()
69
- assert list (common .pyfiles (root = str ( python_file ) )) == [str (python_file )]
69
+ assert list (common .pyfiles (root = python_file )) == [str (python_file )]
70
70
71
71
72
72
def test_pyfiles_file_no_dice (tmp_path : Path ) -> None :
73
73
not_python_file = tmp_path / "example"
74
74
not_python_file .touch ()
75
75
76
76
with pytest .raises (ValueError ):
77
- list (common .pyfiles (root = str ( not_python_file ) ))
77
+ list (common .pyfiles (root = not_python_file ))
78
78
79
79
80
80
def test_pyfiles_package (tmp_path : Path ) -> None :
@@ -88,7 +88,7 @@ def test_pyfiles_package(tmp_path: Path) -> None:
88
88
89
89
not_python_file .touch ()
90
90
91
- assert list (common .pyfiles (root = str ( tmp_path ) )) == [
91
+ assert list (common .pyfiles (root = tmp_path )) == [
92
92
str (python_file ),
93
93
str (nested_python_file ),
94
94
]
You can’t perform that action at this time.
0 commit comments