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

Add pre-commit with ruff, and other checks (EOL, trailing whitespace) #102

Merged
merged 1 commit into from
Dec 18, 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
53 changes: 14 additions & 39 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@ env:
LATEST_PY_VERSION: '3.11'

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.*
- name: pre-commit checks
shell: bash
run: |
python -m pip install --upgrade pip
python -m pip install pre-commit
pre-commit run --show-diff-on-failure --all-files

tests:
runs-on: ubuntu-latest
strategy:
Expand Down Expand Up @@ -41,42 +55,3 @@ jobs:
files: ./coverage.xml
flags: unittests
fail_ci_if_error: false

lint:
needs: tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.LATEST_PY_VERSION }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pydocstyle

- name: Run lint
run: |
flake8 --ignore=E501,W503
python -m pydocstyle affine

typing:
needs: tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.LATEST_PY_VERSION }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install mypy pytest

- name: Run typing test
run: |
mypy affine
21 changes: 21 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
ci:
autoupdate_schedule: quarterly
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.4
hooks:
# Run the linter.
- id: ruff
args: [ --fix ]
# Run the formatter.
- id: ruff-format
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.11.2
hooks:
- id: mypy
2 changes: 1 addition & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Bug fixes:

2.0b2 (2016-05-16)
------------------
- Bug fix: restore ``Affine __rmul__`` even though it permits dubious
- Bug fix: restore ``Affine __rmul__`` even though it permits dubious
vector * matrix expressions (#27).

2.0b1 (2016-05-16)
Expand Down
1 change: 0 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,3 @@ The reverse transformation is obtained using the ``~`` operator.
>>> rev = ~fwd
>>> rev * fwd * (col, row)
(0.0, 99.99999999999999)

6 changes: 3 additions & 3 deletions affine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,10 +341,10 @@ def _scaling(self):
# The singular values are the square root of the eigenvalues
# of the matrix times its transpose, M M*
# Computing trace and determinant of M M*
trace = a ** 2 + b ** 2 + d ** 2 + e ** 2
trace = a**2 + b**2 + d**2 + e**2
det = (a * e - b * d) ** 2

delta = trace ** 2 / 4 - det
delta = trace**2 / 4 - det
if delta < 1e-12:
delta = 0

Expand All @@ -362,7 +362,7 @@ def eccentricity(self) -> float:
Raises NotImplementedError for improper transformations.
"""
l1, l2 = self._scaling
return math.sqrt(l1 ** 2 - l2 ** 2) / l1
return math.sqrt(l1**2 - l2**2) / l1

@property
def rotation_angle(self) -> float:
Expand Down
1 change: 0 additions & 1 deletion affine/tests/test_pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Validate that instances of `affine.Affine()` can be pickled and unpickled.
"""


import pickle
from multiprocessing import Pool

Expand Down
36 changes: 18 additions & 18 deletions docs/src/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,45 @@

import sys

sys.path.append(os.path.abspath('../..'))
sys.path.append(os.path.abspath("../.."))

# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

project = 'rasterio/affine'
copyright = '2023, Sean Gillies'
author = 'Sean Gillies'
release = 'development'
project = "rasterio/affine"
copyright = "2023, Sean Gillies"
author = "Sean Gillies"
release = "development"

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.coverage',
'sphinx.ext.ifconfig',
'sphinx.ext.viewcode',
'sphinx.ext.githubpages',
"sphinx.ext.autodoc",
"sphinx.ext.coverage",
"sphinx.ext.ifconfig",
"sphinx.ext.viewcode",
"sphinx.ext.githubpages",
]

templates_path = ['_templates']
exclude_patterns = ['Thumbs.db', '.DS_Store']
templates_path = ["_templates"]
exclude_patterns = ["Thumbs.db", ".DS_Store"]

# The suffix of source filenames.
source_suffix = '.rst'
source_suffix = ".rst"

# The root toctree document.
root_doc = 'index'
root_doc = "index"

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
pygments_style = "sphinx"

# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

html_theme = 'nature'
html_theme = "nature"

html_static_path = ['_static']
html_static_path = ["_static"]

# If this is not None, a ‘Last updated on:’ timestamp is inserted at every page bottom.
html_last_updated_fmt = ''
html_last_updated_fmt = ""
16 changes: 14 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ test = [
"pytest-cov",
]
dev = [
"pydocstyle",
"flake8",
"coveralls",
]

Expand All @@ -42,3 +40,17 @@ include = [
"CHANGES.txt",
"LICENSE.txt",
]

[tool.ruff.lint]
select = [
"D1", # pydocstyle
"E", # pycodestyle
"F", # Pyflakes
]
ignore = [
"D105", # Missing docstring in magic method
]

[tool.ruff.lint.per-file-ignores]
"affine/tests/**.py" = ["D"]
"docs/**.py" = ["D"]
6 changes: 0 additions & 6 deletions setup.cfg

This file was deleted.

Loading