Skip to content

Commit

Permalink
next gen linting with ruff + only using pyproject.toml + pack/unpack …
Browse files Browse the repository at this point in the history
…functions have option bitorder and parallel + mypy
  • Loading branch information
pravirkr committed Apr 19, 2024
1 parent 267251a commit 5ee4d5a
Show file tree
Hide file tree
Showing 22 changed files with 1,111 additions and 592 deletions.
28 changes: 14 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,34 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
python-version: ['3.8', '3.9']
python-version: ['3.8', '3.9', '3.10']

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install it
run: |
python -m pip install -U pip setuptools wheel
python -m pip install -e .[tests]
- name: Lint with flake8
python -m pip install .[tests] -v
- name: Lint with Ruff
uses: chartboost/ruff-action@v1
with:
args: "check"
- name: Check types with mypy
run: |
pip install flake8 wemake-python-styleguide
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --statistics
- name: Run pytest and Generate coverage report
mypy --strict ./sigpyproc/
- name: Test with pytest and Generate coverage report
run: |
pip install pytest pytest-cov
pytest --cov=./ --cov-report=xml
continue-on-error: false
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage.xml
name: codecov-umbrella
fail_ci_if_error: true
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ docs/jupyter_execute/
.dmypy.json
dmypy.json

# ruff
.ruff_cache/

# Mr Developer
.mr.developer.cfg
.project
Expand Down
101 changes: 82 additions & 19 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,35 +1,99 @@
[build-system]
requires = [
"setuptools>=47",
"wheel",
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "sigpyproc"
version = "1.1.0"
description = "Python FRB/pulsar data toolbox"
readme = "README.md"
authors = [{ name = "Ewan Barr", email = "ewan.d.barr@gmail.com" }]
maintainers = [{ name = "Pravir Kumar", email = "pravirka@gmail.com" }]
requires-python = ">=3.8"
classifiers = [
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Operating System :: MacOS :: MacOS X",
"Operating System :: Microsoft :: Windows",
"Operating System :: POSIX :: Linux",
"License :: OSI Approved :: MIT License",
"Development Status :: 4 - Beta",
"Intended Audience :: Science/Research",
"Topic :: Scientific/Engineering :: Astronomy",
]
dependencies = [
"numpy",
"numba",
"astropy",
"h5py",
"bottleneck",
"attrs",
"click",
"rich",
"bidict",
"typing_extensions",
]

build-backend = "setuptools.build_meta"
[project.urls]
Repository = "https://github.com/FRBs/sigpyproc3"

[project.optional-dependencies]
tests = [
"pytest",
"pytest-cov",
"pytest-randomly",
"pytest-sugar",
"pytest-benchmark",
"mypy",
]
docs = ["sphinx", "sphinx-book-theme", "sphinx-click", "myst-nb"]
develop = ["ruff"]

[tool.black]
line-length = 90
target_version = ['py38', 'py39', 'py310']
[project.scripts]
spp_header = "sigpyproc.apps.spp_header:main"
spp_decimate = "sigpyproc.apps.spp_decimate:main"
spp_extract = "sigpyproc.apps.spp_extract:main"
spp_clean = "sigpyproc.apps.spp_clean:main"


[tool.pytest.ini_options]
minversion = "6.0"
testpaths = [
"tests",
]
[tool.ruff]
include = ["pyproject.toml", "sigpyproc/**/*.py"]
line-length = 88
indent-width = 4
target-version = "py39"

[tool.ruff.format]
quote-style = "double"
indent-style = "space"

[tool.ruff.lint]
select = ["ALL"]
ignore = ["D1", "ANN1", "PLR2004"]

[tool.ruff.lint.pylint]
max-args = 10

[tool.ruff.lint.pydocstyle]
convention = "numpy"


[tool.pytest.ini_options]
minversion = "8.0"
testpaths = "tests"

[tool.coverage.paths]
source = ["./sigpyproc/"]

[tool.coverage.run]
omit = [
'*tests*',
'*docs*',
'*apps*',
'*setup.py',
'*__init__.py',
'*sigpyproc/core/kernels.py',
"tests/*",
"docs/*",
"apps/*",
"*__init__.py",
"sigpyproc/core/kernels.py",
]

[tool.coverage.report]
Expand All @@ -38,7 +102,6 @@ show_missing = true
ignore_errors = true
exclude_lines = ['raise AssertionError', 'raise NotImplementedError']


[tool.mypy]
ignore_missing_imports = true
plugins = ["numpy.typing.mypy_plugin"]
123 changes: 0 additions & 123 deletions setup.cfg

This file was deleted.

2 changes: 0 additions & 2 deletions setup.py

This file was deleted.

35 changes: 28 additions & 7 deletions sigpyproc/apps/spp_clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


@click.command(
context_settings=dict(help_option_names=["-h", "--help"], show_default=True)
context_settings={"help_option_names": ["-h", "--help"], "show_default": True},
)
@click.argument("filfile", type=click.Path(exists=True))
@click.option(
Expand All @@ -15,24 +15,45 @@
help="RFI cleaning method to use.",
)
@click.option(
"-t", "--threshold", type=float, default=3.0, help="Sigma threshold for RFI cleaning."
"-t",
"--threshold",
type=float,
default=3.0,
help="Sigma threshold for RFI cleaning.",
)
@click.option(
"-g", "--gulp", type=int, default=16384, help="Number of samples to read at once"
"-g",
"--gulp",
type=int,
default=16384,
help="Number of samples to read at once",
)
@click.option(
"-o", "--outfile", type=click.Path(exists=False), help="Output masked filterbank file"
"-o",
"--outfile",
type=click.Path(exists=False),
help="Output masked filterbank file",
)
@click.option(
"--save/--no-save", default=True, help="Save the mask information to a file"
"--save/--no-save",
default=True,
help="Save the mask information to a file",
)
def main(
filfile: str, method: str, threshold: float, outfile: str, gulp: int, save: bool
filfile: str,
method: str,
threshold: float,
outfile: str,
gulp: int,
save: bool, # noqa: FBT001
) -> None:
"""Clean RFI from filterbank data."""
fil = FilReader(filfile)
_out_file, rfimask = fil.clean_rfi(
method=method, threshold=threshold, filename=outfile, gulp=gulp
method=method,
threshold=threshold,
filename=outfile,
gulp=gulp,
)
if save:
rfimask.to_file()
Expand Down
Loading

0 comments on commit 5ee4d5a

Please sign in to comment.