Skip to content

Commit 6eb17a7

Browse files
authored
Add back pre-commit job for mypy type-checking (aiidateam#6827)
The pre-commit hook cannot install dependencies therefore the mypy hook (and others) were skipped in it. We reintroduce the pre-commit CI job to run these hooks on the CI.
1 parent 936185b commit 6eb17a7

File tree

7 files changed

+46
-11
lines changed

7 files changed

+46
-11
lines changed

.github/workflows/pre-commit.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: pre-commit
2+
# NOTE: This job is not duplicating pre-commit.ci job,
3+
# since that once skips running mypy type-checking\
4+
# due to technical limitations of pre-commit.ci runners.
5+
6+
on:
7+
push:
8+
branches-ignore: [gh-pages]
9+
pull_request:
10+
branches-ignore: [gh-pages]
11+
12+
env:
13+
FORCE_COLOR: 1
14+
15+
jobs:
16+
17+
pre-commit:
18+
19+
runs-on: ubuntu-24.04
20+
timeout-minutes: 15
21+
22+
steps:
23+
- uses: actions/checkout@v4
24+
25+
- name: Install python dependencies
26+
uses: ./.github/actions/install-aiida-core
27+
with:
28+
python-version: '3.11'
29+
from-lock: 'true'
30+
31+
- name: Run pre-commit
32+
run: pre-commit run --all-files || ( git status --short ; git diff ; exit 1 )

.pre-commit-config.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,8 @@ repos:
201201
files: >-
202202
(?x)^(
203203
pyproject.toml|
204-
utils/dependency_management.py
204+
utils/dependency_management.py|
205+
environment.yml|
205206
)$
206207
207208
- id: validate-conda-environment

docs/source/reference/command_line.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ Below is a list with all available subcommands.
451451
--broker-host HOSTNAME Hostname for the message broker. [default: 127.0.0.1]
452452
--broker-port INTEGER Port for the message broker. [default: 5672]
453453
--broker-virtual-host TEXT Name of the virtual host for the message broker without
454-
leading forward slash.
454+
leading forward slash. [default: ""]
455455
--repository DIRECTORY Absolute path to the file repository.
456456
--test-profile Designate the profile to be used for running the test
457457
suite only.

environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ dependencies:
3737
- typing-extensions~=4.0
3838
- upf_to_json~=0.9.2
3939
- wrapt~=1.11
40-
- chardet~=5.2.0 # [win]
40+
- chardet~=5.2.0

src/aiida/orm/nodes/data/code/portable.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class Model(AbstractCode.Model):
6363
description='Relative filepath of executable with directory of code files.',
6464
short_name='-X',
6565
priority=1,
66-
orm_to_model=lambda node, _: str(node.filepath_executable),
66+
orm_to_model=lambda node, _: str(node.filepath_executable), # type: ignore[attr-defined]
6767
)
6868
filepath_files: str = MetadataField(
6969
...,
@@ -72,7 +72,7 @@ class Model(AbstractCode.Model):
7272
short_name='-F',
7373
is_attribute=False,
7474
priority=2,
75-
orm_to_model=_export_filpath_files_from_repo,
75+
orm_to_model=_export_filpath_files_from_repo, # type: ignore[arg-type]
7676
)
7777

7878
def __init__(
@@ -104,7 +104,7 @@ def __init__(
104104
if not filepath_files_path.is_dir():
105105
raise ValueError(f'The filepath `{filepath_files}` is not a directory.')
106106

107-
self.filepath_executable = filepath_executable
107+
self.filepath_executable = filepath_executable # type: ignore[assignment] # should be fixed in mypy 1.15 see mypy/commit/1eb9d4c
108108
self.base.repository.put_object_from_tree(str(filepath_files))
109109

110110
def _validate(self):

src/aiida/orm/nodes/node.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
import base64
1414
import datetime
1515
from functools import cached_property
16-
from logging import Logger
1716
from typing import TYPE_CHECKING, Any, ClassVar, Dict, Generic, Iterator, List, Optional, Tuple, Type, TypeVar
1817
from uuid import UUID
1918

2019
from aiida.common import exceptions
2120
from aiida.common.lang import classproperty, type_check
2221
from aiida.common.links import LinkType
22+
from aiida.common.log import AIIDA_LOGGER
2323
from aiida.common.pydantic import MetadataField
2424
from aiida.common.warnings import warn_deprecation
2525
from aiida.manage import get_manager
@@ -43,6 +43,8 @@
4343
if TYPE_CHECKING:
4444
from importlib_metadata import EntryPoint
4545

46+
from aiida.common.log import AiidaLoggerType
47+
4648
from ..implementation import StorageBackend
4749
from ..implementation.nodes import BackendNode # noqa: F401
4850
from .repository import NodeRepository
@@ -174,8 +176,8 @@ def _query_type_string(cls) -> str: # noqa: N805
174176
cls.__query_type_string = get_query_type_from_type_string(cls._plugin_type_string) # type: ignore[misc]
175177
return cls.__query_type_string
176178

177-
# This will be set by the metaclass call
178-
_logger: Optional[Logger] = None
179+
# This will be set by the metaclass call but we set default
180+
_logger: AiidaLoggerType = AIIDA_LOGGER
179181

180182
# A tuple of attribute names that can be updated even after node is stored
181183
# Requires Sealable mixin, but needs empty tuple for base class
@@ -407,7 +409,7 @@ def entry_point(cls) -> Optional['EntryPoint']: # noqa: N805
407409
return get_entry_point_from_class(cls.__module__, cls.__name__)[1]
408410

409411
@property
410-
def logger(self) -> Optional[Logger]:
412+
def logger(self) -> Optional[AiidaLoggerType]:
411413
"""Return the logger configured for this Node.
412414
413415
:return: Logger object

src/aiida/storage/sqlite_zip/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def _json_contains(lhs: Union[str, bytes, bytearray, dict, list], rhs: Union[str
7272
rhs = json.loads(rhs)
7373
except json.JSONDecodeError:
7474
return 0
75-
return int(_contains(lhs, rhs))
75+
return int(_contains(lhs, rhs)) # type: ignore[arg-type]
7676

7777

7878
def register_json_contains(dbapi_connection, _):

0 commit comments

Comments
 (0)