Skip to content

Ruff improvements #392

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

Merged
merged 4 commits into from
Jul 24, 2025
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
7 changes: 2 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ jobs:
run: |
python -m ruff check src/gstools/

- name: ruff import check
run: |
python -m ruff check --select I --diff src/gstools/

- name: ruff format check
run: |
python -m ruff format --diff src/gstools/
Expand All @@ -58,7 +54,8 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, ubuntu-24.04-arm, windows-latest, macos-13, macos-14]
os:
[ubuntu-latest, ubuntu-24.04-arm, windows-latest, macos-13, macos-14]
# https://github.com/scipy/oldest-supported-numpy/blob/main/setup.cfg
ver:
- { py: "3.8", np: "==1.20.0", sp: "==1.5.4" }
Expand Down
61 changes: 1 addition & 60 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,68 +30,9 @@ with your idea or suggestion and we'd love to discuss about it.
- Fork the repo on [GitHub](https://github.com/GeoStat-Framework/GSTools)
- Add yourself to AUTHORS.md (if you want to).
- We use [Ruff](https://github.com/psf/black) to check and format the code.
Please use the scripts `ruff check src/gstools`,
`ruff check --select I --fix src/gstools/`, and
Please use the scripts `ruff check src/gstools` and
`ruff format --diff src/gstools/` after you have written your code.
- Add some tests if possible.
- Add an example showing your new feature in one of the examples sub-folders if possible.
Follow this [Sphinx-Gallary guide](https://sphinx-gallery.github.io/stable/syntax.html#embed-rst-in-your-example-python-files).
- Push to your fork and submit a pull request.

### PyLint Settings

Your code will be checked by [Pylint](https://github.com/PyCQA/pylint/)
with `pylint gstools` in the CI.
We made some generous default settings in `pyproject.toml` for the linter:

- max-args = 20
- max-locals = 50
- max-branches = 30
- max-statements = 80
- max-attributes = 25
- max-public-methods = 75

Since some classes in GSTools are quite huge and some function signatures are
somewhat longish.

By default [R0801](https://vald-phoenix.github.io/pylint-errors/plerr/errors/similarities/R0801)
(duplicate-code) is disabled, since it produces a lot of false positive errors
for docstrings and `__init__.py` settings.

We also disabled some pylint checks for some files by setting
comments like these at the beginning:
```python
# pylint: disable=C0103
```

Here is a list of the occurring disabled errors:
- [C0103](https://vald-phoenix.github.io/pylint-errors/plerr/errors/basic/C0103)
(invalid-name) - `ax`, `r` etc. are marked as no valid names
- [C0302](https://vald-phoenix.github.io/pylint-errors/plerr/errors/format/C0302)
(too-many-lines) - namely the `CovModel` definition has more than 1000 lines
- [C0415](https://vald-phoenix.github.io/pylint-errors/plerr/errors/imports/C0415)
(import-outside-toplevel) - needed sometimes for deferred imports of optional
dependencies like `matplotlib`
- [R0201](https://vald-phoenix.github.io/pylint-errors/plerr/errors/classes/R0201)
(no-self-use) - methods with no `self` calls in some base-classes
- [W0212](https://vald-phoenix.github.io/pylint-errors/plerr/errors/classes/W0212)
(protected-access) - we didn't want to draw attention to `CovModel._prec`
- [W0221](https://vald-phoenix.github.io/pylint-errors/plerr/errors/classes/W0221)
(arguments-differ) - the `__call__` methods of `SRF` and `Krige` differ from `Field`
- [W0222](https://vald-phoenix.github.io/pylint-errors/plerr/errors/classes/W0222)
(signature-differ) - the `__call__` methods of `SRF` and `Krige` differ from `Field`
- [W0231](https://vald-phoenix.github.io/pylint-errors/plerr/errors/classes/W0231)
(super-init-not-called) - some child classes have their specialized `__init__`
- [W0613](https://vald-phoenix.github.io/pylint-errors/plerr/errors/variables/W0613)
(unused-argument) - needed sometimes to match required call signatures
- [W0632](https://vald-phoenix.github.io/pylint-errors/plerr/errors/variables/W0632)
(unbalanced-tuple-unpacking) - false positive for some call returns
- [E1101](https://vald-phoenix.github.io/pylint-errors/plerr/errors/typecheck/E1101)
(no-member) - some times false positive
- [E1102](https://vald-phoenix.github.io/pylint-errors/plerr/errors/typecheck/E1102)
(not-callable) - this is a false-positive result form some called properties
- [E1130](https://vald-phoenix.github.io/pylint-errors/plerr/errors/typecheck/E1130)
(invalid-unary-operand-type) - false positive at some points

Although we disabled these errors at some points, we encourage you to prevent
disabling errors when it is possible.
10 changes: 2 additions & 8 deletions examples/11_plurigaussian/02_spatial_relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,12 @@
for i in range(4):
lithotypes[
M[0] // 2 + S1[0] : M[0] // 2 + S1[0] + rect[0],
M[1] // 2
+ S1[1]
+ rect[1]
+ 3
+ 2 * i : M[1] // 2
M[1] // 2 + S1[1] + rect[1] + 3 + 2 * i : M[1] // 2
+ S1[1]
+ rect[1]
+ 4
+ 2 * i,
] = (
4 + i
)
] = 4 + i

###############################################################################
# With the two SRFs and the L-field ready, we can create the PGS.
Expand Down
1 change: 0 additions & 1 deletion examples/11_plurigaussian/04_3d_pgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"""

# sphinx_gallery_thumbnail_path = 'pics/3d_pgs.png'
import matplotlib.pyplot as plt
import numpy as np

import gstools as gs
Expand Down
49 changes: 21 additions & 28 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@


[build-system]
requires = [
"hatchling>=1.8.0",
"hatch-vcs",
]
requires = ["hatchling>=1.8.0", "hatch-vcs"]
build-backend = "hatchling.build"

[project]
requires-python = ">=3.8"
name = "gstools"
description = "GSTools: A geostatistical toolbox."
authors = [
{name = "Sebastian Müller, Lennart Schüler", email = "info@geostat-framework.org"},
{ name = "Sebastian Müller, Lennart Schüler", email = "info@geostat-framework.org" },
]
readme = "README.md"
license = "LGPL-3.0"
Expand Down Expand Up @@ -67,10 +64,7 @@ doc = [
"sphinx-rtd-theme>=3",
"sphinxcontrib-youtube>=1.1",
]
plotting = [
"matplotlib>=3.7",
"pyvista>=0.40",
]
plotting = ["matplotlib>=3.7", "pyvista>=0.40"]
rust = ["gstools_core>=1.0.0"]
test = ["pytest-cov>=3"]
lint = ["ruff"]
Expand All @@ -95,10 +89,7 @@ version-file = "src/gstools/_version.py"
template = "__version__ = '{version}'"

[tool.hatch.build.targets.sdist]
include = [
"/src",
"/tests",
]
include = ["/src", "/tests"]

[tool.hatch.build.targets.wheel]
packages = ["src/gstools"]
Expand All @@ -107,20 +98,22 @@ packages = ["src/gstools"]
line-length = 79
target-version = "py38"

[tool.ruff.lint]
select = [
"F",
"I",
]

[tool.coverage]
[tool.coverage.run]
source = ["gstools"]
omit = [
"*docs*",
"*examples*",
"*tests*",
"*/src/gstools/covmodel/plot.py",
"*/src/gstools/field/plot.py",
]
[tool.coverage.run]
source = ["gstools"]
omit = [
"*docs*",
"*examples*",
"*tests*",
"*/src/gstools/covmodel/plot.py",
"*/src/gstools/field/plot.py",
]

[tool.coverage.report]
exclude_lines = [
"pragma: no cover",
"def __repr__",
"def __str__",
]
[tool.coverage.report]
exclude_lines = ["pragma: no cover", "def __repr__", "def __str__"]
6 changes: 3 additions & 3 deletions tests/test_rng.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
import unittest

import numpy as np
from scipy.stats import kurtosis, normaltest, skew

from gstools import Gaussian, TPLStable
from gstools import Gaussian
from gstools.random.rng import RNG


Expand Down Expand Up @@ -100,7 +99,8 @@ def test_sample_dist(self):

# TODO test with different models

# TODO rework this
# TODO rework this, needs
# from scipy.stats import kurtosis, normaltest, skew
# def test_gau(self):
# for d in range(len(self.rngs)):
# Z, k = self.rngs[d]('gau', self.len_scale, self.many_modes)
Expand Down
1 change: 0 additions & 1 deletion tests/test_srf.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import numpy as np

import gstools as gs
from gstools import transform as tf

HAS_PYVISTA = False
try:
Expand Down