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

Use Ruff implementation of PyDocStyle and isort #59

Merged
merged 6 commits into from
Aug 16, 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
15 changes: 0 additions & 15 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
repos:
- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
files: template

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.7
hooks:
- id: ruff
name: ruff linter
args: [--fix, --show-fixes]
files: template
- id: ruff-format
name: ruff formatter
files: template

- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
Expand All @@ -23,13 +15,6 @@ repos:
args: [--write-changes]
additional_dependencies: [tomli]

- repo: https://github.com/pycqa/pydocstyle
rev: 6.3.0
hooks:
- id: pydocstyle
files: template
additional_dependencies: [tomli]

- repo: https://github.com/mscheltienne/bibclean
rev: 0.8.0
hooks:
Expand Down
5 changes: 3 additions & 2 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# https://www.sphinx-doc.org/en/master/usage/configuration.html

from __future__ import annotations

import inspect
import subprocess
import sys
Expand All @@ -24,7 +25,7 @@

project = "template-python"
author = "Mathieu Scheltienne"
copyright = f"{date.today().year}, {author}"
copyright = f"{date.today().year}, {author}" # noqa: A001
release = template.__version__
package = template.__name__
gh_url = "https://github.com/mscheltienne/template-python"
Expand Down Expand Up @@ -95,7 +96,7 @@
<svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0 0 16 8c0-4.42-3.58-8-8-8z"></path>
</svg>
""",
""", # noqa: E501
"class": "",
},
],
Expand Down
40 changes: 13 additions & 27 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,14 @@ full = [
'template[all]',
]
stubs = [
'isort',
'mypy',
'ruff>=0.1.8',
'ruff>=0.6.0',
]
style = [
'bibclean',
'codespell[toml]>=2.2.4',
'isort',
'pydocstyle[toml]',
'ruff>=0.1.8',
'pre-commit',
'ruff>=0.6.0',
'toml-sort',
'yamllint',
]
Expand Down Expand Up @@ -120,33 +118,13 @@ omit = [
'**/tests/**',
]

[tool.isort]
extend_skip_glob = [
'doc/*',
'examples/*',
'tutorials/*',
]
line_length = 88
multi_line_output = 3
profile = 'black'
py_version = 39

[tool.pydocstyle]
add_ignore = 'D100,D104,D107'
convention = 'numpy'
ignore-decorators = '(copy_doc|property|.*setter|.*getter|pyqtSlot|Slot)'
match = '^(?!__init__|test_).*\.py'
match-dir = '^template.*'

[tool.pytest.ini_options]
addopts = ['--color=yes', '--cov-report=', '--durations=20', '--junit-xml=junit-results.xml', '--strict-config', '--tb=short', '-ra', '-v']
junit_family = 'xunit2'
minversion = '8.0'

[tool.ruff]
extend-exclude = [
'doc',
]
extend-exclude = []
line-length = 88

[tool.ruff.format]
Expand All @@ -155,15 +133,23 @@ line-ending = "lf"

[tool.ruff.lint]
ignore = []
select = ['A', 'B', 'E', 'F', 'G', 'LOG', 'NPY', 'PIE', 'PT', 'T20', 'UP', 'W']
select = ['A', 'B', 'D', 'E', 'F', 'G', 'I', 'LOG', 'NPY', 'PIE', 'PT', 'T20', 'UP', 'W']

[tool.ruff.lint.per-file-ignores]
'*' = [
'B904', # 'Within an except clause, raise exceptions with raise ... from ...'
'D100', # 'Missing docstring in public module'
'D104', # 'Missing docstring in public package'
'D107', # 'Missing docstring in __init__'
'UP007', # 'Use `X | Y` for type annotations', requires python 3.10
]
'*.pyi' = ['E501']
'__init__.py' = ['F401']
'tutorials/*' = ['D205', 'D400', 'T201']

[tool.ruff.lint.pydocstyle]
convention = 'numpy'
ignore-decorators = ["template.utils._docs.copy_doc"]

[tool.setuptools]
include-package-data = false
Expand Down
4 changes: 2 additions & 2 deletions template/commands/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@


@click.group()
def run() -> None: # noqa: D401
"""Main package entry-point."""
def run() -> None:
"""Main package entry-point.""" # noqa: D401


run.add_command(sys_info)
9 changes: 5 additions & 4 deletions tools/stubgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from importlib import import_module
from pathlib import Path

import isort
from mypy import stubgen

import template
Expand Down Expand Up @@ -33,7 +32,6 @@
)
stubs = list(directory.rglob("*.pyi"))
config = str(directory.parent / "pyproject.toml")
config_isort = isort.settings.Config(config)

# expand docstrings and inject into stub files
for stub in stubs:
Expand All @@ -59,9 +57,12 @@
method.body[0].value.value = docstring
unparsed = ast.unparse(module_ast)
stub.write_text(unparsed, encoding="utf-8")
# sort imports
isort.file(stub, config=config_isort)

# run ruff to improve stub style
execution = subprocess.run(
["ruff", "check", str(directory), "--fix", "--unsafe-fixes", "--config", config]
)
if execution.returncode:
sys.exit(execution.returncode)
execution = subprocess.run(["ruff", "format", str(directory), "--config", config])
sys.exit(execution.returncode)