Skip to content

Commit

Permalink
relnote
Browse files Browse the repository at this point in the history
  • Loading branch information
anakin87 committed Nov 28, 2024
1 parent 66ee512 commit 0d8865d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 5 additions & 3 deletions .github/utils/check_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand All @@ -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 == '.':
Expand All @@ -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:")
Expand Down
6 changes: 6 additions & 0 deletions releasenotes/notes/check-imports-8a2aa18c73e5c492.yaml
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit 0d8865d

Please sign in to comment.