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

chore: Switch to Ruff #112

Merged
merged 12 commits into from
Apr 22, 2024
40 changes: 7 additions & 33 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ ci:

repos:

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.1
hooks:
- id: ruff
args: [ --fix ]
- id: ruff-format

- repo: https://github.com/commitizen-tools/commitizen
rev: v3.22.0
hooks:
Expand Down Expand Up @@ -38,44 +45,11 @@ repos:
- id: rst-directive-colons
- id: rst-inline-touching-normal

- repo: https://github.com/psf/black
rev: 24.4.0
hooks:
- id: black

- repo: https://github.com/PyCQA/bandit
rev: 1.7.8
hooks:
- id: bandit
args: ["-c", "pyproject.toml"]
additional_dependencies: ["bandit[toml]"]

- repo: https://github.com/PyCQA/doc8
rev: v1.1.1
hooks:
- id: doc8

- repo: https://github.com/PyCQA/flake8
rev: 7.0.0
hooks:
- id: flake8

- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
- id: isort

- repo: https://github.com/PyCQA/prospector
rev: v1.10.3
hooks:
- id: prospector
additional_dependencies: ["dateparser"]

- repo: https://github.com/PyCQA/pydocstyle
rev: 6.3.0
hooks:
- id: pydocstyle

- repo: https://github.com/regebro/pyroma
rev: "4.2"
hooks:
Expand Down
41 changes: 5 additions & 36 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ pre-commit install --hook-type commit-msg --hook-type pre-push
[precommit]: https://pre-commit.com/

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

[ruff]: https://docs.astral.sh/ruff/
[commitizen]: https://github.com/commitizen-tools/commitizen
[conventional]: https://www.conventionalcommits.org/en/v1.0.0/
[extension]: https://marketplace.visualstudio.com/items?itemName=vivaxy.vscode-conventional-commits
[mypy]: https://github.com/python/mypy
[typing]: https://docs.python.org/3/library/typing.html
[black]: https://github.com/psf/black
[bandit]: https://github.com/PyCQA/bandit
[rest]: https://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html
[doc8]: https://github.com/PyCQA/doc8
[flake8]: https://github.com/pyCQA/flake8
[isort]: https://github.com/pyCQA/isort
[prospector]: https://github.com/landscapeio/prospector
[dodgy]: https://github.com/landscapeio/dodgy
[mccabe]: https://github.com/PyCQA/mccabe
[pycodestyle]: https://pycodestyle.pycqa.org/en/latest/
[pyflakes]: https://launchpad.net/pyflakes
[pylint]: https://www.pylint.org/
[pydocstyle]: https://github.com/PyCQA/pydocstyle
[pep257]: http://www.python.org/dev/peps/pep-0257/
[pyroma]: https://github.com/regebro/pyroma

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

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

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

Expand Down
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
[![Code Style: black](https://img.shields.io/badge/Code%20Style-black-000000.svg)](https://github.com/psf/black)
[![codecov](https://codecov.io/gh/sandialabs/reverse_argparse/branch/master/graph/badge.svg?token=FmDStZ6FVR)](https://codecov.io/gh/sandialabs/reverse_argparse)
[![CodeFactor](https://www.codefactor.io/repository/github/sandialabs/reverse_argparse/badge/master)](https://www.codefactor.io/repository/github/sandialabs/reverse_argparse/overview/master)
[![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)
Expand All @@ -8,18 +7,17 @@
[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](CODE_OF_CONDUCT.md)
[![GitHub contributors](https://img.shields.io/github/contributors/sandialabs/reverse_argparse.svg)](https://github.com/sandialabs/reverse_argparse/graphs/contributors)
[![Documentation Status](https://readthedocs.org/projects/reverse-argparse/badge/?version=latest)](https://reverse-argparse.readthedocs.io/en/latest/?badge=latest)
[![Anaconda-Server Badge](https://anaconda.org/conda-forge/reverse-argparse/badges/license.svg)](LICENSE.md)
[![Linting: Pylint](https://img.shields.io/badge/Linting-Pylint-yellowgreen)](https://github.com/pylint-dev/pylint)
[![License](https://anaconda.org/conda-forge/reverse-argparse/badges/license.svg)](LICENSE.md)
[![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)
[![OpenSSF Best Practices](https://bestpractices.coreinfrastructure.org/projects/7632/badge)](https://bestpractices.coreinfrastructure.org/projects/7632)
[![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/sandialabs/reverse_argparse/badge)](https://securityscorecards.dev/viewer/?uri=github.com/sandialabs/reverse_argparse)
![Anaconda-Server Badge](https://anaconda.org/conda-forge/reverse-argparse/badges/platforms.svg)
![Platforms](https://anaconda.org/conda-forge/reverse-argparse/badges/platforms.svg)
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://github.com/pre-commit/pre-commit)
[![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)
[![PyPI - Version](https://img.shields.io/pypi/v/reverse-argparse?label=PyPI)](https://pypi.org/project/reverse-argparse/)
![PyPI - Downloads](https://img.shields.io/pypi/dm/reverse-argparse?label=PyPI%20downloads)
![Python Version](https://img.shields.io/badge/Python-3.8|3.9|3.10|3.11|3.12-blue.svg)
[![Security: Bandit](https://img.shields.io/badge/Security-Bandit-yellow.svg)](https://github.com/PyCQA/bandit)
[![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)

# reverse_argparse

Expand Down
6 changes: 3 additions & 3 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
# -- Project information ------------------------------------------------------

project = "reverse_argparse"
copyright = (
"2023–2024, National Technology & Engineering Solutions of Sandia, LLC "
"(NTESS)"
copyright = ( # noqa: A001
"2023–2024, National Technology & Engineering Solutions " # noqa: RUF001
"of Sandia, LLC (NTESS)"
)
author = "Jason M. Gates"
version = "1.0.6"
Expand Down
12 changes: 3 additions & 9 deletions doc/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ reverse_argparse
examples
reference

|Code Style: black|
|codecov|
|CodeFactor|
|CodeQL|
Expand All @@ -21,7 +20,6 @@ reverse_argparse
|GitHub Contributors|
|Documentation Status|
|License|
|Linting: Pylint|
|Merged PRs|
|OpenSSF Best Practices|
|OpenSSF Scorecard|
Expand All @@ -31,10 +29,8 @@ reverse_argparse
|PyPI Version|
|PyPI Downloads|
|Python Version|
|Security: Bandit|
|Ruff|

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

The ``reverse_argparse`` module provides a means of undoing the argument
parsing provided by :mod:`argparse`. That is, it can take a
Expand Down
2 changes: 1 addition & 1 deletion example/post_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
parser.add_argument("--foo")
parser.add_argument("--bar", default="spam")
parser.add_argument("--baz", type=int, default=42)
parser.add_argument("--src", type=os.path.abspath) # type: ignore
parser.add_argument("--src", type=os.path.abspath) # type: ignore[arg-type]
parser.add_argument("--before")

# Parse the command line arguments.
Expand Down
2 changes: 1 addition & 1 deletion example/pretty_printing.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
parser.add_argument("--foo")
parser.add_argument("--bar", default="spam")
parser.add_argument("--baz", type=int, default=42)
parser.add_argument("--src", type=os.path.abspath) # type: ignore
parser.add_argument("--src", type=os.path.abspath) # type: ignore[arg-type]
parser.add_argument("--before")

# Parse the command line arguments.
Expand Down
2 changes: 1 addition & 1 deletion example/relative_references.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
parser.add_argument("--foo")
parser.add_argument("--bar", default="spam")
parser.add_argument("--baz", type=int, default=42)
parser.add_argument("--src", type=os.path.abspath) # type: ignore
parser.add_argument("--src", type=os.path.abspath) # type: ignore[arg-type]

# Parse the command line arguments.
args = parser.parse_args()
Expand Down
5 changes: 4 additions & 1 deletion example/subparsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
foo_parser.add_argument("--two", default="spam")
foo_parser.add_argument("--three", type=int, default=42)
bar_parser = subparsers.add_parser("bar")
bar_parser.add_argument("--four", type=os.path.abspath) # type: ignore
bar_parser.add_argument(
"--four",
type=os.path.abspath, # type: ignore[arg-type]
)
bar_parser.add_argument("--five")

# Parse the command line arguments.
Expand Down
Loading
Loading