Skip to content

Commit

Permalink
Merge pull request #167 from StingraySoftware/new_package_infra
Browse files Browse the repository at this point in the history
Replace setup.cfg with pyproject.toml
  • Loading branch information
matteobachetti authored Dec 2, 2024
2 parents c158a90 + fc23cc2 commit f75fb50
Show file tree
Hide file tree
Showing 69 changed files with 2,679 additions and 2,747 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/ci_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ jobs:
run: |
python -m pip install --upgrade pip
python -m pip install tox
pip install -e ".[docs]"
- name: Install system dependencies
run: sudo apt-get -y install graphviz pandoc
- name: Print Python, pip, setuptools, and tox versions
Expand Down Expand Up @@ -121,8 +122,8 @@ jobs:
use_remote_data: true
continue-on-error: true
- os: ubuntu-latest
python: '3.8'
tox_env: 'py38-test-oldestdeps-cov'
python: '3.9'
tox_env: 'py39-test-oldestdeps-cov'
use_remote_data: true
- os: macos-latest
python: '3.11'
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ __pycache__

# Other generated files
*/version.py
*/_version.py
*/cython_version.py
htmlcov
.coverage
Expand Down
30 changes: 0 additions & 30 deletions .pep8speaks.yml

This file was deleted.

117 changes: 117 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
ci:
autofix_prs: false
autoupdate_schedule: 'monthly'

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: check-added-large-files
args: ["--enforce-all", "--maxkb=300"]
exclude: "^(\
.*.svg|\
notebooks/.*.ipynb|\
.*.jpe?g|\
.*logo.png|\
.*test.rmf|\
)$"
# Prevent giant files from being committed.
- id: check-case-conflict
# Check for files with names that would conflict on a case-insensitive
# filesystem like MacOS HFS+ or Windows FAT.
- id: check-json
# Attempts to load all json files to verify syntax.
- id: check-merge-conflict
# Check for files that contain merge conflict strings.
- id: check-symlinks
# Checks for symlinks which do not point to anything.
- id: check-toml
# Attempts to load all TOML files to verify syntax.
- id: check-xml
# Attempts to load all xml files to verify syntax.
- id: check-yaml
# Attempts to load all yaml files to verify syntax.
exclude: ".*(.github.*)$"
- id: detect-private-key
# Checks for the existence of private keys.
- id: end-of-file-fixer
# Makes sure files end in a newline and only a newline.
exclude: ".*(.*.svg|data.*|extern.*|_templates.*|licenses.*|_static.*|_parsetab.py|cli.rst)$"
# - id: fix-encoding-pragma # covered by pyupgrade
- id: trailing-whitespace
# Trims trailing whitespace.
exclude_types: [python] # Covered by Ruff W291.
exclude: ".*(data.*|extern.*|licenses.*|_static.*)$"

- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
- id: rst-directive-colons
# Detect mistake of rst directive not ending with double colon.
- id: rst-inline-touching-normal
# Detect mistake of inline code touching normal text in rst.
- id: text-unicode-replacement-char
# Forbid files which have a UTF-8 Unicode replacement character.
exclude: "^(\
.*.rmf|\
)$"

- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
hooks:
- id: codespell
args: ["--write-changes"]
additional_dependencies:
- tomli

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.9
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]
- id: ruff-format

# - repo: https://github.com/scientific-python/cookie
# rev: 2024.08.19
# hooks:
# - id: sp-repo-review

- repo: https://github.com/PyCQA/docformatter
# using an untagged rev for forward compatibility with pre-commit 4.0
# see https://github.com/PyCQA/docformatter/issues/289
# This should be changed back to a tag when (>1.7.5) is released
rev: 06907d0267368b49b9180eed423fae5697c1e909
hooks:
- id: docformatter
additional_dependencies: [tomli]
args: [--in-place, --config, ./pyproject.toml]
exclude: |
(?x)(
test.*\.py |
hendrics/__init__\.py |
hendrics/_dev/ |
hendrics/conftest\.py |
astropy/version\.py |
docs/ |
examples/
)
# - repo: local
# hooks:
# - id: changelogs-rst
# name: changelog filenames
# language: fail
# entry: >-
# changelog files must be named <sub-package>/####.(bugfix|feature|api|perf).rst
# or ####.other.rst (in the root directory only)
# exclude: >-
# ^docs/changes/[\w\.]+/(\d+\.(bugfix|feature|api|perf)(\.\d)?.rst|.gitkeep)
# files: ^docs/changes/[\w\.]+/
# - id: changelogs-rst-other
# name: changelog filenames for other category
# language: fail
# entry: >-
# only "other" changelog files must be placed in the root directory
# exclude: >-
# ^docs/changes/(\d+\.other.rst|README.rst|template.rst)
# files: ^docs/changes/\d+.\w+.rst
211 changes: 211 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
extend = "pyproject.toml"
lint.ignore = [
# NOTE: to find a good code to fix, run:
# ruff --select="ALL" --statistics astropy/<subpackage>

# flake8-annotations (ANN) : static typing
"ANN001", # Function argument without type annotation
"ANN003", # `**kwargs` without type annotation
"ANN202", # Private function without return type annotation
"ANN401", # Use of `Any` type

# flake8-unused-arguments (ARG)
"ARG001", # unused-function-argument
"ARG002", # unused-method-argument
"ARG003", # unused-class-method-argument
"ARG004", # unused-static-method-argument
"ARG005", # unused-lambda-argument

# flake8-bugbear (B)
"B006", # MutableArgumentDefault
"B007", # UnusedLoopControlVariable
"B023", # FunctionUsesLoopVariable
"B028", # No-explicit-stacklevel
"B904", # RaiseWithoutFromInsideExcept
"B905", # ZipWithoutExplicitStrict

# flake8-blind-except (BLE)
"BLE001", # blind-except

# mccabe (C90) : code complexity
# TODO: configure maximum allowed complexity.
"C901", # McCabeComplexity

# pydocstyle (D)
# Missing Docstrings
"D100", # undocumented-public-module
"D101", # undocumented-public-class
"D103", # undocumented-public-function
"D104", # undocumented-public-package
"D205", # blank-line-after-summary
# Quotes Issues
"D300", # triple-single-quotes
"D301", # escape-sequence-in-docstring
# Docstring Content Issues
"D403", # first-line-capitalized
"D404", # docstring-starts-with-this
"D401", # non-imperative-mood.
"D414", # empty-docstring-section
"D419", # docstring is empty

# flake8-datetimez (DTZ)
"DTZ001", # call-datetime-without-tzinfo
"DTZ005", # call-datetime-now-without-tzinfo

# pycodestyle (E, W)
"E501", # line-too-long
"E721", # type-comparison
"E731", # lambda-assignment

# flake8-errmsg (EM) : nicer error tracebacks
"EM101", # raw-string-in-exception
"EM102", # f-string-in-exception
"EM103", # dot-format-in-exception

# eradicate (ERA)
# NOTE: be careful that developer notes are kept.
"ERA001", # commented-out-code

# flake8-executable (EXE)
"EXE002", # shebang-missing-executable-file

# Pyflakes (F)
"F841", # unused-variable

# flake8-boolean-trap (FBT) : boolean flags should be kwargs, not args
# NOTE: a good thing to fix, but changes API.
"FBT001", # boolean-positional-arg-in-function-definition
"FBT002", # boolean-default-value-in-function-definition
"FBT003", # boolean-positional-value-in-function-call

# flake8-fixme (FIX)
"FIX001", # Line contains FIXME. this should be fixed or at least FIXME replaced with TODO
"FIX004", # Line contains HACK. replace HACK with NOTE.

# pep8-naming (N)
# NOTE: some of these can/should be fixed, but this changes the API.
"N801", # invalid-class-name
"N802", # invalid-function-name
"N803", # invalid-argument-name
"N804", # invalid-first-argument-name-for-class-method
"N805", # invalid-first-argument-name-for-method
"N807", # dunder-function-name
"N813", # camelcase-imported-as-lowercase
"N815", # mixed-case-variable-in-class-scope
"N816", # mixed-case-variable-in-global-scope
"N818", # error-suffix-on-exception-name

# NumPy-specific rules (NPY)
"NPY002", # Replace legacy `np.random.rand` call with `np.random.Generator` (2023-05-03)

# Perflint (PERF)
"PERF203", # `try`-`except` within a loop incurs performance overhead
"PERF401", # Use a list comprehension to create a transformed list

# Pylint (PLC, PLE, PLR, PLW)
"PLE0101", # return-in-init
"PLR0124", # Name compared with itself
"PLR0402", # ConsiderUsingFromImport
"PLR0912", # too-many-branches
"PLR0913", # too-many-args
"PLR0915", # too-many-statements
"PLR1714", # Consider merging multiple comparisons
"PLR2004", # MagicValueComparison
"PLR5501", # collapsible-else-if
"PLW0603", # global-statement
"PLW2901", # redefined-loop-name

# flake8-pytest-style (PT)
"PT003", # pytest-extraneous-scope-function
"PT004", # pytest-missing-fixture-name-underscore # deprecated in ruff 0.6.0
"PT006", # pytest-parametrize-names-wrong-type
"PT007", # pytest-parametrize-values-wrong-type
"PT011", # pytest-raises-too-broad
"PT012", # pytest-raises-with-multiple-statements
"PT017", # pytest-assert-in-exceptinstead
"PT018", # pytest-composite-assertion
"PT022", # pytest-useless-yield-fixture

# flake8-return (RET)
"RET501", # unnecessary-return-none
"RET502", # implicit-return-value
"RET503", # implicit-return
"RET504", # unnecessary-assign
"RET507", # superfluous-else-continue

# flake8-raise (RSE)
"RSE102", # unnecessary-paren-on-raise-exception

# Ruff-specific rules (RUF)
"RUF001", # ambiguous-unicode-character-string
"RUF002", # ambiguous-unicode-character-docstring
"RUF010", # use conversion in f-string
"RUF012", # Mutable class attributes should be annotated with `typing.ClassVar`

# flake8-bandit (S)
"S101", # Use of `assert` detected
"S105", # hardcoded-password-string
"S110", # try-except-pass
"S112", # try-except-continue
"S301", # suspicious-pickle-usage
"S307", # Use of possibly insecure function; consider using `ast.literal_eval`
"S311", # suspicious-non-cryptographic-randomness
"S324", # hashlib-insecure-hash-function
"S506", # UnsafeYAMLLoad
"S310", # Suspicious-url-open-usage
"S603", # `subprocess` call: check for execution of untrusted input
"S607", # Starting a process with a partial executable path

# flake8-simplify (SIM)
"SIM102", # NestedIfStatements
"SIM105", # UseContextlibSuppress
"SIM108", # UseTernaryOperator
"SIM114", # if-with-same-arms
"SIM115", # OpenFileWithContextHandler
"SIM117", # MultipleWithStatements
"SIM118", # KeyInDict
"SIM201", # NegateEqualOp
"SIM300", # yoda condition

# flake8-print (T20)
"T201", # PrintUsed

# flake8-todos (TD)
"TD001", # Invalid TODO tag
"TD003", # Missing issue link on the line following this TODO
"TD004", # Missing colon in TODO
"TD007", # Missing space after colon in TODO

# tryceratops (TRY)
"TRY002", # raise-vanilla-class
"TRY003", # raise-vanilla-args
"TRY004", # prefer-type-error
"TRY201", # verbose-raise
"TRY301", # raise-within-try

# pyupgrade (UP)
"UP038", # isinstance using union separators. The code is slower as of Python 3.11-3.12

# flake8-quotes (Q)
"Q000", # use double quotes
]
lint.unfixable = [
"E711" # NoneComparison. Hard to fix b/c numpy has it's own None.
]

[lint.extend-per-file-ignores]
"__init__.py" = ["E402", "F401", "F403"]
"test_*.py" = [
"PTH", # all flake8-use-pathlib
"RUF015", # Prefer next({iterable}) over single element slice
"F401",
]
# TODO: fix these, on a per-subpackage basis.
# When a general exclusion is being fixed, but it affects many subpackages, it
# is better to fix for subpackages individually. The general exclusion should be
# copied to these subpackage sections and fixed there.
# "astropy/config/*" = []
# "astropy/constants/*" = [
# "N817", # camelcase-imported-as-acronym
# "RET505", # superfluous-else-return
# ]
1 change: 0 additions & 1 deletion CITATION
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,3 @@ archivePrefix = "arXiv",
adsurl = {https://adsabs.harvard.edu/abs/2015ApJ...800..109B},
adsnote = {Provided by the SAO/NASA Astrophysics Data System}
}

Loading

0 comments on commit f75fb50

Please sign in to comment.