Skip to content

Commit

Permalink
Add linter
Browse files Browse the repository at this point in the history
  • Loading branch information
JulienPeloton committed Nov 22, 2024
1 parent d7cf5f0 commit 034d1c2
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 2 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
@@ -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/
84 changes: 84 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -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"
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
9 changes: 7 additions & 2 deletions tests/api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -56,6 +57,7 @@ def cutouttest(

def test_fits_cutout() -> None:
"""
Examples
--------
>>> test_fits_cutout()
Expand All @@ -68,6 +70,7 @@ def test_fits_cutout() -> None:

def test_array_cutout() -> None:
"""
Examples
--------
>>> test_array_cutout()
Expand All @@ -80,6 +83,7 @@ def test_array_cutout() -> None:

def test_kind_cutout() -> None:
"""
Examples
--------
>>> test_kind_cutout()
Expand All @@ -99,6 +103,7 @@ def test_kind_cutout() -> None:

def test_integrity() -> None:
"""
Examples
--------
>>> test_integrity()
Expand All @@ -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
# --------
Expand Down

0 comments on commit 034d1c2

Please sign in to comment.