Skip to content

Commit

Permalink
Merge pull request #56 from reactome/poetry-test
Browse files Browse the repository at this point in the history
poetry-check
  • Loading branch information
heliamoh authored Nov 29, 2024
2 parents 7ded3c0 + 02e9f6c commit 8741fc2
Show file tree
Hide file tree
Showing 5 changed files with 380 additions and 303 deletions.
16 changes: 16 additions & 0 deletions .github/actions/install_python_poetry/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: 'Setup Python and Poetry'
description: 'Setup Python environment and install Poetry'
runs:
using: 'composite'
steps:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.12'

- name: Install dependencies
shell: bash
run: |
pip install --upgrade pip
pip install poetry==1.8.4
poetry install --no-root
42 changes: 42 additions & 0 deletions .github/actions/verify_imports.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import importlib.machinery
import importlib.util
import traceback
from pathlib import Path

# List all entry points here
entry_points: list[Path] = list(
map(
Path("bin").joinpath,
[
"chat-chainlit.py",
"chat-fastapi.py",
"embeddings_manager",
],
)
)

failed_imports: list[str] = []

location: Path
for location in entry_points:
name: str = location.stem
try:
loader = importlib.machinery.SourceFileLoader(name, str(location))
spec = importlib.util.spec_from_loader(name, loader)
if spec is None:
raise ModuleNotFoundError(name)
module = importlib.util.module_from_spec(spec)
loader.exec_module(module)
except ImportError:
failed_imports.append(name)
print(f"Failed to import {location} due to ImportError:")
traceback.print_exc()
except Exception as e:
print(f"Non-import error for {location}: {e}")
traceback.print_exc()

if failed_imports:
print(f"Failed to import: {", ".join(failed_imports)}")
exit(1)
else:
print("All entry points imported successfully.")
40 changes: 30 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,43 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.12'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
poetry install --no-root
- name: Set up Python and Poetry
uses: ./.github/actions/install_python_poetry

- name: Run linters
run: |
poetry run ruff check .
poetry run mypy .
poetry run isort --check .
poetry-check:
if: ${{ github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch' }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-13]

steps:
- uses: actions/checkout@v4

- name: Check poetry.lock for changes
id: check-poetry-lock
uses: tj-actions/changed-files@v45
with:
files: poetry.lock

- name: Set up Python and Poetry
if: steps.check-poetry-lock.outputs.any_changed == 'true'
uses: ./.github/actions/install_python_poetry

- name: Verify Python imports
if: steps.check-poetry-lock.outputs.any_changed == 'true'
env:
PYTHONPATH: ./bin:./src
run: |
poetry check
poetry run python ./.github/actions/verify_imports.py
docker-build:
runs-on: ubuntu-latest

Expand Down
Loading

0 comments on commit 8741fc2

Please sign in to comment.