diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..8dcde61 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,67 @@ +name: ci + +on: [push, pull_request] + +jobs: + + tests: + runs-on: ubuntu-latest + timeout-minutes: 30 + strategy: + matrix: + python-version: ['3.10','3.11','3.12'] + + steps: + - uses: actions/checkout@v4 + + - name: Install uv + uses: astral-sh/setup-uv@v4 + with: + version: "0.5.18" + python-version: ${{ matrix.python-version }} + + - name: Install dependencies + run: uv sync + + - name: Run test suite + env: + # show timings of tests + PYTEST_ADDOPTS: "--durations=0" + run: uv run pytest --cov janus_web --cov-append . + + - name: Report coverage to Coveralls + uses: coverallsapp/github-action@v2 + with: + parallel: true + flag-name: run-${{ matrix.python-version }} + file: coverage.xml + base-path: api + + coverage: + needs: tests + runs-on: ubuntu-latest + steps: + - name: Close parallel build + uses: coverallsapp/github-action@v2 + with: + parallel-finished: true + + pre-commit: + runs-on: ubuntu-latest + timeout-minutes: 15 + steps: + - uses: actions/checkout@v4 + + - name: Install uv + uses: astral-sh/setup-uv@v4 + with: + version: "0.5.18" + python-version: "3.12" + + - name: Install dependencies + run: uv sync + + - name: Run pre-commit + run: | + uv run pre-commit install + uv run pre-commit run --all-files || ( git status --short ; git diff ; exit 1 ) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..62c7365 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +__pycache__/ +data/* +.venv diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..b0601d1 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,21 @@ +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 + hooks: + - id: end-of-file-fixer + - id: mixed-line-ending + - id: trailing-whitespace + - id: check-json + +- repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.7.4 + hooks: + - id: ruff + args: [ --fix ] + - id: ruff-format + +- repo: https://github.com/numpy/numpydoc + rev: v1.6.0 + hooks: + - id: numpydoc-validation + files: ^api/ diff --git a/janus_web/__init__.py b/janus_web/__init__.py new file mode 100644 index 0000000..41b042a --- /dev/null +++ b/janus_web/__init__.py @@ -0,0 +1,7 @@ +"""API for janus-core.""" + +from __future__ import annotations + +from importlib.metadata import version + +__version__ = version("janus-web") diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..d56a275 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,132 @@ +[project] +name = "janus-web" +version = "0.0.1" +description = "API for janus-core" +authors = [ + { name = "Cameron Ball" }, +] +requires-python = ">=3.10" +classifiers = [ + "Programming Language :: Python", + "Intended Audience :: Science/Research", + "License :: OSI Approved :: BSD License", + "Natural Language :: English", + "Development Status :: 3 - Alpha", +] +readme = "README.md" + +dependencies = [ + "janus-core", + "fastapi<1.0.0,>=0.95.0", + "uvicorn<1.0.0,>=0.22.0", + "python-multipart", + "fastapi-cors" +] + +[project.optional-dependencies] + +[project.scripts] + +[project.urls] +repository = "https://github.com/stfc/janus-web/" +documentation = "https://stfc.github.io/janus-web/" + +[dependency-groups] +dev = [ + "coverage[toml]<8.0.0,>=7.4.1", + "pgtest<2.0.0,>=1.3.2", + "pytest<9.0,>=8.0", + "pytest-cov<5.0.0,>=4.1.0", + "tox-uv<2.0,>=1.16.1", + "wheel<1.0,>=0.42", +] + +docs = [ + "furo<2025.0.0,>=2024.1.29", + "markupsafe<2.1", + "numpydoc<2.0.0,>=1.6.0", + "sphinx<8.0.0,>=7.2.6", + "sphinxcontrib-contentui<1.0.0,>=0.2.5", + "sphinxcontrib-details-directive<1.0,>=0.1", + "sphinx-copybutton<1.0.0,>=0.5.2", +] + +pre-commit = [ + "pre-commit<4.0.0,>=3.6.0", + "ruff<1.0.0,>=0.7.4", +] + +[build-system] +requires = ["pdm-backend"] +build-backend = "pdm.backend" + +[tool.pytest.ini_options] +# Configuration for pytest +python_files = "test_*.py" +addopts = '--cov-report xml' +pythonpath = ["."] + +[tool.coverage.run] +# Configuration of coverage.py +# reporting which lines of your plugin are covered by tests +source=["janus_web"] + +[tool.ruff] +exclude = ["conf.py"] +target-version = "py310" + +[tool.ruff.lint] +# Ignore complexity +ignore = ["C901"] +select = [ + # flake8-bugbear + "B", + # pylint + "C", "R", + # pydocstyle + "D", + # pycodestyle + "E", "W", + # Pyflakes + "F", "FA", + # pyupgrade + "I", + # pep8-naming + "N", + # isort + "UP", +] + +[tool.ruff.lint.isort] +force-sort-within-sections = true +required-imports = ["from __future__ import annotations"] + +[tool.ruff.lint.pydocstyle] +convention = "numpy" + +[tool.ruff.lint.pylint] +max-args = 10 + +[tool.ruff.lint.pyupgrade] +keep-runtime-typing = false + +[tool.numpydoc_validation] +# report on all checks, except the below +checks = [ + "all", + "EX01", + "SA01", + "ES01", +] +# Don't report on objects that match any of these regex +exclude = [ + ".__weakref__$", + ".__repr__$", +] + +[tool.uv] +default-groups = [ + "dev", + "docs", + "pre-commit", +] diff --git a/tests/test_example.py b/tests/test_example.py new file mode 100644 index 0000000..68af3c7 --- /dev/null +++ b/tests/test_example.py @@ -0,0 +1,11 @@ +"""Example test.""" + +from __future__ import annotations + +from janus_web import __version__ + + +def test_example(): + """Example test.""" + print(__version__) + assert 1 == (2 / 2)