Skip to content

Commit 1ad999f

Browse files
committed
fix mypy issues
1 parent d0a4214 commit 1ad999f

27 files changed

+312
-177
lines changed

conda-lock.yml

Lines changed: 96 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ metadata:
33
- url: conda-forge
44
used_env_vars: []
55
content_hash:
6-
linux-64: 47e27eadf78b024984ba2246127d65e7524c60bcb407b978498c1135cec23162
7-
osx-64: 5e63598ecaacbfd5f9f0e91975968b3d3bc12fae95d5cee457dd9b23b569ac98
8-
osx-arm64: 0f204f64b92bd922585ecf919b03561a9dccf5481b70ff29f89ea97b40c8ffb8
6+
linux-64: 4e740f8af6de809a90d97ae11e9665ea4057e2b62f165ae5425e72178f3c7659
7+
osx-64: 52e22739c47ecf742d0e09cb3959ecaecbdffd18c089951fb20d642bfb8d154f
8+
osx-arm64: d685097d2634b4be5015607c52d7a2b23b3eb609a18ba28962c6b7250db1f760
99
platforms:
1010
- osx-arm64
1111
- linux-64
@@ -8583,6 +8583,99 @@ package:
85838583
platform: osx-arm64
85848584
url: https://conda.anaconda.org/conda-forge/noarch/msrest-0.6.21-pyh44b312d_0.tar.bz2
85858585
version: 0.6.21
8586+
- category: main
8587+
dependencies:
8588+
__glibc: '>=2.17,<3.0.a0'
8589+
libgcc: '>=13'
8590+
mypy_extensions: '>=1.0.0'
8591+
psutil: '>=4.0'
8592+
python: '>=3.11,<3.12.0a0'
8593+
python_abi: 3.11.*
8594+
typing_extensions: '>=4.1.0'
8595+
hash:
8596+
md5: 0111eaad55bea1e607d90d4f84089f74
8597+
sha256: 460f3eb43160dc9e9a1f2aeabdf8cd809aefcf776c33ffd155f9bd2420a005c5
8598+
manager: conda
8599+
name: mypy
8600+
optional: false
8601+
platform: linux-64
8602+
url:
8603+
https://conda.anaconda.org/conda-forge/linux-64/mypy-1.13.0-py311h9ecbd09_0.conda
8604+
version: 1.13.0
8605+
- category: main
8606+
dependencies:
8607+
__osx: '>=10.13'
8608+
mypy_extensions: '>=1.0.0'
8609+
psutil: '>=4.0'
8610+
python: '>=3.11,<3.12.0a0'
8611+
python_abi: 3.11.*
8612+
typing_extensions: '>=4.1.0'
8613+
hash:
8614+
md5: 83a6e2bb0ea4940434b4d1402c92d3c4
8615+
sha256: ddca5a4235df88b876769dc191a5a41a453d2983bcb56104c0821d252e1abbb4
8616+
manager: conda
8617+
name: mypy
8618+
optional: false
8619+
platform: osx-64
8620+
url: https://conda.anaconda.org/conda-forge/osx-64/mypy-1.13.0-py311h1314207_0.conda
8621+
version: 1.13.0
8622+
- category: main
8623+
dependencies:
8624+
__osx: '>=11.0'
8625+
mypy_extensions: '>=1.0.0'
8626+
psutil: '>=4.0'
8627+
python: '>=3.11,<3.12.0a0'
8628+
python_abi: 3.11.*
8629+
typing_extensions: '>=4.1.0'
8630+
hash:
8631+
md5: 8b3f3c83db062e4970ba7a04890c83d5
8632+
sha256: 23c4fec92c5926baf3fe6ca8c0ad8b3d8ada66786d5b697d6e641d8885ac8ac6
8633+
manager: conda
8634+
name: mypy
8635+
optional: false
8636+
platform: osx-arm64
8637+
url:
8638+
https://conda.anaconda.org/conda-forge/osx-arm64/mypy-1.13.0-py311hae2e1ce_0.conda
8639+
version: 1.13.0
8640+
- category: main
8641+
dependencies:
8642+
python: '>=3.5'
8643+
hash:
8644+
md5: 4eccaeba205f0aed9ac3a9ea58568ca3
8645+
sha256: f240217476e148e825420c6bc3a0c0efb08c0718b7042fae960400c02af858a3
8646+
manager: conda
8647+
name: mypy_extensions
8648+
optional: false
8649+
platform: linux-64
8650+
url:
8651+
https://conda.anaconda.org/conda-forge/noarch/mypy_extensions-1.0.0-pyha770c72_0.conda
8652+
version: 1.0.0
8653+
- category: main
8654+
dependencies:
8655+
python: '>=3.5'
8656+
hash:
8657+
md5: 4eccaeba205f0aed9ac3a9ea58568ca3
8658+
sha256: f240217476e148e825420c6bc3a0c0efb08c0718b7042fae960400c02af858a3
8659+
manager: conda
8660+
name: mypy_extensions
8661+
optional: false
8662+
platform: osx-64
8663+
url:
8664+
https://conda.anaconda.org/conda-forge/noarch/mypy_extensions-1.0.0-pyha770c72_0.conda
8665+
version: 1.0.0
8666+
- category: main
8667+
dependencies:
8668+
python: '>=3.5'
8669+
hash:
8670+
md5: 4eccaeba205f0aed9ac3a9ea58568ca3
8671+
sha256: f240217476e148e825420c6bc3a0c0efb08c0718b7042fae960400c02af858a3
8672+
manager: conda
8673+
name: mypy_extensions
8674+
optional: false
8675+
platform: osx-arm64
8676+
url:
8677+
https://conda.anaconda.org/conda-forge/noarch/mypy_extensions-1.0.0-pyha770c72_0.conda
8678+
version: 1.0.0
85868679
- category: main
85878680
dependencies:
85888681
__glibc: '>=2.17,<3.0.a0'

conda_forge_tick/auto_tick.py

Lines changed: 52 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import traceback
1010
import typing
1111
from dataclasses import dataclass
12-
from typing import Literal, cast
12+
from typing import Any, Literal, cast
1313
from urllib.error import URLError
1414
from uuid import uuid4
1515

@@ -70,12 +70,15 @@
7070
)
7171

7272
from .migrators_types import MigrationUidTypedDict
73-
from .models.pr_json import PullRequestData, PullRequestInfoSpecial, PullRequestState
73+
from .models.pr_json import (
74+
PullRequestData,
75+
PullRequestInfoSpecial,
76+
PullRequestState,
77+
)
7478

7579
logger = logging.getLogger(__name__)
7680

7781
BOT_HOME_DIR: str = os.getcwd()
78-
START_TIME = None
7982
TIMEOUT = int(os.environ.get("TIMEOUT", 600))
8083

8184
# migrator runs on loop so avoid any seeds at current time should that happen
@@ -424,9 +427,9 @@ def _check_and_process_solvability(
424427

425428
def get_spoofed_closed_pr_info() -> PullRequestInfoSpecial:
426429
return PullRequestInfoSpecial(
427-
id=str(uuid4()),
430+
id=uuid4(),
428431
merged_at="never issued",
429-
state="closed",
432+
state=PullRequestState.CLOSED,
430433
)
431434

432435

@@ -437,7 +440,10 @@ def run_with_tmpdir(
437440
rerender: bool = True,
438441
base_branch: str = "main",
439442
**kwargs: typing.Any,
440-
) -> tuple[MigrationUidTypedDict, dict] | tuple[Literal[False], Literal[False]]:
443+
) -> (
444+
tuple[MigrationUidTypedDict, LazyJson | Literal[False]]
445+
| tuple[Literal[False], Literal[False]]
446+
):
441447
"""
442448
For a given feedstock and migration run the migration in a temporary directory that will be deleted after the
443449
migration is complete.
@@ -465,7 +471,10 @@ def run(
465471
rerender: bool = True,
466472
base_branch: str = "main",
467473
**kwargs: typing.Any,
468-
) -> tuple[MigrationUidTypedDict, dict] | tuple[Literal[False], Literal[False]]:
474+
) -> (
475+
tuple[MigrationUidTypedDict, LazyJson | Literal[False]]
476+
| tuple[Literal[False], Literal[False]]
477+
):
469478
"""For a given feedstock and migration run the migration
470479
471480
Parameters
@@ -601,19 +610,25 @@ def run(
601610
and pr_data.state != PullRequestState.CLOSED
602611
and rerender_info.rerender_comment
603612
):
613+
if pr_data.number is None:
614+
raise ValueError(
615+
f"Unexpected GitHub API response: PR number is missing for PR ID {pr_data.id}."
616+
)
604617
git_backend.comment_on_pull_request(
605618
repo_owner=context.git_repo_owner,
606619
repo_name=context.git_repo_name,
607620
pr_number=pr_data.number,
608621
comment=rerender_info.rerender_comment,
609622
)
610623

624+
pr_lazy_json: LazyJson | Literal[False]
611625
if pr_data:
612-
pr_lazy_json = LazyJson(
626+
pr_lazy_json_present = LazyJson(
613627
os.path.join("pr_json", f"{pr_data.id}.json"),
614628
)
615-
with pr_lazy_json as __edit_pr_lazy_json:
629+
with pr_lazy_json_present as __edit_pr_lazy_json:
616630
__edit_pr_lazy_json.update(**pr_data.model_dump(mode="json"))
631+
pr_lazy_json = pr_lazy_json_present
617632
else:
618633
pr_lazy_json = False
619634

@@ -624,7 +639,10 @@ def run(
624639
context.attrs, migrator_name, is_version=is_version_migration
625640
)
626641

627-
return migration_run_data["migrate_return_value"], pr_lazy_json
642+
migrate_return_value: MigrationUidTypedDict = migration_run_data[
643+
"migrate_return_value"
644+
]
645+
return migrate_return_value, pr_lazy_json
628646

629647

630648
def _compute_time_per_migrator(migrators):
@@ -633,8 +651,8 @@ def _compute_time_per_migrator(migrators):
633651
for migrator in tqdm.tqdm(migrators, ncols=80, desc="computing time per migrator"):
634652
if isinstance(migrator, Version):
635653
_num_nodes = 0
636-
for node_name in migrator.effective_graph.nodes:
637-
with migrator.effective_graph.nodes[node_name]["payload"] as attrs:
654+
for node_name in migrator.effective_graph.nodes: # type: ignore[union-attr] # TODO: effective_graph can be None
655+
with migrator.effective_graph.nodes[node_name]["payload"] as attrs: # type: ignore[union-attr] # TODO: effective_graph can be None
638656
with attrs["version_pr_info"] as vpri:
639657
_attempts = vpri.get("new_version_attempts", {}).get(
640658
vpri.get("new_version", ""),
@@ -644,7 +662,7 @@ def _compute_time_per_migrator(migrators):
644662
_num_nodes += 1
645663
_num_nodes = max(
646664
_num_nodes,
647-
min(PR_LIMIT * 4, len(migrator.effective_graph.nodes)),
665+
min(PR_LIMIT * 4, len(migrator.effective_graph.nodes)), # type: ignore[union-attr] # TODO: effective_graph can be None
648666
)
649667
num_nodes.append(_num_nodes)
650668
else:
@@ -684,23 +702,6 @@ def _compute_time_per_migrator(migrators):
684702
return num_nodes, time_per_migrator, tot_time_per_migrator
685703

686704

687-
def _over_time_limit():
688-
_now = time.time()
689-
print(
690-
"""\
691-
692-
=~>=~>=~>=~>=~>=~>=~>=~>=~>=~>=~>=~>=~>=~>=~>=~>=~>=~>=~>=~>=~>=~>=~>=~>=~>=~>
693-
=~> elpased time %ds (timeout %ds)
694-
=~>=~>=~>=~>=~>=~>=~>=~>=~>=~>=~>=~>=~>=~>=~>=~>=~>=~>=~>=~>=~>=~>=~>=~>=~>=~>
695-
696-
"""
697-
% (_now - START_TIME, TIMEOUT),
698-
flush=True,
699-
end="",
700-
)
701-
return _now - START_TIME > TIMEOUT
702-
703-
704705
def _run_migrator_on_feedstock_branch(
705706
attrs,
706707
base_branch,
@@ -730,15 +731,15 @@ def _run_migrator_on_feedstock_branch(
730731
# if migration successful
731732
if migrator_uid:
732733
with attrs["pr_info"] as pri:
733-
d = frozen_to_json_friendly(migrator_uid)
734+
d: Any = frozen_to_json_friendly(migrator_uid)
734735
# if we have the PR already do nothing
735736
if d["data"] in [
736737
existing_pr["data"] for existing_pr in pri.get("PRed", [])
737738
]:
738739
pass
739740
else:
740741
if not pr_json:
741-
pr_json = {
742+
pr_json = { # type: ignore[assignment] # TODO: incompatible with LazyJson
742743
"state": "closed",
743744
"head": {
744745
"ref": "<this_is_not_a_branch>",
@@ -847,15 +848,15 @@ def _run_migrator_on_feedstock_branch(
847848
return good_prs, break_loop
848849

849850

850-
def _is_migrator_done(_mg_start, good_prs, time_per, pr_limit):
851+
def _is_migrator_done(_mg_start, good_prs, time_per, pr_limit, start_time: float):
851852
curr_time = time.time()
852853
backend = github_backend()
853854
api_req = backend.get_api_requests_left()
854855

855-
if curr_time - START_TIME > TIMEOUT:
856+
if curr_time - start_time > TIMEOUT:
856857
logger.info(
857858
"BOT TIMEOUT: breaking after %d seconds (limit %d)",
858-
curr_time - START_TIME,
859+
curr_time - start_time,
859860
TIMEOUT,
860861
)
861862
return True
@@ -885,7 +886,9 @@ def _is_migrator_done(_mg_start, good_prs, time_per, pr_limit):
885886
return False
886887

887888

888-
def _run_migrator(migrator, mctx, temp, time_per, git_backend: GitPlatformBackend):
889+
def _run_migrator(
890+
migrator, mctx, temp, time_per, git_backend: GitPlatformBackend, start_time: float
891+
):
889892
_mg_start = time.time()
890893

891894
migrator_name = get_migrator_name(migrator)
@@ -939,7 +942,9 @@ def _run_migrator(migrator, mctx, temp, time_per, git_backend: GitPlatformBacken
939942
flush=True,
940943
)
941944

942-
if _is_migrator_done(_mg_start, good_prs, time_per, migrator.pr_limit):
945+
if _is_migrator_done(
946+
_mg_start, good_prs, time_per, migrator.pr_limit, start_time
947+
):
943948
return 0
944949

945950
for node_name in possible_nodes:
@@ -956,7 +961,9 @@ def _run_migrator(migrator, mctx, temp, time_per, git_backend: GitPlatformBacken
956961
):
957962
# Don't let CI timeout, break ahead of the timeout so we make certain
958963
# to write to the repo
959-
if _is_migrator_done(_mg_start, good_prs, time_per, migrator.pr_limit):
964+
if _is_migrator_done(
965+
_mg_start, good_prs, time_per, migrator.pr_limit, start_time
966+
):
960967
break
961968

962969
base_branches = migrator.get_possible_feedstock_branches(attrs)
@@ -1201,8 +1208,7 @@ def _update_graph_with_pr_info():
12011208

12021209

12031210
def main(ctx: CliContext) -> None:
1204-
global START_TIME
1205-
START_TIME = time.time()
1211+
start_time = time.time()
12061212

12071213
_setup_limits()
12081214

@@ -1260,7 +1266,12 @@ def main(ctx: CliContext) -> None:
12601266

12611267
for mg_ind, migrator in enumerate(migrators):
12621268
good_prs = _run_migrator(
1263-
migrator, mctx, temp, time_per_migrator[mg_ind], git_backend
1269+
migrator,
1270+
mctx,
1271+
temp,
1272+
time_per_migrator[mg_ind],
1273+
git_backend,
1274+
start_time=start_time,
12641275
)
12651276
if good_prs > 0:
12661277
pass

conda_forge_tick/container_cli.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,11 @@ def _migrate_feedstock(*, feedstock_name, default_branch, attrs, input_kwargs):
199199
logger = logging.getLogger("conda_forge_tick.container")
200200

201201
with tempfile.TemporaryDirectory() as tmpdir:
202-
input_fs_dir = glob.glob("/cf_feedstock_ops_dir/*-feedstock")
203-
assert len(input_fs_dir) == 1, f"expected one feedstock, got {input_fs_dir}"
204-
input_fs_dir = input_fs_dir[0]
202+
input_fs_dir_list = glob.glob("/cf_feedstock_ops_dir/*-feedstock")
203+
assert (
204+
len(input_fs_dir_list) == 1
205+
), f"expected one feedstock, got {input_fs_dir_list}"
206+
input_fs_dir = input_fs_dir_list[0]
205207
logger.debug(
206208
f"input container feedstock dir {input_fs_dir}: {os.listdir(input_fs_dir)}"
207209
)
@@ -253,9 +255,11 @@ def _update_version(*, version, hash_type):
253255
logger = logging.getLogger("conda_forge_tick.container")
254256

255257
with tempfile.TemporaryDirectory() as tmpdir:
256-
input_fs_dir = glob.glob("/cf_feedstock_ops_dir/*-feedstock")
257-
assert len(input_fs_dir) == 1, f"expected one feedstock, got {input_fs_dir}"
258-
input_fs_dir = input_fs_dir[0]
258+
input_fs_dir_list = glob.glob("/cf_feedstock_ops_dir/*-feedstock")
259+
assert (
260+
len(input_fs_dir_list) == 1
261+
), f"expected one feedstock, got {input_fs_dir_list}"
262+
input_fs_dir = input_fs_dir_list[0]
259263
logger.debug(
260264
f"input container feedstock dir {input_fs_dir}: {os.listdir(input_fs_dir)}"
261265
)
@@ -472,12 +476,14 @@ def parse_meta_yaml(
472476
"--cbc-path", type=str, default=None, help="The path to global pinning file."
473477
)
474478
def parse_recipe_yaml(
479+
log_level,
475480
for_pinning,
476481
platform_arch,
477482
cbc_path,
478483
):
479484
return _run_bot_task(
480485
_parse_recipe_yaml,
486+
log_level=log_level,
481487
existing_feedstock_node_attrs=None,
482488
for_pinning=for_pinning,
483489
platform_arch=platform_arch,

0 commit comments

Comments
 (0)