diff --git a/.github/utils/check_imports.py b/.github/utils/check_imports.py index 46a2a47889..31ced6ee51 100644 --- a/.github/utils/check_imports.py +++ b/.github/utils/check_imports.py @@ -7,12 +7,13 @@ """ This script checks that all Haystack packages can be imported successfully. This can detect several issues. -One example is forgetting to use a forward reference for a type hint coming from a lazy import. +One example is forgetting to use a forward reference for a type hint coming +from a lazy import. """ def import_packages_with_init(directory): """ - Recursively search for directories with __init__.py and import them safely. + Recursively search for directories with __init__.py and import them. """ imported = [] failed = [] @@ -30,6 +31,7 @@ def import_packages_with_init(directory): if init_path.endswith(f'{directory}/__init__.py'): continue + # convert filesystem path to Python module name relative_path = os.path.relpath(root, directory) module_name = relative_path.replace(os.path.sep, '.') if module_name == '.': @@ -55,7 +57,7 @@ def import_packages_with_init(directory): print("\nNO PACKAGES WERE IMPORTED") sys.exit(1) - print(f"\nSUCCESSFULLY IMPORTED {len(imported)} PACKAGES:") + print(f"\nSUCCESSFULLY IMPORTED {len(imported)} PACKAGES") if failed: print(f"\nFAILED TO IMPORT {len(failed)} PACKAGES:") diff --git a/releasenotes/notes/check-imports-8a2aa18c73e5c492.yaml b/releasenotes/notes/check-imports-8a2aa18c73e5c492.yaml new file mode 100644 index 0000000000..2d1814e89a --- /dev/null +++ b/releasenotes/notes/check-imports-8a2aa18c73e5c492.yaml @@ -0,0 +1,6 @@ +--- +enhancements: + - | + Add a testing job to check that all packages can be imported successfully. + This should help detecting several issues, such as forgetting to use a + forward reference for a type hint coming from a lazy import.