Debian Codegraph @

test/import_all.py

raw symbols SCIP
1 #!/usr/bin/env python3
2
3 # Copyright (c) 2021 Chris Reed
4 # SPDX-License-Identifier: Apache-2.0
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #
10 # http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17
18 from pathlib import Path
19 from importlib import import_module
20
21 # Import pyocd to get its filesystem path.
22 import pyocd
23
24 # Total count of modules imported.
25 import_count = 0
26
27 def process_dir(dotted_path: str, dir_path: Path) -> None:
28 global import_count
29 for entry in sorted(dir_path.iterdir(), key=lambda v: v.name):
30 is_subpackage = (entry.is_dir() and (entry / "__init__.py").exists())
31 is_module = entry.suffix == ".py"
32
33 if not (is_subpackage or is_module):
34 continue
35
36 module_path = dotted_path + '.' + entry.stem
37 print(f"Importing: {module_path}")
38 import_module(module_path)
39 import_count += 1
40
41 # Recursive into valid sub-packages.
42 if is_subpackage:
43 process_dir(module_path, entry)
44
45 def main() -> None:
46 pyocd_path = Path(pyocd.__file__).parent.resolve()
47 print(f"pyocd package path: {pyocd_path}")
48 process_dir("pyocd", pyocd_path)
49 print(f"Imported {import_count} modules successfully")
50
51 if __name__ == "__main__":
52 main()