Skip to content

Commit 8f6e576

Browse files
authored
chore: update precommit (#3187)
1 parent 47fa194 commit 8f6e576

File tree

12 files changed

+330
-280
lines changed

12 files changed

+330
-280
lines changed

.pre-commit-config.yaml

Lines changed: 84 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,85 @@
11
repos:
2-
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v2.3.0
4-
hooks:
5-
- id: check-yaml
6-
- id: end-of-file-fixer
7-
- id: trailing-whitespace
8-
- repo: https://github.com/psf/black
9-
rev: 22.3.0
10-
hooks:
11-
- id: black
12-
additional_dependencies: ["click==8.0.4"]
13-
- repo: https://github.com/pycqa/isort
14-
rev: 5.10.1
15-
hooks:
16-
- id: isort
17-
name: isort (python)
18-
- repo: https://github.com/pycqa/flake8
19-
rev: "6.0.0"
20-
hooks:
21-
- id: flake8
22-
exclude: ^docs/
23-
additional_dependencies:
24-
- Flake8-pyproject==1.2.2
25-
- repo: https://github.com/pycqa/pydocstyle
26-
rev: 4.0.1
27-
hooks:
28-
- id: pydocstyle
29-
args:
30-
- --ignore=D105,D107,D202,D203,D212,D213,D401,D406,D407,D410,D411,D413
31-
- repo: https://github.com/koalaman/shellcheck-precommit
32-
rev: v0.8.0
33-
hooks:
34-
- id: shellcheck
35-
- repo: https://github.com/pre-commit/mirrors-mypy
36-
rev: "v0.990"
37-
hooks:
38-
- id: mypy
39-
args:
40-
- --no-strict-optional
41-
- --ignore-missing-imports
42-
additional_dependencies:
43-
- types-python-dateutil>=2.8.10
44-
- types-PyYAML<6.1.0,>=5.4
45-
- types-redis>=3.5.3,<4.1.0
46-
- types-requests<2.27.2,>=2.23.0
47-
- types-tabulate<0.8.10,>=0.7.7
48-
- attrs<21.5.0,>=21.4.0
49-
- filelock>=3.3.0,<3.6.1
50-
- repo: https://github.com/hadolint/hadolint
51-
rev: master
52-
hooks:
53-
- id: hadolint-docker
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.3.0
4+
hooks:
5+
- id: check-yaml
6+
exclude: ^helm-chart/renku-core/templates
7+
- id: check-added-large-files
8+
- id: check-case-conflict
9+
- id: check-json
10+
- id: check-merge-conflict
11+
- id: check-toml
12+
- id: debug-statements
13+
- id: end-of-file-fixer
14+
types: [python]
15+
- id: mixed-line-ending
16+
- id: trailing-whitespace
17+
- repo: https://github.com/psf/black
18+
rev: 22.10.0
19+
hooks:
20+
- id: black
21+
additional_dependencies: ["click==8.0.4"]
22+
- repo: https://github.com/pycqa/isort
23+
rev: 5.10.1
24+
hooks:
25+
- id: isort
26+
name: isort (python)
27+
- repo: https://github.com/pycqa/flake8
28+
rev: "5.0.4"
29+
hooks:
30+
- id: flake8
31+
exclude: ^docs/
32+
args:
33+
- "--max-line-length=120"
34+
- "--show-source"
35+
- "--ignore=E121,E126,E203,E226,E231,W503,W504"
36+
additional_dependencies:
37+
- Flake8-pyproject==1.2.2
38+
- repo: https://github.com/pycqa/pydocstyle
39+
rev: 6.1.1
40+
hooks:
41+
- id: pydocstyle
42+
args:
43+
- --ignore=D105,D107,D202,D203,D212,D213,D401,D406,D407,D410,D411,D413
44+
- repo: https://github.com/koalaman/shellcheck-precommit
45+
rev: v0.8.0
46+
hooks:
47+
- id: shellcheck
48+
- repo: https://github.com/pre-commit/mirrors-mypy
49+
rev: "v0.990"
50+
hooks:
51+
- id: mypy
52+
args:
53+
- --no-strict-optional
54+
- --ignore-missing-imports
55+
additional_dependencies:
56+
- types-python-dateutil>=2.8.10
57+
- types-PyYAML<6.1.0,>=5.4
58+
- types-redis>=3.5.3,<4.1.0
59+
- types-requests<2.27.2,>=2.23.0
60+
- types-tabulate<0.8.10,>=0.7.7
61+
- attrs<21.5.0,>=21.4.0
62+
- filelock>=3.3.0,<3.6.1
63+
- repo: https://github.com/hadolint/hadolint
64+
rev: 'v2.10.0'
65+
hooks:
66+
- id: hadolint-docker
67+
- repo: https://github.com/asottile/yesqa
68+
rev: v1.4.0
69+
hooks:
70+
- id: yesqa
71+
- repo: https://github.com/PyCQA/bandit
72+
rev: '1.7.4'
73+
hooks:
74+
- id: bandit
75+
args: [--configfile, pyproject.toml]
76+
types: [python]
77+
additional_dependencies: ["bandit[toml]"]
78+
- repo: local
79+
hooks:
80+
- id: poetry-check
81+
name: poetry check
82+
entry: poetry check
83+
language: system
84+
files: pyproject.toml
85+
pass_filenames: false

poetry.lock

Lines changed: 200 additions & 189 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ python = "^3.7.1"
5454
appdirs = "<=1.4.4,>=1.4.3"
5555
attrs = ">=21.1.0,<22.2.0"
5656
bashlex = ">=0.16,<0.17"
57-
black = { version = "==22.6.0", optional = true }
5857
calamus = ">=0.3.13,<0.5"
5958
click = ">=8.0,<8.1.4"
6059
click-option-group = "<0.6.0,>=0.5.2"
@@ -111,7 +110,7 @@ apispec-webframeworks = { version = "<0.6,>=0.5.2", optional = true }
111110
circus = { version = "==0.17.1", optional = true }
112111
flask = { version = "==2.1.1", optional = true }
113112
gunicorn = { version = "*", optional = true }
114-
marshmallow = { version = ">=3.18.0", optional = true }
113+
marshmallow = { version = ">=3.18.0,<3.20.0", optional = true }
115114
marshmallow-oneofschema = { version = ">=3.0.1,<4.0.0", optional = true }
116115
pillow = { version = ">=9.0.0,<9.4", optional = true }
117116
python-dotenv = { version = ">=0.19.0,<0.21.0", optional = true }
@@ -122,7 +121,7 @@ sentry-sdk = { version = ">=1.5.11,<1.5.12", extras = ["flask"], optional = tru
122121
walrus = { version = ">=0.8.2,<0.10.0", optional = true }
123122

124123
[tool.poetry.group.dev.dependencies]
125-
black = "==22.6.0"
124+
black = "==22.10.0"
126125
flake8 = [
127126
{ version = ">=6.0.0,<7.0.0", python = ">=3.8.1"},
128127
{ version = ">=4.0.0,<5.0.0", python = "<3.8.1"}
@@ -222,6 +221,8 @@ exclude = '''
222221
[tool.pydocstyle]
223222
add_ignore = ["D105", "D107", "D202", "D401"]
224223

224+
[tool.bandit]
225+
skips = ["B101", "B603", "B404"]
225226

226227
[tool.isort]
227228
multi_line_output = 3
@@ -275,6 +276,11 @@ files = [
275276
"renku/**/*.py",
276277
"tests/**/*.py"
277278
]
279+
pretty = true
280+
show_column_numbers = true
281+
show_error_codes = true
282+
show_error_context = true
283+
warn_unreachable = true
278284
implicit_optional = true
279285
check_untyped_defs = true
280286

renku/command/rollback.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import re
2222
from datetime import datetime
2323
from itertools import islice
24-
from typing import Dict, List, Optional, Tuple, cast
24+
from typing import TYPE_CHECKING, Dict, Generator, List, Optional, Tuple, cast
2525

2626
from renku.command.command_builder.command import Command
2727
from renku.core.util import communication
@@ -30,6 +30,9 @@
3030
from renku.domain_model.provenance.activity import Activity
3131
from renku.domain_model.workflow.plan import AbstractPlan
3232

33+
if TYPE_CHECKING:
34+
from renku.infrastructure.repository import Commit
35+
3336
CHECKPOINTS_PER_PAGE = 50
3437

3538

@@ -40,7 +43,7 @@ def rollback_command():
4043

4144
def _rollback_command():
4245
"""Perform a rollback of the repo."""
43-
commits = project_context.repository.iterate_commits(project_context.metadata_path)
46+
commits: Generator["Commit", None, None] = project_context.repository.iterate_commits(project_context.metadata_path)
4447

4548
checkpoint = _prompt_for_checkpoint(commits)
4649

@@ -304,7 +307,7 @@ def _checkpoint_iterator(commits):
304307
"""
305308
transaction_pattern = re.compile(r"\n\nrenku-transaction:\s([0-9a-g]+)$")
306309

307-
current_checkpoint = None
310+
current_checkpoint: Optional[Tuple[str, "Commit", str]] = None
308311

309312
for commit in commits:
310313
commit_message = commit.message

renku/core/util/git.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ def get_full_repository_path(url: Optional[str]) -> str:
250250
Returns:
251251
The hostname plus path extracted from the URL.
252252
"""
253-
if str is None:
253+
if url is None:
254254
return ""
255255

256256
parsed_url = parse_git_url(url)

renku/core/util/metadata.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import os
2222
import re
2323
import tempfile
24-
from collections.abc import Iterable
2524
from pathlib import Path
2625
from typing import TYPE_CHECKING, List, Optional, Tuple, Union
2726

@@ -42,9 +41,6 @@ def construct_creators(creators: List[Union[dict, str]], ignore_email=False) ->
4241
"""Parse input and return a list of Person."""
4342
creators = creators or []
4443

45-
if not isinstance(creators, Iterable) or isinstance(creators, str):
46-
raise errors.ParameterError("Invalid creators type")
47-
4844
people = []
4945
no_email_warnings = []
5046
for creator in creators:

renku/core/workflow/execute.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ def iterate_workflow(
411411
tag_separator = "@"
412412
index_pattern = re.compile(r"{iter_index}")
413413

414-
iter_params: Optional[Dict[str, Any]] = {"indexed": {}, "params": {}, "tagged": {}}
414+
iter_params: Dict[str, Any] = {"indexed": {}, "params": {}, "tagged": {}}
415415
workflow_params = {}
416416
if mapping_path:
417417
mapping = safe_read_yaml(mapping_path)
@@ -423,42 +423,42 @@ def iterate_workflow(
423423
iter_params["indexed"][param_name] = param_value # type: ignore
424424
else:
425425
try:
426-
param_value = ast.literal_eval(param_value)
426+
evaluated_param_value = ast.literal_eval(param_value)
427427
except Exception:
428428
raise errors.ParameterError(
429429
f"The value of '{param_name}' parameter is neither a list nor templated variable!"
430430
)
431431

432-
if isinstance(param_value, list) and len(param_value) == 1:
432+
if isinstance(evaluated_param_value, list) and len(evaluated_param_value) == 1:
433433
communication.warn(
434434
f"The parameter '{param_name}' has only one element '{param_value}', "
435435
"changing it to be a fixed parameter!"
436436
)
437437
workflow_params[param_name] = param_value[0]
438438
continue
439-
elif not isinstance(param_value, list):
439+
elif not isinstance(evaluated_param_value, list):
440440
workflow_params[param_name] = param_value
441441
continue
442442

443443
if tag_separator in param_name:
444444
name, tag = param_name.split(tag_separator, maxsplit=1)
445445
if tag in iter_params["tagged"]:
446-
iter_params["tagged"][tag][name] = param_value
446+
iter_params["tagged"][tag][name] = evaluated_param_value
447447
else:
448-
iter_params["tagged"][tag] = {name: param_value}
448+
iter_params["tagged"][tag] = {name: evaluated_param_value}
449449

450450
param_name = name
451451
else:
452-
iter_params["params"][param_name] = param_value
452+
iter_params["params"][param_name] = evaluated_param_value
453453

454454
set_param = reduce(lambda x, y: {y: x}, reversed(param_name.split(".")), param_value) # type: ignore
455455
workflow_params = always_merger.merge(workflow_params, set_param)
456456

457-
iter_params = _validate_iterate_parameters(workflow, workflow_params, cast(Dict[str, Any], iter_params))
458-
if iter_params is None:
457+
validated_iter_params = _validate_iterate_parameters(workflow, workflow_params, cast(Dict[str, Any], iter_params))
458+
if validated_iter_params is None:
459459
return
460460

461-
plans, execute_plan = _build_iterations(workflow, workflow_params, iter_params, index_pattern)
461+
plans, execute_plan = _build_iterations(workflow, workflow_params, validated_iter_params, index_pattern)
462462

463463
communication.echo(f"\n\n{tabulate(execute_plan, execute_plan[0].keys())}")
464464
if not dry_run:

renku/core/workflow/parser/renku.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def get_elements(data: Union[Dict[str, Any], List[Dict[str, Any]]]) -> Generator
210210
"""Get elements of a list of dict as a dict."""
211211
if isinstance(data, list):
212212
for element in data:
213-
if isinstance(element, list):
213+
if isinstance(element, list): # type: ignore[unreachable]
214214
raise errors.ParseError(f"Data cannot be a list: {element}")
215215
yield element
216216
elif not isinstance(data, dict):

renku/core/workflow/plan.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import itertools
2121
import os
22-
from datetime import timedelta
22+
from datetime import datetime, timedelta
2323
from pathlib import Path
2424
from typing import Any, Dict, Generator, List, Optional, Set, Tuple, Union, cast, overload
2525

@@ -79,12 +79,12 @@ def get_plan(
7979

8080

8181
@overload
82-
def get_latest_plan(plan: None = ..., plan_gateway: IPlanGateway = ...) -> None: # noqa: D103
82+
def get_latest_plan(plan: None = ..., plan_gateway: IPlanGateway = ...) -> None:
8383
...
8484

8585

8686
@overload
87-
def get_latest_plan(plan: AbstractPlan, plan_gateway: IPlanGateway = ...) -> AbstractPlan: # noqa: D103
87+
def get_latest_plan(plan: AbstractPlan, plan_gateway: IPlanGateway = ...) -> AbstractPlan:
8888
...
8989

9090

@@ -197,12 +197,12 @@ def show_workflow(name_or_id_or_path: str, activity_gateway: IActivityGateway, w
197197
if isinstance(workflow, Plan):
198198

199199
num_executions = 0
200-
last_execution = None
200+
last_execution: Optional[datetime] = None
201201

202202
for activity in relevant_activities:
203203
num_executions += 1
204204

205-
if not last_execution or last_execution < activity.ended_at_time:
205+
if last_execution is None or last_execution < activity.ended_at_time:
206206
last_execution = activity.ended_at_time
207207

208208
workflow = cast(Plan, DynamicProxy(workflow))
@@ -810,7 +810,7 @@ def get_plans_with_metadata(activity_gateway: IActivityGateway, plan_gateway: IP
810810
latest_plan.touches_existing_files = False
811811
latest_plan.number_of_executions = 0
812812
latest_plan.created = latest_plan.date_created
813-
latest_plan.last_executed = None
813+
latest_plan.last_executed = cast(Optional[datetime], None)
814814
latest_plan.children = []
815815
duration = _get_plan_duration(latest_plan, duration_cache, activity_map)
816816

@@ -819,7 +819,7 @@ def get_plans_with_metadata(activity_gateway: IActivityGateway, plan_gateway: IP
819819

820820
if isinstance(plan_chain[0], Plan):
821821
for activity in activity_map.get(latest_plan.id, []):
822-
if not latest_plan.last_executed or latest_plan.last_executed < activity.ended_at_time:
822+
if latest_plan.last_executed is None or latest_plan.last_executed < activity.ended_at_time:
823823
latest_plan.last_executed = activity.ended_at_time
824824

825825
latest_plan.number_of_executions += 1

0 commit comments

Comments
 (0)