diff --git a/.gitignore b/.gitignore index b6e4761..7be1192 100644 --- a/.gitignore +++ b/.gitignore @@ -127,3 +127,6 @@ dmypy.json # Pyre type checker .pyre/ + +# VSCode +.vscode/ diff --git a/README.md b/README.md index 9e9b6ba..25ecfbb 100644 --- a/README.md +++ b/README.md @@ -29,12 +29,10 @@ So, this tool comes in handy for easily identifying which exact packages are act [i] Please wait! It may take few minutes to complete... [i] Scanning unused packages: - 1. rcssmin - 2. argon2-cffi - 3. flower - 4. django-model-utils - 5. pinax-theme-bootstrap - 6. phonenumbers + 1. Module: rcssmin ---> Package: rcssmin + 2. Module: model_utils ---> Package: django-model-utils + 3. Module: pinax_theme_bootstrap ---> Package: pinax-theme-bootstrap + 4. Module: phonenumbers ---> Package: phonenumbers ``` Cool right? 😎 diff --git a/scan.py b/scan.py index c2ffc57..4cd1541 100644 --- a/scan.py +++ b/scan.py @@ -2,7 +2,7 @@ import multiprocessing import os import re -from typing import List, Optional +from typing import List, Optional, Tuple import importlib_metadata @@ -17,6 +17,15 @@ - If not, then print the "packages name". """ +# allowed extensions to scan +ALLOWED_EXTENSIONS: Tuple[str] = ( + ".py", + ".conf", + ".cfg", + ".yml", + ".yaml", +) + def get_main_packages() -> dict: """ @@ -37,6 +46,7 @@ def get_main_packages() -> dict: for module_name, package_names in packages.items(): if ( not any(exclude in module_name for exclude in excluded_packages) + and not module_name.startswith("_") and package_names and isinstance(package_names, list) ): @@ -82,7 +92,7 @@ def search_string_in_python_files(directory: str, search_string: str) -> List[st pool = multiprocessing.Pool() for root, _, files in os.walk(directory): for file_name in files: - if file_name.endswith(".py"): + if file_name.endswith(ALLOWED_EXTENSIONS): file_path = os.path.join(root, file_name) found_file = pool.apply_async( search_string_in_file, (file_path, search_string) @@ -134,7 +144,9 @@ def main(project_path: str, requirement_file: str): results: list = search_string_in_python_files(project_path, module_name) if not results and (module_name not in unused_packages): unused_packages.append(package_name) - print(f" {number}. {package_name}") + print( + f" {number}. Module: {module_name} ---> Package: {package_name}" + ) number += 1 if len(unused_packages) < 1: