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

py: switch to use Ruff for linting and formatting #174

Merged
merged 2 commits into from
Nov 27, 2023
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
13 changes: 0 additions & 13 deletions .flake8

This file was deleted.

13 changes: 5 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,15 @@ jobs:
python -m pip install --upgrade pip
pip install -r lint_requirements.txt
pip install -e .
- name: Isort
run: |
isort py -cv
- name: Black
- name: Formatting
if: always()
run: |
black py --check
- name: Flake8
ruff format py --check
- name: Linting
if: always()
run: |
flake8 py
- name: Run Mypy
ruff py
- name: Typing
if: always()
# We test twice to ensure the type annotations are properly installed
run: |
Expand Down
74 changes: 43 additions & 31 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,36 +146,7 @@ jobs:
name: artifact
path: dist/*.whl

release_upload:
name: Create Release and Upload Release Asset
runs-on: ubuntu-latest
if: github.event_name == 'push'
needs: [build_wheels, build_sdist]
steps:
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: ${{ contains(github.ref, 'rc') || contains(github.ref, 'a') || contains(github.ref, 'b')}}
- uses: actions/download-artifact@v3
with:
name: artifact
path: dist
- name: Upload Release Asset
id: upload-release-asset
uses: shogo82148/actions-upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: dist/*

upload_pypi:
publish:
if: github.event_name == 'push'
needs: [build_wheels, build_sdist]
runs-on: ubuntu-latest
Expand All @@ -185,9 +156,50 @@ jobs:
name: artifact
path: dist

- uses: pypa/gh-action-pypi-publish@master
- uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.pypi_password }}
# To test:
# repository_url: https://test.pypi.org/legacy/

github-release:
name: >-
Sign the Python 🐍 distribution 📦 with Sigstore
and create a GitHub Release
runs-on: ubuntu-latest
needs:
- publish

permissions:
contents: write
id-token: write

steps:
- name: Download all the dists
uses: actions/download-artifact@v3
with:
name: artifact
path: dist
- name: Sign the dists with Sigstore
uses: sigstore/gh-action-sigstore-python@v2.1.0
with:
password: ${{ secrets.pypi_password }}
inputs: >-
./dist/*.tar.gz
./dist/*.whl
- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
run: >-
gh release create
'${{ github.ref_name }}'
--repo '${{ github.repository }}'
--generate-notes
- name: Upload artifact signatures to GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
run: >-
gh release upload
'${{ github.ref_name }}' dist/**
--repo '${{ github.repository }}'
22 changes: 9 additions & 13 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
repos:
- repo: https://github.com/pre-commit/mirrors-isort
rev: v5.10.1
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: main
hooks:
- id: black
- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.2
hooks:
- id: flake8
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.1.6
hooks:
# Run the linter.
- id: ruff
# Run the formatter.
- id: ruff-format
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.910
rev: v1.7.1
hooks:
- id: mypy
additional_dependencies: []
4 changes: 1 addition & 3 deletions lint_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
black
flake8
isort
ruff
mypy
# Allow to lint tests using mypy
pytest
4 changes: 2 additions & 2 deletions py/kiwisolver/_cext.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class Term:

__hash__: None # type: ignore
def __init__(
self, variable: Variable, coefficient: int | float = 1.0, / # noqa
self, variable: Variable, coefficient: int | float = 1.0, /
) -> None: ...
def coefficient(self) -> float:
"""Get the coefficient for the term."""
Expand Down Expand Up @@ -112,7 +112,7 @@ class Expression:

__hash__: None # type: ignore
def __init__(
self, terms: Iterable[Term], constant: int | float = 0.0, / # noqa
self, terms: Iterable[Term], constant: int | float = 0.0, /
) -> None: ...
def constant(self) -> float:
"" "Get the constant for the expression." ""
Expand Down
6 changes: 3 additions & 3 deletions py/tests/test_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ def test_variable_methods() -> None:
"""Test the variable modification methods."""
v = Variable()
assert v.name() == ""
v.setName("γ")
assert v.name() == "γ"
v.setName("Δ")
assert v.name() == "Δ"
v.setName("foo")
assert v.name() == "foo"
with pytest.raises(TypeError):
Expand Down Expand Up @@ -139,7 +139,7 @@ def test_variable_sub() -> None:
def test_variable_rich_compare_operations() -> None:
"""Test using comparison on variables."""
v = Variable("foo")
v2 = Variable("γ")
v2 = Variable("Δ")

for op, symbol in ((operator.le, "<="), (operator.eq, "=="), (operator.ge, ">=")):
c = op(v, v2 + 1)
Expand Down
23 changes: 13 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,19 @@ write_to_template = """

"""

[tool.black]
line-length = 88 # Enforce the default value
[tool.ruff]
src = ["src"]
select = ["C", "E", "F", "W", "I", "C90", "RUF"]
extend-exclude = ["tests/instruments/hardware/nifpga/scope_based"]
extend-ignore = ["E501", "RUF012"]
line-length = 88

[tool.ruff.isort]
combine-as-imports = true
known-first-party = ["kiwisolver"]

[tool.ruff.mccabe]
max-complexity = 20

[tool.pytest.ini_options]
minversion = "6.0"
Expand All @@ -80,11 +91,3 @@ minversion = "6.0"
follow_imports = "normal"
strict_optional = true

[tool.isort]
multi_line_output = 3
include_trailing_comma = true
combine_as_imports = true
force_grid_wrap = 0
use_parentheses = true
line_length = 88
known_first_party = "kiwisolver"