@@ -11,10 +11,8 @@ mod module_finding;
1111use crate :: errors:: { GrimpError , GrimpResult } ;
1212use crate :: graph:: higher_order_queries:: Level ;
1313use crate :: graph:: { Graph , Module , ModuleIterator , ModuleTokenIterator } ;
14- use crate :: import_scanning:: { py_found_packages_to_rust, scan_for_imports_no_py} ;
1514use crate :: module_expressions:: ModuleExpression ;
1615use derive_new:: new;
17- use filesystem:: get_file_system_boxed;
1816use itertools:: Itertools ;
1917use pyo3:: IntoPyObjectExt ;
2018use pyo3:: exceptions:: PyValueError ;
@@ -27,7 +25,7 @@ use std::collections::HashSet;
2725#[ pymodule]
2826mod _rustgrimp {
2927 #[ pymodule_export]
30- use super :: scan_for_imports;
28+ use crate :: import_scanning :: scan_for_imports;
3129
3230 #[ pymodule_export]
3331 use crate :: caching:: read_cache_data_map_file;
@@ -44,79 +42,6 @@ mod _rustgrimp {
4442 } ;
4543}
4644
47- /// Statically analyses the given module and returns a set of Modules that
48- /// it imports.
49- /// Python args:
50- ///
51- /// - module_files The modules to scan.
52- /// - found_packages: Set of FoundPackages containing all the modules
53- /// for analysis.
54- /// - include_external_packages: Whether to include imports of external modules (i.e.
55- /// modules not contained in modules_by_package_directory)
56- /// in the results.
57- /// - exclude_type_checking_imports: If True, don't include imports behind TYPE_CHECKING guards.
58- /// - file_system: The file system interface to use. (A BasicFileSystem.)
59- ///
60- /// Returns dict[Module, set[DirectImport]].
61- #[ pyfunction]
62- fn scan_for_imports < ' py > (
63- py : Python < ' py > ,
64- module_files : Vec < Bound < ' py , PyAny > > ,
65- found_packages : Bound < ' py , PyAny > ,
66- include_external_packages : bool ,
67- exclude_type_checking_imports : bool ,
68- file_system : Bound < ' py , PyAny > ,
69- ) -> PyResult < Bound < ' py , PyDict > > {
70- let file_system_boxed = get_file_system_boxed ( & file_system) ?;
71- let found_packages_rust = py_found_packages_to_rust ( & found_packages) ;
72- let modules_rust: HashSet < module_finding:: Module > = module_files
73- . iter ( )
74- . map ( |module_file| {
75- module_file
76- . getattr ( "module" )
77- . unwrap ( )
78- . extract :: < module_finding:: Module > ( )
79- . unwrap ( )
80- } )
81- . collect ( ) ;
82-
83- let imports_by_module_result = py. detach ( || {
84- scan_for_imports_no_py (
85- & file_system_boxed,
86- & found_packages_rust,
87- include_external_packages,
88- & modules_rust,
89- exclude_type_checking_imports,
90- )
91- } ) ;
92-
93- match imports_by_module_result {
94- Err ( GrimpError :: ParseError {
95- module_filename,
96- line_number,
97- text,
98- ..
99- } ) => {
100- // TODO: define SourceSyntaxError using pyo3.
101- let exceptions_pymodule = PyModule :: import ( py, "grimp.exceptions" ) . unwrap ( ) ;
102- let py_exception_class = exceptions_pymodule. getattr ( "SourceSyntaxError" ) . unwrap ( ) ;
103- let exception = py_exception_class
104- . call1 ( ( module_filename, line_number, text) )
105- . unwrap ( ) ;
106- return Err ( PyErr :: from_value ( exception) ) ;
107- }
108- Err ( e) => {
109- return Err ( e. into ( ) ) ;
110- }
111- _ => ( ) ,
112- }
113- let imports_by_module = imports_by_module_result. unwrap ( ) ;
114-
115- let imports_by_module_py = import_scanning:: imports_by_module_to_py ( py, imports_by_module) ;
116-
117- Ok ( imports_by_module_py)
118- }
119-
12045#[ pyclass( name = "Graph" ) ]
12146#[ derive( Clone ) ]
12247struct GraphWrapper {
0 commit comments