12
12
from ._supported_packages import PACKAGE_RENAMES , STANDARD_LIBRARY , PYODIDE_PACKAGES
13
13
14
14
15
- class UnsupportedFileType (Exception ):
16
- pass
17
-
18
-
19
15
class NamespaceInfo :
20
16
def __init__ (self , source_fpath : Path ) -> None :
21
17
# expanding base_folder to absolute as pkgutils.FileFinder will do so - easier for later purging
@@ -164,14 +160,16 @@ def _convert_notebook(source_fpath: Path) -> str:
164
160
return source
165
161
166
162
167
- def find_imports (source_fpath : Path ,) -> FinderResult :
163
+ def find_imports (source : str , source_fpath : Path ,) -> FinderResult :
168
164
"""
169
165
Parse the input source, and returns its dependencies, as organised in
170
166
the sets of external _packages, and local modules, respectively.
171
167
Any modules or package with the same name found in the local
172
168
173
169
Parameters
174
170
----------
171
+ source : str
172
+ Python source code to parse
175
173
source_fpath : Path
176
174
Path to the input Python module to parse
177
175
@@ -182,24 +180,5 @@ def find_imports(source_fpath: Path,) -> FinderResult:
182
180
This instance provides reference to packages and paths to
183
181
include in the py-env, as well as any unsuppoted import.
184
182
"""
185
- fname , extension = source_fpath .name , source_fpath .suffix
186
- if extension == ".py" :
187
- with open (source_fpath , "rt" ) as f :
188
- source = f .read ()
189
-
190
- elif extension == ".ipynb" :
191
- try :
192
- import nbconvert
193
- except ImportError as e : # pragma no cover
194
- raise ImportError (
195
- "Please install nbconvert to serve Jupyter Notebooks."
196
- ) from e
197
-
198
- source = _convert_notebook (source_fpath )
199
-
200
- else :
201
- raise UnsupportedFileType (
202
- "{} is neither a script (.py) nor a notebook (.ipynb)" .format (fname )
203
- )
204
183
205
184
return _find_modules (source , source_fpath )
0 commit comments