Skip to content

Commit

Permalink
Merge pull request #397 from NLeSC/378b-ruff-config-update-dbodor
Browse files Browse the repository at this point in the history
378b ruff config update dbodor
  • Loading branch information
DaniBodor authored Aug 2, 2024
2 parents 003117c + 9451420 commit a50915a
Show file tree
Hide file tree
Showing 13 changed files with 69 additions and 83 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cffconvert.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out a copy of the repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Check whether the citation metadata from CITATION.cff is valid
uses: citation-file-format/cffconvert-github-action@2.0.0
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/markdown-link-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
name: Check markdown links
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: gaurav-nelson/github-action-markdown-link-check@v1
with:
config-file: '.mlc-config.json'
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ jobs:
os: ['ubuntu-latest', 'macos-latest', 'windows-latest']
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Python info
Expand Down
2 changes: 1 addition & 1 deletion tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def test_ruff_check(baked_with_development_dependencies, project_env_bin_dir):
project_dir = baked_with_development_dependencies
bin_dir = project_env_bin_dir

result = run([f'{bin_dir}ruff', '.'], project_dir)
result = run([f'{bin_dir}ruff', 'check', '--fix'], project_dir)
assert result.returncode == 0
assert '' in result.stdout

Expand Down
3 changes: 2 additions & 1 deletion {{cookiecutter.directory_name}}/.githooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ echo "Script $0 triggered ..."
echo "Starting ruff analysis..."

# quietly run ruff
ruff check . --fix
ruff check --fix
ruff format

# use return code to abort commit if necessary
if [ $? != "0" ]; then
Expand Down
12 changes: 7 additions & 5 deletions {{cookiecutter.directory_name}}/.github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ jobs:
os: ['ubuntu-latest', 'macos-latest', 'windows-latest']
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ '{{ ' -}} matrix.python-version }}
uses: actions/setup-python@v3
uses: actions/setup-python@v5
with:
python-version: ${{ '{{ ' -}} matrix.python-version }}
- name: Python info
Expand All @@ -44,9 +44,9 @@ jobs:
strategy:
fail-fast: false
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python 3.9
uses: actions/setup-python@v3
uses: actions/setup-python@v5
with:
python-version: 3.9
- name: Python info
Expand All @@ -59,4 +59,6 @@ jobs:
python -m pip install --upgrade pip setuptools
python -m pip install .[dev,publishing]
- name: Check style against standards using ruff
run: ruff .
run: |
ruff check
ruff format --check
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
name: "cffconvert"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
name: Check out a copy of the repository

- name: Check whether the citation metadata from CITATION.cff is valid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ jobs:
strategy:
fail-fast: false
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python 3.9
uses: actions/setup-python@v3
uses: actions/setup-python@v5
with:
python-version: 3.9
- name: Python info
Expand All @@ -33,4 +33,4 @@ jobs:
run: sudo apt install pandoc
- name: Build documentation
run: make coverage doctest html
working-directory: docs
working-directory: docs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
name: Check markdown links
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: gaurav-nelson/github-action-markdown-link-check@v1
with:
config-file: '.mlc-config.json'
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
next_steps:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Create Sonarcloud integration issue
uses: JasonEtco/create-an-issue@v2
env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ jobs:
name: SonarCloud
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up Python
uses: actions/setup-python@v3
uses: actions/setup-python@v5
with:
python-version: 3.9
- name: Python info
Expand Down
109 changes: 46 additions & 63 deletions {{cookiecutter.directory_name}}/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -92,78 +92,61 @@ extras = dev
"""

[tool.ruff]
exclude = [
".bzr",
".direnv",
".eggs",
".git",
".hg",
".mypy_cache",
".nox",
".pants.d",
".ruff_cache",
".svn",
".tox",
".venv",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"venv",
".venv",
"scripts",
]

target-version = "py39"
line-length = 120

output-format = "concise"

[tool.ruff.lint]
# Enable Pyflakes `E` and `F` codes by default.
select = [
"F", # Pyflakes
"E", # pycodestyle (error)
"W", # pycodestyle (warning)
# "C90", # mccabe
"I", # isort
"D", # pydocstyle
# "PL", # Pylint
# "PLC", # Convention
# "PLE", # Error
# "PLR", # Refactor
# "PLW", # Warning
# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

]
# Enable Pyflakes `E` and `F` codes by default.
select = ["ALL"]
ignore = [
'D100', # Missing module docstring
'D104', # Missing public package docstring
# The following list excludes rules irrelevant to the Google style
'D203',
'D204',
'D213',
'D215',
'D400',
'D401',
'D404',
'D406',
'D407',
'D408',
'D409',
'D413',
"ANN101", # Missing type annotation for `self` in method
"ANN102", # Missing type annotation for `cls` in classmethod
"ANN204", # Missing return type annotation for special (dunder) method
"FBT", # Using boolean function arguments
"TD", # TODOs
"FIX001", # Resolve FIXMEs
"FIX002", # Resolve TODOs
"B028", # No explicit `stacklevel` keyword argument found in warning
# No docstrings required in the following cases
"D100", # Missing module docstring
"D104", # Missing public package docstring
"D105", # Missing docstring in magic method
"D107", # Missing docstring in `__init__`
]
pydocstyle.convention = "google"

# Allow autofix for all enabled rules (when `--fix`) is provided.
fixable = ["A", "B", "C", "D", "E", "F", "I"]
unfixable = []

per-file-ignores = {}


# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
fixable = ["ALL"]
unfixable = ["F401"] # unused imports (should not disappear while editing)
extend-safe-fixes = [
"D415", # First line should end with a period, question mark, or exclamation point
"D300", # Use triple double quotes `"""`
"D200", # One-line docstring should fit on one line
"TCH", # Format type checking only imports
"ISC001", # Implicitly concatenated strings on a single line
"EM", # Exception message variables
"RUF013", # Implicit Optional
"B006", # Mutable default argument
]

[tool.ruff.lint.per-file-ignores]
"tests/*" = [
"S101", # Use of `assert` detected
"PT011", # pytest-raises-too-broad
"ANN001", # Missing function argument type
"ANN201", # Missing return type
"D103", # Missing function docstring
"ANN401", # Function arguments annotated with too generic `Any` type
"SLF001", # Private member access
]
"docs/conf.py" = [
"INP001", # Add __init__.py to implicit namespace package
"ERA001", # Commented-out code
"A001", # Shadowing Python builtin name, specifically `copyright`
]

[tool.ruff.lint.isort]
known-first-party = ["{{ cookiecutter.package_name }}"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


# FIXME: put actual code here
def hello(name):
def hello(name: str) -> str:
"""Say hello.
Function docstring using Google docstring style.
Expand Down

0 comments on commit a50915a

Please sign in to comment.