From 0a5814d8ef04775924c5f15c479188ee1d234150 Mon Sep 17 00:00:00 2001
From: Antoine Lambert <anlambert@softwareheritage.org>
Date: Fri, 14 Feb 2025 15:13:29 +0100
Subject: [PATCH 1/2] Apply swh-py-template v0.3.3 with copier

Bump development tools: mypy, codespell, isort, ...

Move all tools configuration in pyproject.toml.

Remove no longer needed mypy overrides.
---
 .copier-answers.yml     |  2 +-
 .pre-commit-config.yaml | 14 +++++++-------
 mypy.ini                | 13 -------------
 pyproject.toml          | 37 +++++++++++++++++++++++++++++++++++++
 pytest.ini              | 12 ------------
 setup.cfg               |  8 --------
 tox.ini                 |  8 +++++---
 7 files changed, 50 insertions(+), 44 deletions(-)
 delete mode 100644 mypy.ini
 delete mode 100644 pytest.ini
 delete mode 100644 setup.cfg

diff --git a/.copier-answers.yml b/.copier-answers.yml
index 142939a7..7b97e9ff 100644
--- a/.copier-answers.yml
+++ b/.copier-answers.yml
@@ -1,5 +1,5 @@
 # Changes here will be overwritten by Copier
-_commit: v0.2.3
+_commit: v0.3.3
 _src_path: https://gitlab.softwareheritage.org/swh/devel/swh-py-template.git
 description: Software Heritage data model
 distribution_name: swh-model
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index a8b70933..5df993fa 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -1,18 +1,18 @@
 repos:
   - repo: https://github.com/pre-commit/pre-commit-hooks
-    rev: v4.6.0
+    rev: v5.0.0
     hooks:
       - id: trailing-whitespace
       - id: check-json
       - id: check-yaml
 
   - repo: https://github.com/python/black
-    rev: 24.8.0
+    rev: 25.1.0
     hooks:
       - id: black
 
   - repo: https://github.com/PyCQA/isort
-    rev: 5.13.2
+    rev: 6.0.0
     hooks:
       - id: isort
 
@@ -20,15 +20,15 @@ repos:
     rev: 7.1.1
     hooks:
       - id: flake8
-        additional_dependencies: [flake8-bugbear==24.4.26]
+        additional_dependencies: [flake8-bugbear==24.12.12, flake8-pyproject]
 
   - repo: https://github.com/codespell-project/codespell
-    rev: v2.3.0
+    rev: v2.4.1
     hooks:
       - id: codespell
         name: Check source code spelling
-        stages: [commit]
-        args: [-L assertIn]
+        stages: [pre-commit]
+        args: [-L assertIn, -L anc]
       - id: codespell
         name: Check commit message spelling
         stages: [commit-msg]
diff --git a/mypy.ini b/mypy.ini
deleted file mode 100644
index 2f09ec12..00000000
--- a/mypy.ini
+++ /dev/null
@@ -1,13 +0,0 @@
-[mypy]
-namespace_packages = True
-warn_unused_ignores = True
-explicit_package_bases = True
-# ^ Needed for mypy to detect py.typed from swh packages installed
-# in editable mode
-
-# 3rd party libraries without stubs (yet)
-[mypy-pkg_resources.*]
-ignore_missing_imports = True
-
-# [mypy-add_your_lib_here.*]
-# ignore_missing_imports = True
diff --git a/pyproject.toml b/pyproject.toml
index 5f4640e4..751ebbec 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -59,3 +59,40 @@ ensure_newline_before_comments = true
 line_length = 88
 force_sort_within_sections = true
 known_first_party = ['swh']
+
+[tool.mypy]
+namespace_packages = true
+warn_unused_ignores = true
+explicit_package_bases = true
+# ^ Needed for mypy to detect py.typed from swh packages installed
+# in editable mode
+
+plugins = []
+
+# 3rd party libraries without stubs (yet)
+# [[tool.mypy.overrides]]
+# module = [
+#     "package1.*",
+#     "package2.*",
+# ]
+# ignore_missing_imports = true
+
+[tool.flake8]
+select = ["C", "E", "F", "W", "B950"]
+ignore = [
+    "E203", # whitespaces before ':' <https://github.com/psf/black/issues/315>
+    "E231", # missing whitespace after ','
+    "E501", # line too long, use B950 warning from flake8-bugbear instead
+    "W503" # line break before binary operator <https://github.com/psf/black/issues/52>
+]
+max-line-length = 88
+
+[tool.pytest.ini_options]
+addopts = "--doctest-modules -p no:pytest_swh_core"
+norecursedirs = "build docs .*"
+asyncio_mode = "strict"
+consider_namespace_packages = true
+markers = [
+    "fs: tests that involve filesystem ios",
+    "requires_optional_deps: tests in test_cli.py that should not run if optional dependencies are not installed",
+]
diff --git a/pytest.ini b/pytest.ini
deleted file mode 100644
index 2677d2a7..00000000
--- a/pytest.ini
+++ /dev/null
@@ -1,12 +0,0 @@
-[pytest]
-norecursedirs = build docs .*
-asyncio_mode = strict
-consider_namespace_packages = true
-
-addopts =
-    --doctest-modules
-    -p no:pytest_swh_core
-
-markers =
-    fs: tests that involve filesystem ios
-    requires_optional_deps: tests in test_cli.py that should not run if optional dependencies are not installed
diff --git a/setup.cfg b/setup.cfg
deleted file mode 100644
index adf9af3e..00000000
--- a/setup.cfg
+++ /dev/null
@@ -1,8 +0,0 @@
-[flake8]
-# E203: whitespaces before ':' <https://github.com/psf/black/issues/315>
-# E231: missing whitespace after ','
-# E501: line too long, use B950 warning from flake8-bugbear instead
-# W503: line break before binary operator <https://github.com/psf/black/issues/52>
-select = C,E,F,W,B950
-ignore = E203,E231,E501,E704,W503
-max-line-length = 88
diff --git a/tox.ini b/tox.ini
index 64250fd9..f1980be2 100644
--- a/tox.ini
+++ b/tox.ini
@@ -30,7 +30,7 @@ commands =
 [testenv:black]
 skip_install = true
 deps =
-  black==24.8.0
+  black==25.1.0
 commands =
   {envpython} -m black --check swh
 
@@ -38,8 +38,10 @@ commands =
 skip_install = true
 deps =
   flake8==7.1.1
-  flake8-bugbear==24.4.26
+  flake8-bugbear==24.12.12
+  flake8-pyproject==1.2.3
   pycodestyle==2.12.1
+
 commands =
   {envpython} -m flake8
 
@@ -47,7 +49,7 @@ commands =
 extras =
   testing
 deps =
-  mypy==1.11.1
+  mypy==1.15.0
 commands =
   mypy swh
 
-- 
GitLab


From e021814b6990c7849c39cb5106ca7037351effb8 Mon Sep 17 00:00:00 2001
From: Antoine Lambert <anlambert@softwareheritage.org>
Date: Fri, 14 Feb 2025 15:13:52 +0100
Subject: [PATCH 2/2] git_objects, model, swhids: Fix black formatting

---
 swh/model/git_objects.py | 2 +-
 swh/model/model.py       | 2 +-
 swh/model/swhids.py      | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/swh/model/git_objects.py b/swh/model/git_objects.py
index a1e42939..679011b5 100644
--- a/swh/model/git_objects.py
+++ b/swh/model/git_objects.py
@@ -516,7 +516,7 @@ def snapshot_git_object(
 
 
 def raw_extrinsic_metadata_git_object(
-    metadata: Union[Dict, model.RawExtrinsicMetadata]
+    metadata: Union[Dict, model.RawExtrinsicMetadata],
 ) -> bytes:
     """Formats RawExtrinsicMetadata as a git-like object.
 
diff --git a/swh/model/model.py b/swh/model/model.py
index e6b99a6c..7745e539 100644
--- a/swh/model/model.py
+++ b/swh/model/model.py
@@ -85,7 +85,7 @@ def parents_repr(parents: Tuple[Sha1Git, ...]):
 
 
 def freeze_optional_dict(
-    d: Union[None, Dict, ImmutableDict]
+    d: Union[None, Dict, ImmutableDict],
 ) -> Optional[ImmutableDict]:
     if isinstance(d, dict):
         return ImmutableDict(d)
diff --git a/swh/model/swhids.py b/swh/model/swhids.py
index 6464c8b0..3422d6fa 100644
--- a/swh/model/swhids.py
+++ b/swh/model/swhids.py
@@ -217,7 +217,7 @@ def _parse_core_swhid(swhid: Union[str, CoreSWHID, None]) -> Optional[CoreSWHID]
 
 
 def _parse_lines_qualifier(
-    lines: Union[str, Tuple[int, Optional[int]], None]
+    lines: Union[str, Tuple[int, Optional[int]], None],
 ) -> Optional[Tuple[int, Optional[int]]]:
     try:
         if lines is None or isinstance(lines, tuple):
-- 
GitLab