1
1
from __future__ import annotations
2
2
3
+ import json
3
4
import logging
4
- from collections import defaultdict
5
+ from collections import OrderedDict , defaultdict
5
6
from typing import TYPE_CHECKING
6
7
7
8
from deptry .rust import get_imports_from_ipynb_files , get_imports_from_py_files
@@ -25,21 +26,29 @@ def get_imported_modules_from_list_of_files(list_of_files: list[Path]) -> dict[s
25
26
# Process all .py files in parallel using Rust
26
27
if py_files :
27
28
rust_result = get_imports_from_py_files (py_files )
28
- for module , locations in convert_rust_locations_to_python_locations (rust_result ).items ():
29
+ for module , locations in _convert_rust_locations_to_python_locations (rust_result ).items ():
29
30
modules [module ].extend (locations )
30
31
31
32
# Process all .ipynb files in parallel using Rust
32
33
if ipynb_files :
33
34
rust_result = get_imports_from_ipynb_files (ipynb_files )
34
- for module , locations in convert_rust_locations_to_python_locations (rust_result ).items ():
35
+ for module , locations in _convert_rust_locations_to_python_locations (rust_result ).items ():
35
36
modules [module ].extend (locations )
36
37
37
- logging .debug ("All imported modules: %s\n " , modules )
38
+ sorted_modules = OrderedDict (sorted (modules .items ()))
39
+ _log_modules_with_locations (sorted_modules )
40
+ return sorted_modules
38
41
39
- return modules
40
42
43
+ def _log_modules_with_locations (modules : dict [str , list [Location ]]) -> None :
44
+ modules_dict = {
45
+ module_name : [str (location ) for location in locations ] for module_name , locations in modules .items ()
46
+ }
47
+ modules_json = json .dumps (modules_dict , indent = 2 )
48
+ logging .debug ("All imported modules and their locations:\n %s" , modules_json )
41
49
42
- def convert_rust_locations_to_python_locations (
50
+
51
+ def _convert_rust_locations_to_python_locations (
43
52
imported_modules : dict [str , list [RustLocation ]],
44
53
) -> dict [str , list [Location ]]:
45
54
converted_modules : dict [str , list [Location ]] = {}
0 commit comments