diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml new file mode 100644 index 0000000..ef34f6a --- /dev/null +++ b/.github/workflows/CI.yml @@ -0,0 +1,53 @@ +name: CI + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + build: + name: 'Build and test fjsplib using ${{ matrix.python-version }}' + runs-on: ubuntu-latest + strategy: + fail-fast: true + matrix: + python-version: ['3.9', '3.12'] + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - name: Update pip and poetry + run: | + python -m pip install --upgrade pip + pip install poetry + - name: Cache Python dependencies + uses: actions/cache@v4 + id: cache-python + with: + path: ~/.cache/pypoetry + key: ${{ runner.os }}-python-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }} + - name: Install Python dependencies + if: steps.cache-python.outputs.cache-hit != 'true' + run: poetry install + - name: Cache pre-commit + uses: actions/cache@v4 + id: cache-pre-commit + with: + path: ~/.cache/pre-commit/ + key: pre-commit-${{ env.pythonLocation }}-${{ hashFiles('.pre-commit-config.yaml') }} + - name: Install pre-commit + if: steps.cache-pre-commit.outputs.cache-hit != 'true' + run: poetry run pre-commit install --install-hooks + - name: Run pre-commit + run: poetry run pre-commit run --all-files + - name: Run tests + run: poetry run pytest + - if: matrix.python-version == '3.9' + name: Upload coverage reports to Codecov + uses: codecov/codecov-action@v4.0.1 + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + slug: leonlan/FJSPLIB diff --git a/README.md b/README.md index 6417a27..1182589 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ # FJSPLIB +![PyPI](https://img.shields.io/pypi/v/FJSPLIB?style=flat-square) +![License](https://img.shields.io/pypi/l/FJSPLIB?style=flat-square) +![CI](https://img.shields.io/github/actions/workflow/status/leonlan/FJSPLIB/.github%2Fworkflows%2FCI.yml?style=flat-square) +![Codecov](https://img.shields.io/codecov/c/github/leonlan/FJSPLIB?style=flat-square) FJSPLIB is a Python package for reading and writing flexible job shop problem (FJSP) instances. diff --git a/fjsplib/read.py b/fjsplib/read.py index 1ef4b35..be52135 100644 --- a/fjsplib/read.py +++ b/fjsplib/read.py @@ -1,5 +1,6 @@ from dataclasses import dataclass from pathlib import Path +from typing import Union ProcessingData = list[tuple[int, int]] Arc = tuple[int, int] @@ -115,7 +116,7 @@ def read(loc: Path) -> Instance: ) -def file2lines(loc: Path | str) -> list[list[int]]: +def file2lines(loc: Union[Path, str]) -> list[list[int]]: with open(loc, "r") as fh: lines = [line for line in fh.readlines() if line.strip()] diff --git a/pyproject.toml b/pyproject.toml index fdb7af6..7f24a57 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,20 +11,23 @@ repository = "https://github.com/leonlan/FJSPLIB" python = "^3.9" numpy = "^1.26.4" - [tool.poetry.group.dev.dependencies] -pytest = "^7.1.2" pre-commit = "^2.19.0" +pytest = "^7.1.2" +pytest-cov = ">=2.6.1" [tool.black] line-length = 79 +[tool.mypy] +ignore_missing_imports = true + + [tool.ruff] line-length = 79 - [tool.ruff.lint] ignore-init-module-imports = true select = [ @@ -36,8 +39,9 @@ case-sensitive = true known-first-party = ["fjsplib", "tests"] -[tool.mypy] -ignore_missing_imports = true +[tool.pytest.ini_options] +addopts = "--cov=. --cov-report=xml --cov-report=term" +testpaths = "tests" [build-system]