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

GEOPY-1362: replace black and a few linters with Ruff #21

Merged
merged 4 commits into from
May 31, 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
5 changes: 0 additions & 5 deletions .flake8

This file was deleted.

33 changes: 12 additions & 21 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,20 @@ ci:
autoupdate_schedule: monthly

repos:
- repo: https://github.com/psf/black
rev: 23.10.0
- repo: https://github.com/hadialqattan/pycln
rev: v2.4.0
hooks:
- id: black
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
- id: pycln
args: [ --config=pyproject.toml ]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.4
hooks:
- id: isort
additional_dependencies: [tomli] # to read config from pyproject.toml
- repo: https://github.com/humitos/mirrors-autoflake
rev: v1.1
hooks:
- id: autoflake
- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
hooks:
- id: flake8
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
hooks:
- id: pyupgrade
args: [--py39-plus]
# exclude: plates
- id: ruff
args:
- --fix
- --exit-non-zero-on-fix
# - --unsafe-fixes
- id: ruff-format
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.6.1
hooks:
Expand Down
1 change: 1 addition & 0 deletions devtools/add_url_tag_sha256.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from pathlib import Path
from urllib import request


_url_filename_re = re.compile(".*/([^/]*)")


Expand Down
1 change: 1 addition & 0 deletions devtools/check-copyright.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import sys
from datetime import date


if __name__ == "__main__":
current_year = date.today().year
copyright_re = re.compile(
Expand Down
12 changes: 5 additions & 7 deletions devtools/git_message_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ def check_commit_message(filepath: str) -> tuple[bool, str]:
if branch_jira_id and message_jira_id and branch_jira_id != message_jira_id:
return (
False,
"Different JIRA ID in commit message %s and in branch name %s."
% (message_jira_id, branch_jira_id),
f"Different JIRA ID in commit message {message_jira_id} and in branch name {branch_jira_id}.",
)

stripped_message_line = ""
Expand All @@ -140,8 +139,8 @@ def check_commit_message(filepath: str) -> tuple[bool, str]:
if len(stripped_message_line) < min_required_length:
return (
False,
"First line of commit message must be at least %s characters long, "
"beyond the JIRA ID." % min_required_length,
f"First line of commit message must be at least {min_required_length} characters long, "
"beyond the JIRA ID.",
)

return True, ""
Expand All @@ -156,9 +155,8 @@ def check_commit_msg(filepath: str) -> None:
(is_valid, error_message) = check_commit_message(filepath)
if not is_valid:
print(
"""commit-msg hook: **ERROR** %s
Message has been saved to %s."""
% (error_message, filepath)
f"""commit-msg hook: **ERROR** {error_message}
Message has been saved to {filepath}."""
)
sys.exit(1)

Expand Down
1 change: 1 addition & 0 deletions devtools/rename_my_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import subprocess
from pathlib import Path


logger = logging.getLogger(__name__)

THIS_FILE = Path(__file__).resolve()
Expand Down
15 changes: 9 additions & 6 deletions devtools/run_conda_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from add_url_tag_sha256 import patch_pyproject_toml
from ruamel.yaml import YAML


env_file_variables_section_ = """
variables:
KMP_WARNINGS: 0
Expand Down Expand Up @@ -167,9 +168,10 @@ def patch_none_hash(self) -> None:
)
with tempfile.TemporaryDirectory(dir=str(self.lock_file.parent)) as tmpdirname:
patched_file = Path(tmpdirname) / self.lock_file.name
with open(patched_file, mode="w", encoding="utf-8") as patched, open(
self.lock_file, encoding="utf-8"
) as f:
with (
open(patched_file, mode="w", encoding="utf-8") as patched,
open(self.lock_file, encoding="utf-8") as f,
):
for line in f:
match = none_hash_re.match(line)
if not match:
Expand Down Expand Up @@ -202,9 +204,10 @@ def remove_pip_hashes(self) -> None:

with tempfile.TemporaryDirectory(dir=str(self.lock_file.parent)) as tmpdirname:
patched_file = Path(tmpdirname) / self.lock_file.name
with open(patched_file, mode="w", encoding="utf-8") as patched, open(
self.lock_file, encoding="utf-8"
) as f:
with (
open(patched_file, mode="w", encoding="utf-8") as patched,
open(self.lock_file, encoding="utf-8") as f,
):
for line in f:
patched_line = self.sha_re.sub(r"\1", line)
patched.write(patched_line)
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

project = "plate-simulation"
copyright = "2024, Benjamin Kary"
project_copyright = "2024, Mira Geoscience"
author = "Benjamin Kary"
release = "2024"

Expand Down
1 change: 1 addition & 0 deletions plate_simulation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from pathlib import Path


__version__ = "0.1.0-alpha.1"


Expand Down
2 changes: 1 addition & 1 deletion plate_simulation/mesh/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def octree_params(
"Refinement B levels": "4, 2",
"Refinement B type": "radial",
}
for plate, letter in zip(plates, string.ascii_uppercase[2:]):
for plate, letter in zip(plates, string.ascii_uppercase[2:], strict=False):
refinements.update(
{
f"Refinement {letter} object": plate,
Expand Down
1 change: 1 addition & 0 deletions plate_simulation/models/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from trimesh import Trimesh
from trimesh.proximity import ProximityQuery


# pylint: disable=too-few-public-methods


Expand Down
3 changes: 2 additions & 1 deletion plate_simulation/models/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
model_validator,
)


T = TypeVar("T")


Expand Down Expand Up @@ -101,7 +102,7 @@ def center(
:param surface: surface object to reference plate depth from.
:param depth_offset: Additional offset to be added to the depth of the plate.
"""
return self._get_xy(survey) + [self._get_z(surface, depth_offset)]
return [*self._get_xy(survey), self._get_z(surface, depth_offset)]
sebhmg marked this conversation as resolved.
Show resolved Hide resolved

def _get_xy(self, survey: ObjectBase) -> list[float]:
"""Return true or relative locations in x and y."""
Expand Down
1 change: 1 addition & 0 deletions plate_simulation/models/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

from .events import Anomaly, Erosion, Overburden


if TYPE_CHECKING:
from .events import Deposition, Event

Expand Down
1 change: 1 addition & 0 deletions plate_simulation/simulations/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from simpeg_drivers.params import InversionBaseParams
from simpeg_drivers.potential_fields.gravity.params import GravityParams


# pylint: disable=import-outside-toplevel, too-few-public-methods


Expand Down
44 changes: 34 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,40 @@ readthedocs-sphinx-ext = "*"
platforms = ['win-64', 'linux-64']
channels = ['conda-forge']

[tool.isort]
# settings for compatibility between ``isort`` and ``black`` formatting
multi_line_output = 3
include_trailing_comma = true
force_grid_wrap = 0
use_parentheses = true
line_length = 88

[tool.black]
# defaults are just fine
[tool.ruff]
target-version = "py310"

[tool.ruff.lint]
ignore = [
"B028", # no-explicit-stacklevel for warnings.warn()
"E501", # line-too-long - code is reformatted (do not care about comments and docstring)
"F401", # unsused-import - covered by pycln
]
select = [
"A", # flake8-builtins
"B", # flake8-bugbear
"B006", # Do not use mutable data structures for argument defaults
"B9", # flake8-bugbear opiniated warnings
"BLE", # flake8-blind-except
"C4", # flake8-comprehensions
"C9", # mccabe
"E", # pycodestyle errors
"F", # pyflakes
"I", # isort
"RUF", # ruff rules
"TID", # flake8-tidy-imports
"UP", # pyupgrade
"W", # pycodestyle warnings
]

[tool.ruff.lint.mccabe]
max-complexity = 18

[tool.ruff.lint.isort]
lines-after-imports = 2

[tool.ruff.format]
# default formatting is just fine

[tool.mypy]
warn_unused_configs = true
Expand Down
2 changes: 1 addition & 1 deletion tests/assets_path_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ def test_assets_directory_exist():

def test_uijson_files_exists():
assert (assets_path() / "uijson").is_dir()
assert list((assets_path() / "uijson").iterdir())[0].is_file()
assert next(iter((assets_path() / "uijson").iterdir())).is_file()
3 changes: 2 additions & 1 deletion tests/runtest/driver_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

from . import get_survey, get_topography


# pylint: disable=duplicate-code


Expand Down Expand Up @@ -112,7 +113,7 @@ def test_plate_simulation(tmp_path):
with Workspace(result.options["geoh5"]) as ws:
data = ws.get_entity(result.options["data_object"]["value"].uid)[0]
mesh = ws.get_entity(result.options["mesh"]["value"].uid)[0]
model = [k for k in mesh.children if k.name == "starting_model"][0]
model = next(k for k in mesh.children if k.name == "starting_model")

assert len(data.property_groups) == 3
assert all(
Expand Down
Loading