Skip to content

refactor: Rework legacy filters embedding tests and remove numpy dependency #635

refactor: Rework legacy filters embedding tests and remove numpy dependency

refactor: Rework legacy filters embedding tests and remove numpy dependency #635

Workflow file for this run

name: Verify preview imports only preview
on:
pull_request:
types:
- opened
- reopened
- synchronize
- ready_for_review
paths:
- "haystack/preview/**.py"
jobs:
verify-imports:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
# With the default value of 1, there are corner cases where tj-actions/changed-files
# fails with a `no merge base` error
fetch-depth: 0
- name: Get changed files
id: files
uses: tj-actions/changed-files@v40
with:
files: |
haystack/preview/**.py
- name: Check imports
shell: python
run: |
import re
regex = r"^(from haystack|import haystack)(?!\.preview| import preview)(.*)"
changed_files = "${{ steps.files.outputs.all_changed_files }}".split()
matches = {}
for path in changed_files:
with open(path, "r") as f:
file_matches = []
for line in f.readlines():
file_matches.extend(re.finditer(regex, line.strip()))
if file_matches:
matches[path] = file_matches
for path, match in matches.items():
print(f"Bad imports in file '{path}'")
for m in match:
print(m.group())
print()
if matches:
print("::error:: Imports in haystack.preview can only import from haystack.preview")
import sys; sys.exit(1)