Skip to content

Commit 21a02d3

Browse files
authored
Merge pull request #112 from sandialabs/switch-to-ruff
chore: Switch to Ruff
2 parents 70f2968 + f02c7f2 commit 21a02d3

15 files changed

+253
-209
lines changed

.pre-commit-config.yaml

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ ci:
66

77
repos:
88

9+
- repo: https://github.com/astral-sh/ruff-pre-commit
10+
rev: v0.4.1
11+
hooks:
12+
- id: ruff
13+
args: [ --fix ]
14+
- id: ruff-format
15+
916
- repo: https://github.com/commitizen-tools/commitizen
1017
rev: v3.24.0
1118
hooks:
@@ -38,44 +45,11 @@ repos:
3845
- id: rst-directive-colons
3946
- id: rst-inline-touching-normal
4047

41-
- repo: https://github.com/psf/black
42-
rev: 24.4.0
43-
hooks:
44-
- id: black
45-
46-
- repo: https://github.com/PyCQA/bandit
47-
rev: 1.7.8
48-
hooks:
49-
- id: bandit
50-
args: ["-c", "pyproject.toml"]
51-
additional_dependencies: ["bandit[toml]"]
52-
5348
- repo: https://github.com/PyCQA/doc8
5449
rev: v1.1.1
5550
hooks:
5651
- id: doc8
5752

58-
- repo: https://github.com/PyCQA/flake8
59-
rev: 7.0.0
60-
hooks:
61-
- id: flake8
62-
63-
- repo: https://github.com/PyCQA/isort
64-
rev: 5.13.2
65-
hooks:
66-
- id: isort
67-
68-
- repo: https://github.com/PyCQA/prospector
69-
rev: v1.10.3
70-
hooks:
71-
- id: prospector
72-
additional_dependencies: ["dateparser"]
73-
74-
- repo: https://github.com/PyCQA/pydocstyle
75-
rev: 6.3.0
76-
hooks:
77-
- id: pydocstyle
78-
7953
- repo: https://github.com/regebro/pyroma
8054
rev: "4.2"
8155
hooks:

CONTRIBUTING.md

Lines changed: 5 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ pre-commit install --hook-type commit-msg --hook-type pre-push
6969
[precommit]: https://pre-commit.com/
7070

7171
The checks we perform are the following:
72+
* Use [ruff][ruff] to lint and format the code and docstrings.
7273
* Use [commitizen][commitizen] to ensure commit messages match the
7374
[Conventional Commits specification][conventional]. Use the
7475
[Conventional Commits extension for VS Code][extension] (or something
@@ -84,42 +85,18 @@ The checks we perform are the following:
8485
* Trim trailing whitespace.
8586
* Ensure we use [type-hinting][typing].
8687
* Check for common mistakes in [reStructuredText][rest] in our documentation.
87-
* Use [black][black] to automatically format the code.
88-
* Use [Bandit][bandit] to find common security issues.
8988
* Use [doc8][doc8] to enforce our style for our documentation.
90-
* Lint the code with [flake8][flake8].
91-
* Use [isort][isort] to ensure `import` statements are sorted correctly.
92-
* Use [prospector][prospector] to check for various errors, potential problems,
93-
convention violations, complexity, etc. This uses the following tools under
94-
the hood:
95-
* [dodgy][dodgy]
96-
* [mccabe][mccabe]
97-
* [pycodestyle][pycodestyle]
98-
* [Pyflakes][pyflakes]
99-
* [Pylint][pylint]
100-
* Use [pydocstyle][pydocstyle] to ensure our docstrings line up with
101-
[PEP 257][pep257].
10289
* Use [pyroma][pyroma] to ensure our package complies with the best practices
10390
of the Python packaging ecosystem.
10491

92+
[ruff]: https://docs.astral.sh/ruff/
10593
[commitizen]: https://github.com/commitizen-tools/commitizen
10694
[conventional]: https://www.conventionalcommits.org/en/v1.0.0/
10795
[extension]: https://marketplace.visualstudio.com/items?itemName=vivaxy.vscode-conventional-commits
10896
[mypy]: https://github.com/python/mypy
10997
[typing]: https://docs.python.org/3/library/typing.html
110-
[black]: https://github.com/psf/black
111-
[bandit]: https://github.com/PyCQA/bandit
98+
[rest]: https://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html
11299
[doc8]: https://github.com/PyCQA/doc8
113-
[flake8]: https://github.com/pyCQA/flake8
114-
[isort]: https://github.com/pyCQA/isort
115-
[prospector]: https://github.com/landscapeio/prospector
116-
[dodgy]: https://github.com/landscapeio/dodgy
117-
[mccabe]: https://github.com/PyCQA/mccabe
118-
[pycodestyle]: https://pycodestyle.pycqa.org/en/latest/
119-
[pyflakes]: https://launchpad.net/pyflakes
120-
[pylint]: https://www.pylint.org/
121-
[pydocstyle]: https://github.com/PyCQA/pydocstyle
122-
[pep257]: http://www.python.org/dev/peps/pep-0257/
123100
[pyroma]: https://github.com/regebro/pyroma
124101

125102
### VS Code
@@ -183,9 +160,8 @@ search for and install them. These are the ones we recommend:
183160
editor.
184161
* **autoDocstring - Python Docstring Generator:** Quickly generate docstrings
185162
for Python functions.
186-
* **Flake8:** Linting support for Python files using flake8.
163+
* **Mpy Type Checker:** Type checking support for Python.
187164
* **Pylance:** Fast, feature-rich language support for Python.
188-
* **Pylint:** Linting support for Python files.
189165
* **Pytest IntelliSense:** Adds IntelliSense support for [pytest][pytest]
190166
fixtures.
191167
* **Python:** Rich support for the Python language.
@@ -194,6 +170,7 @@ search for and install them. These are the ones we recommend:
194170
or [testplan][testplan] tests with the Test Explorer UI (see **General**
195171
above).
196172
* **Python Type Hint:** Type hint autocompletion.
173+
* **Ruff:** Automatic linting and formatting.
197174
* **Sourcery:** Automatic code review and refactoring.
198175

199176
[unittest]: https://docs.python.org/3/library/unittest.html
@@ -233,13 +210,6 @@ After installing the various extensions, you'll also want to customize your
233210
* **Terminal Git Editor:** Check.
234211
* pre-commit-helper
235212
* **Run On Save:** Select "all hooks".
236-
* Python
237-
* **Formatting:** Provider: Select "black".
238-
* **Linting: Bandit Enabled:** Check.
239-
* **Linting: Flake8 Enabled:** Check.
240-
* **Linting: Lint On Save:** Check.
241-
* **Linting: Mypy Enabled:** Check.
242-
* **Linting: Prospector Enabled:** Check.
243213
* Python Docstring Generator configuration
244214
* **Docstring Format:** Select "google-notypes".
245215
* **Start On New Line:** Check.
@@ -372,7 +342,6 @@ utilize [type-hinting][typing] wherever possible for clarity's sake.
372342

373343
[docstrings]: https://www.python.org/dev/peps/pep-0257
374344
[google]: https://github.com/google/styleguide/blob/gh-pages/pyguide.md#38-comments-and-docstrings
375-
[rest]: https://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html
376345
[docs]: https://reverse-argparse.readthedocs.io
377346
[sphinx]: https://www.sphinx-doc.org/en/master/
378347

README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
[![Code Style: black](https://img.shields.io/badge/Code%20Style-black-000000.svg)](https://github.com/psf/black)
21
[![codecov](https://codecov.io/gh/sandialabs/reverse_argparse/branch/master/graph/badge.svg?token=FmDStZ6FVR)](https://codecov.io/gh/sandialabs/reverse_argparse)
32
[![CodeFactor](https://www.codefactor.io/repository/github/sandialabs/reverse_argparse/badge/master)](https://www.codefactor.io/repository/github/sandialabs/reverse_argparse/overview/master)
43
[![CodeQL](https://github.com/sandialabs/reverse_argparse/actions/workflows/github-code-scanning/codeql/badge.svg)](https://github.com/sandialabs/reverse_argparse/actions/workflows/github-code-scanning/codeql)
@@ -8,18 +7,17 @@
87
[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](CODE_OF_CONDUCT.md)
98
[![GitHub contributors](https://img.shields.io/github/contributors/sandialabs/reverse_argparse.svg)](https://github.com/sandialabs/reverse_argparse/graphs/contributors)
109
[![Documentation Status](https://readthedocs.org/projects/reverse-argparse/badge/?version=latest)](https://reverse-argparse.readthedocs.io/en/latest/?badge=latest)
11-
[![Anaconda-Server Badge](https://anaconda.org/conda-forge/reverse-argparse/badges/license.svg)](LICENSE.md)
12-
[![Linting: Pylint](https://img.shields.io/badge/Linting-Pylint-yellowgreen)](https://github.com/pylint-dev/pylint)
10+
[![License](https://anaconda.org/conda-forge/reverse-argparse/badges/license.svg)](LICENSE.md)
1311
[![Merged PRs](https://img.shields.io/github/issues-pr-closed-raw/sandialabs/reverse_argparse.svg?label=merged+PRs)](https://github.com/sandialabs/reverse_argparse/pulls?q=is:pr+is:merged)
1412
[![OpenSSF Best Practices](https://bestpractices.coreinfrastructure.org/projects/7632/badge)](https://bestpractices.coreinfrastructure.org/projects/7632)
1513
[![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/sandialabs/reverse_argparse/badge)](https://securityscorecards.dev/viewer/?uri=github.com/sandialabs/reverse_argparse)
16-
![Anaconda-Server Badge](https://anaconda.org/conda-forge/reverse-argparse/badges/platforms.svg)
14+
![Platforms](https://anaconda.org/conda-forge/reverse-argparse/badges/platforms.svg)
1715
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://github.com/pre-commit/pre-commit)
1816
[![pre-commit.ci Status](https://results.pre-commit.ci/badge/github/sandialabs/reverse_argparse/master.svg)](https://results.pre-commit.ci/latest/github/sandialabs/reverse_argparse/master)
1917
[![PyPI - Version](https://img.shields.io/pypi/v/reverse-argparse?label=PyPI)](https://pypi.org/project/reverse-argparse/)
2018
![PyPI - Downloads](https://img.shields.io/pypi/dm/reverse-argparse?label=PyPI%20downloads)
2119
![Python Version](https://img.shields.io/badge/Python-3.8|3.9|3.10|3.11|3.12-blue.svg)
22-
[![Security: Bandit](https://img.shields.io/badge/Security-Bandit-yellow.svg)](https://github.com/PyCQA/bandit)
20+
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
2321

2422
# reverse_argparse
2523

doc/source/conf.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
# -- Project information ------------------------------------------------------
1414

1515
project = "reverse_argparse"
16-
copyright = (
17-
"2023–2024, National Technology & Engineering Solutions of Sandia, LLC "
18-
"(NTESS)"
16+
copyright = ( # noqa: A001
17+
"2023–2024, National Technology & Engineering Solutions " # noqa: RUF001
18+
"of Sandia, LLC (NTESS)"
1919
)
2020
author = "Jason M. Gates"
2121
version = "1.0.6"

doc/source/index.rst

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ reverse_argparse
1010
examples
1111
reference
1212

13-
|Code Style: black|
1413
|codecov|
1514
|CodeFactor|
1615
|CodeQL|
@@ -21,7 +20,6 @@ reverse_argparse
2120
|GitHub Contributors|
2221
|Documentation Status|
2322
|License|
24-
|Linting: Pylint|
2523
|Merged PRs|
2624
|OpenSSF Best Practices|
2725
|OpenSSF Scorecard|
@@ -31,10 +29,8 @@ reverse_argparse
3129
|PyPI Version|
3230
|PyPI Downloads|
3331
|Python Version|
34-
|Security: Bandit|
32+
|Ruff|
3533

36-
.. |Code Style: black| image:: https://img.shields.io/badge/Code%20Style-black-000000.svg
37-
:target: https://github.com/psf/black
3834
.. |codecov| image:: https://codecov.io/gh/sandialabs/reverse_argparse/branch/master/graph/badge.svg?token=FmDStZ6FVR
3935
:target: https://codecov.io/gh/sandialabs/reverse_argparse
4036
.. |CodeFactor| image:: https://www.codefactor.io/repository/github/sandialabs/reverse_argparse/badge/master
@@ -54,8 +50,6 @@ reverse_argparse
5450
:target: https://reverse-argparse.readthedocs.io/en/latest/?badge=latest
5551
.. |License| image:: https://anaconda.org/conda-forge/reverse-argparse/badges/license.svg
5652
:target: https://github.com/sandialabs/reverse_argparse/blob/master/LICENSE.md
57-
.. |Linting: Pylint| image:: https://img.shields.io/badge/Linting-Pylint-yellowgreen
58-
:target: https://github.com/pylint-dev/pylint
5953
.. |Merged PRs| image:: https://img.shields.io/github/issues-pr-closed-raw/sandialabs/reverse_argparse.svg?label=merged+PRs
6054
:target: https://github.com/sandialabs/reverse_argparse/pulls?q=is:pr+is:merged
6155
.. |OpenSSF Best Practices| image:: https://bestpractices.coreinfrastructure.org/projects/7632/badge
@@ -71,8 +65,8 @@ reverse_argparse
7165
:target: https://pypi.org/project/reverse-argparse/
7266
.. |PyPI Downloads| image:: https://img.shields.io/pypi/dm/reverse-argparse?label=PyPI%20downloads
7367
.. |Python Version| image:: https://img.shields.io/badge/Python-3.8|3.9|3.10|3.11|3.12-blue.svg
74-
.. |Security: Bandit| image:: https://img.shields.io/badge/Security-Bandit-yellow.svg
75-
:target: https://github.com/PyCQA/bandit
68+
.. |Ruff| image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json
69+
:target: https://github.com/astral-sh/ruff
7670

7771
The ``reverse_argparse`` module provides a means of undoing the argument
7872
parsing provided by :mod:`argparse`. That is, it can take a

example/post_processing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
parser.add_argument("--foo")
2020
parser.add_argument("--bar", default="spam")
2121
parser.add_argument("--baz", type=int, default=42)
22-
parser.add_argument("--src", type=os.path.abspath) # type: ignore
22+
parser.add_argument("--src", type=os.path.abspath) # type: ignore[arg-type]
2323
parser.add_argument("--before")
2424

2525
# Parse the command line arguments.

example/pretty_printing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
parser.add_argument("--foo")
2020
parser.add_argument("--bar", default="spam")
2121
parser.add_argument("--baz", type=int, default=42)
22-
parser.add_argument("--src", type=os.path.abspath) # type: ignore
22+
parser.add_argument("--src", type=os.path.abspath) # type: ignore[arg-type]
2323
parser.add_argument("--before")
2424

2525
# Parse the command line arguments.

example/relative_references.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
parser.add_argument("--foo")
1818
parser.add_argument("--bar", default="spam")
1919
parser.add_argument("--baz", type=int, default=42)
20-
parser.add_argument("--src", type=os.path.abspath) # type: ignore
20+
parser.add_argument("--src", type=os.path.abspath) # type: ignore[arg-type]
2121

2222
# Parse the command line arguments.
2323
args = parser.parse_args()

example/subparsers.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@
2121
foo_parser.add_argument("--two", default="spam")
2222
foo_parser.add_argument("--three", type=int, default=42)
2323
bar_parser = subparsers.add_parser("bar")
24-
bar_parser.add_argument("--four", type=os.path.abspath) # type: ignore
24+
bar_parser.add_argument(
25+
"--four",
26+
type=os.path.abspath, # type: ignore[arg-type]
27+
)
2528
bar_parser.add_argument("--five")
2629

2730
# Parse the command line arguments.

0 commit comments

Comments
 (0)