Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

poetry-check #56

Merged
merged 11 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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