Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update linting workflow #810

Merged
merged 8 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added .codespellexclude
Empty file.
1 change: 1 addition & 0 deletions .codespellignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
NAM
40 changes: 28 additions & 12 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,56 @@ on:
push:
branches: [main]
pull_request:
branches: [main]

concurrency:
group: ${{ github.workflow}}-${{ github.head_ref }}
cancel-in-progress: true

jobs:
flake8:
name: Flake8
lint:
name: Run Lint Tools
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Python 3
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: 3.x
cache: 'pip'
cache-dependency-path: 'ci/linting_requirements.txt'

- name: Install flake8
- name: Install linting tools
run: python -m pip install -r ci/linting_requirements.txt

- name: Set up reviewdog
run: |
mkdir -p $HOME/bin
curl -sfL \
https://github.com/reviewdog/reviewdog/raw/master/install.sh | \
sh -s -- -b $HOME/bin
echo "$HOME/bin" >> $GITHUB_PATH
uses: reviewdog/action-setup@v1

- name: Run ruff
run: ruff check --output-format github

- name: Run flake8
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -o pipefail
flake8 | reviewdog -f=pep8 -name=flake8 -reporter=github-check -filter-mode=nofilter

- name: Run doc8
# Don't skip doc8 if flake8 fails
if: ${{ always() }}
if: always()
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -o pipefail
doc8 docs | reviewdog -efm='%f:%l: %m' -name=doc8 -reporter=github-check -filter-mode=nofilter

- name: Run codespell
# Don't skip codespell if any other steps fail
if: always()
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -o pipefail
codespell | reviewdog -efm='%f:%l: %m' -name=codespell -reporter=github-check -filter-mode=nofilter
2 changes: 1 addition & 1 deletion ci/download_cartopy_maps.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python
# Copyright (c) 2021 MetPy Developers.
# Copyright (c) 2021 Siphon Contributors.
"""Explicitly download needed Cartopy maps."""
from cartopy.io import config, Downloader

Expand Down
2 changes: 1 addition & 1 deletion ci/filter_links.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python
# Copyright (c) 2021 MetPy Developers.
# Copyright (c) 2021 Siphon Contributors.
"""Filter links from Sphinx's linkcheck."""
import json
import subprocess
Expand Down
4 changes: 2 additions & 2 deletions ci/gen_versions_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@

import glob

with open('versions.json', 'wt') as version_file:
version_strings = ','.join('"{}"'.format(d) for d in glob.glob('v*.[0-9]*'))
with open('versions.json', 'w') as version_file:
version_strings = ','.join(f'"{d}"' for d in glob.glob('v*.[0-9]*'))
version_file.write('{"versions":["latest","dev",' + version_strings + ']}\n')
21 changes: 8 additions & 13 deletions ci/linting_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
ruff==0.7.1

flake8==5.0.4
pycodestyle==2.9.1
pyflakes==2.5.0

flake8-bugbear==22.9.23
flake8-builtins==1.5.3
flake8-comprehensions==3.10.0
flake8-copyright==0.2.3
flake8-import-order==0.18.1
flake8-mutable==1.2.0
flake8-pep3101==1.3.0
flake8-print==5.0.0
flake8-quotes==3.3.1
flake8-simplify==0.19.3
pep8-naming==0.13.2
flake8-continuation==1.0.5
flake8-isort==6.1.1
isort==5.13.2
flake8-requirements==2.2.1

flake8-rst-docstrings==0.2.7
flake8-docstrings==1.6.0
pydocstyle==6.1.1

doc8==1.0.0
restructuredtext_lint==1.4.0

codespell==2.3.0
2 changes: 1 addition & 1 deletion docs/api/simplewebservice.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@
===================================
.. automodule:: siphon.simplewebservice.ndbc
:members:
:special-members: __init__
:special-members: __init__
3 changes: 1 addition & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# This file is execfile()d with the current directory set to its
# containing dir.
Expand Down Expand Up @@ -47,7 +46,7 @@
},
'examples_dirs': [os.path.join('..', 'examples')],
'gallery_dirs': ['examples'],
'filename_pattern': '\.py',
'filename_pattern': r'\.py',
'backreferences_dir': 'api/generated',
'default_thumb_file': os.path.join('_static', 'siphon_150x150_white_bg.png'),
'abort_on_example_error': True
Expand Down
17 changes: 6 additions & 11 deletions docs/developerguide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,17 @@ Testing
Unit tests are the lifeblood of the project, as it ensures that we can continue to add and
change the code and stay confident that things have not broken. Running the tests requires
``pytest``, which is easily available through ``conda`` or ``pip``. Running the tests can be
done via either:
done by:

.. parsed-literal::
python setup.py test
pytest tests

or

.. parsed-literal::
py.test

Using ``py.test`` also gives you the option of passing a path to the directory with tests to
This gives you the option of passing a path to the directory with tests to
run, which can speed running only the tests of interest when doing development. For instance,
to only run the tests in the ``siphon/cdmr`` directory, use:

.. parsed-literal::
py.test siphon/cdmr
pytest siphon/cdmr

----------
Code Style
Expand Down Expand Up @@ -142,7 +137,7 @@ To create a new release:
3. (optional) Perform a ``git clean -f -x -d`` from the root of the repository. This will
**delete** everything not tracked by git, but will also ensure clean source distribution.
``MANIFEST.in`` is set to include/exclude mostly correctly, but could miss some things.
4. Run ``python setup.py sdist bdist_wheel`` (this requires ``wheel`` is installed).
4. Run ``python -m build`` (this requires that ``build`` is installed).
5. Upload using ``twine``: ``twine upload dist/*``, assuming the ``dist/`` directory contains
only files for this release. This upload process will include any changes to the ``README``
as well as any updated flags from ``setup.py``.
as well as any updated flags from ``pyproject.toml``.
18 changes: 6 additions & 12 deletions docs/installguide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ In general, Siphon tries to support minor versions of dependencies released with
years. For Python itself, that means supporting the last two minor releases.

Siphon currently supports the following versions of required dependencies:
- requests >= 1.2
- numpy >= 1.8.0
- protobuf >= 3.0.0
- beautifulsoup4>=4.6
- pandas

.. literalinclude:: ../pyproject.toml
:start-at: beautifulsoup4
:end-at: requests

Installation Instructions for NumPy can be found at:
https://numpy.org/install/
Expand All @@ -27,12 +26,7 @@ The easiest way to install Siphon is through ``pip``:
.. parsed-literal::
pip install siphon

Siphon can also be installed through ``conda``:

.. parsed-literal::
conda install -c unidata siphon

Additionally, Siphon can be installed with ``conda-forge``:
Siphon can also be installed through ``conda``, using the ``conda-forge`` channel:

.. parsed-literal::
conda install -c conda-forge siphon
Expand All @@ -41,7 +35,7 @@ The source code can also be grabbed from `GitHub <https://github.com/Unidata/sip
the base of the source directory, run:

.. parsed-literal::
python setup.py install
pip install .

This will build and install Siphon into your current Python installation.

Expand Down
2 changes: 1 addition & 1 deletion examples/acis/Basic_Overview.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@

###########################################
# Now that we have our request information ready, we can call the acis_request
# function and recieve our data!
# function and receive our data!

my_data = acis_request(method, parameters)

Expand Down
66 changes: 66 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,71 @@ extras = [
"Bug Tracker" = "https://github.com/Unidata/siphon/issues"
"Source Code" = "https://github.com/Unidata/siphon"

[tool.codespell]
skip = "*.ipynb,*.pdf,.git,./docs/build,./docs/examples,./tests/fixtures,./tests/cdmr/fixtures,AUTHORS.txt"
exclude-file = ".codespellexclude"
ignore-words = ".codespellignore"

[tool.doc8]
ignore-path = ["docs/build", "docs/api/generated", "docs/_templates", "docs/examples"]
file-encoding = "utf8"
max-line-length = 95

[tool.isort]
line_length = 95
known_first_party = ["siphon"]
force_single_line = false
reverse_relative = true
use_parentheses = true
force_sort_within_sections = true
order_by_type = false
sort_relative_in_force_sorted_sections = true
combine_as_imports = true
combine_star = true

[tool.pytest.ini_options]
norecursedirs = "build docs .idea"
doctest_optionflags = "NORMALIZE_WHITESPACE"

[tool.ruff]
line-length = 95
exclude = ["docs", "build", "src/siphon/cdmr/*_pb2.py"]
preview = true

[tool.ruff.lint]
select = ["A", "B", "C", "CPY001", "D", "E", "E226", "F", "G", "I", "N", "NPY", "PIE", "Q", "R", "S", "SIM", "T", "U", "W"]
# NPY201 ignores the use of 'trapz' false alarm
ignore = ["F405", "I001", "NPY201", "RET504", "RET505", "RET506", "RET507", "RUF100", "S314"]
explicit-preview-rules = true

[tool.ruff.lint.per-file-ignores]
"ci/filter_links.py" = ["E731", "T201", "S603", "S607"]
"examples/*.py" = ["D", "T201", "B018"]
"tests/*/*.py" = ["S101"]
"tests/test_*.py" = ["S101"]

[tool.ruff.lint.flake8-copyright]
# Needed to avoid need for spaces after a comma
notice-rgx = "(?i)Copyright\\s+(\\(C\\)\\s+)?\\d{4}([-,]\\d{4})*"
author = "Siphon Contributors"

[tool.ruff.lint.flake8-quotes]
inline-quotes = "single"
multiline-quotes = "double"

[tool.ruff.lint.isort]
known-first-party = ["siphon"]
force-single-line = false
relative-imports-order = "closest-to-furthest"
force-sort-within-sections = true
order-by-type = false
combine-as-imports = true

[tool.ruff.lint.mccabe]
max-complexity = 61

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

[tool.setuptools_scm]
version_scheme = "post-release"
45 changes: 11 additions & 34 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,38 +1,15 @@
[pycodestyle]
ignore = W503
max-line-length = 95

[flake8]
max-line-length = 95
application-import-names = siphon
import-order-style = google
copyright-check = True
copyright-author = Siphon Contributors
inline-quotes = single
multiline-quotes = double
rst-roles = class, data, doc, func, meth, mod
rst-directives = plot, versionchanged
docstring-convention = numpy
exclude =
docs
build
src/siphon/cdmr/ncStream_pb2.py
src/siphon/cdmr/cdmrfeature_pb2.py
select = A B C D E F H I M Q RST S T W B902
ignore = F405 W503 RST902 SIM
per-file-ignores = examples/*.py: D T201
tutorials/*.py: D T201

[tool:pytest]
norecursedirs = build docs

[doc8]
ignore-path = docs/build,docs/api
max-line-length = 95

[bdist_wheel]
# This flag says that the code is written to work on both Python 2 and 3.
universal=1

[aliases]
test = pytest

[yapf]
based_on_style = pep8
column_limit = 90
known-modules = netcdf4:[netCDF4]
exclude = docs build src/siphon/cdmr/*_pb2.py
select = E301 E302 E303 E304 E305 E306 I R
ignore = F405 W503 RST902 SIM106
per-file-ignores = src/siphon/_version.py: I900
src/siphon/testing.py: I900
ci/filter_links.py: E731
23 changes: 0 additions & 23 deletions setup.py

This file was deleted.

1 change: 1 addition & 0 deletions src/siphon/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@

# Version import needs to come first so everyone else can pull on import
from ._version import get_version

__version__ = get_version()
del get_version
Loading
Loading