@@ -27,6 +27,7 @@ use std::collections::HashSet;
2727#[ pymodule]
2828fn _rustgrimp ( py : Python < ' _ > , m : & Bound < ' _ , PyModule > ) -> PyResult < ( ) > {
2929 m. add_wrapped ( wrap_pyfunction ! ( parse_imported_objects_from_code) ) ?;
30+ m. add_wrapped ( wrap_pyfunction ! ( scan_for_imports) ) ?;
3031 m. add_class :: < GraphWrapper > ( ) ?;
3132 m. add_class :: < PyRealBasicFileSystem > ( ) ?;
3233 m. add_class :: < PyFakeBasicFileSystem > ( ) ?;
@@ -41,6 +42,35 @@ fn _rustgrimp(py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
4142 Ok ( ( ) )
4243}
4344
45+ #[ pyfunction]
46+ fn scan_for_imports < ' py , > (
47+ py : Python < ' py > ,
48+ module_files : Vec < Bound < ' py , PyAny > > ,
49+ found_packages : Bound < ' py , PyAny > ,
50+ include_external_packages : bool ,
51+ exclude_type_checking_imports : bool ,
52+ file_system : Bound < ' py , PyAny > ,
53+ ) -> PyResult < Bound < ' py , PyDict > > {
54+ let scanner = ImportScanner :: new (
55+ py,
56+ file_system,
57+ found_packages,
58+ include_external_packages,
59+ ) ?;
60+
61+ let dict = PyDict :: new ( py) ;
62+ for module_file in module_files {
63+ let py_module_instance = module_file. getattr ( "module" ) . unwrap ( ) ;
64+ let imports = scanner. scan_for_imports (
65+ py,
66+ py_module_instance,
67+ exclude_type_checking_imports,
68+ ) ?;
69+ dict. set_item ( module_file, imports) . unwrap ( ) ;
70+ }
71+ Ok ( dict)
72+ }
73+
4474#[ pyfunction]
4575fn parse_imported_objects_from_code < ' py > (
4676 py : Python < ' py > ,
0 commit comments