From 034d1c231fcee4ac36d31024a989303f5850cc87 Mon Sep 17 00:00:00 2001 From: JulienPeloton Date: Fri, 22 Nov 2024 11:20:56 +0100 Subject: [PATCH] Add linter --- .github/workflows/linter.yml | 36 ++++++++++++++++ .ruff.toml | 84 ++++++++++++++++++++++++++++++++++++ README.md | 8 ++++ tests/api_test.py | 9 +++- 4 files changed, 135 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/linter.yml create mode 100644 .ruff.toml diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml new file mode 100644 index 0000000..07f79e3 --- /dev/null +++ b/.github/workflows/linter.yml @@ -0,0 +1,36 @@ +name: PEP8 + +on: + push: + branches: + - master + pull_request: + +jobs: + build: + + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [3.11] + + steps: + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install ruff + - name: Lint + run: | + ruff check --statistics *.py + ruff check --statistics apps/ + ruff check --ignore D205 tests/ + - name: Format + run: | + ruff format --check *.py + ruff format --check apps/ + ruff format --check tests/ diff --git a/.ruff.toml b/.ruff.toml new file mode 100644 index 0000000..aa3f5ac --- /dev/null +++ b/.ruff.toml @@ -0,0 +1,84 @@ +# Exclude a variety of commonly ignored directories. +exclude = [ + ".bzr", + ".direnv", + ".eggs", + ".git", + ".git-rewrite", + ".hg", + ".ipynb_checkpoints", + ".mypy_cache", + ".nox", + ".pants.d", + ".pyenv", + ".pytest_cache", + ".pytype", + ".ruff_cache", + ".svn", + ".tox", + ".venv", + ".vscode", + "__pypackages__", + "_build", + "buck-out", + "build", + "dist", + "node_modules", + "site-packages", + "venv", +] + +# Same as Black. +line-length = 88 +indent-width = 4 + +# Assume Python 3.8 +target-version = "py38" + +[lint] +# Rules can be found at https://docs.astral.sh/ruff/rules +select = ["E4", "E7", "E9", "F", "E1", "E2", "W", "N", "D", "B", "C4", "PD", "PERF"] +ignore = [ + "C408", "C901", + "D400", "D401", "D100", "D102", "D103", "D104", "D415", "D419", + "N812", "N806", "N803", + "PD901", + "PLR0913" +] + +# Allow fix for all enabled rules (when `--fix`) is provided. +fixable = ["ALL"] +unfixable = [] + +# Allow unused variables when underscore-prefixed. +dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$" + +[format] +# Like Black, use double quotes for strings. +quote-style = "double" + +# Like Black, indent with spaces, rather than tabs. +indent-style = "space" + +# Like Black, respect magic trailing commas. +skip-magic-trailing-comma = false + +# Like Black, automatically detect the appropriate line ending. +line-ending = "auto" + +# Enable auto-formatting of code examples in docstrings. Markdown, +# reStructuredText code/literal blocks and doctests are all supported. +# +# This is currently disabled by default, but it is planned for this +# to be opt-out in the future. +docstring-code-format = false + +# Set the line length limit used when formatting code snippets in +# docstrings. +# +# This only has an effect when the `docstring-code-format` setting is +# enabled. +docstring-code-line-length = "dynamic" + +[lint.pydocstyle] +convention = "numpy" diff --git a/README.md b/README.md index 447c6c3..b2be8d2 100644 --- a/README.md +++ b/README.md @@ -72,3 +72,11 @@ r = requests.post( cutout = fits.open(io.BytesIO(r.content), ignore_missing_simple=True) ``` + +## Tests + +Once the app is deployed (need credentials), simply trigger: + +```bash +python tests/api_test.py URL +``` diff --git a/tests/api_test.py b/tests/api_test.py index 76f0bc4..44765d7 100644 --- a/tests/api_test.py +++ b/tests/api_test.py @@ -23,7 +23,8 @@ APIURL = sys.argv[1] -TESTFILE="archive/science/year=2024/month=11/day=14/part-00019-14b4d19b-5bd1-4a33-a3d2-d7484c407981.c000.snappy.parquet" +TESTFILE = "archive/science/year=2024/month=11/day=14/part-00019-14b4d19b-5bd1-4a33-a3d2-d7484c407981.c000.snappy.parquet" + def cutouttest( objectId="ZTF24abssjsb", @@ -56,6 +57,7 @@ def cutouttest( def test_fits_cutout() -> None: """ + Examples -------- >>> test_fits_cutout() @@ -68,6 +70,7 @@ def test_fits_cutout() -> None: def test_array_cutout() -> None: """ + Examples -------- >>> test_array_cutout() @@ -80,6 +83,7 @@ def test_array_cutout() -> None: def test_kind_cutout() -> None: """ + Examples -------- >>> test_kind_cutout() @@ -99,6 +103,7 @@ def test_kind_cutout() -> None: def test_integrity() -> None: """ + Examples -------- >>> test_integrity() @@ -108,7 +113,7 @@ def test_integrity() -> None: assert np.alltrue(data1[0] == data2[0].data) -#def test_candid_cutout() -> None: +# def test_candid_cutout() -> None: # """ # Examples # --------