Skip to content

Commit 939fed1

Browse files
authored
fix: update python syntax and fix bugs for src updates (#5844)
1 parent 65a4cf4 commit 939fed1

35 files changed

+289
-283
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ repos:
2121
hooks:
2222
- id: pyupgrade
2323
args:
24-
- --py36-plus
24+
- --py312-plus
2525

2626
- repo: https://github.com/adhtruong/mirrors-typos
2727
rev: v1.44.0

conda_forge_tick/all_feedstocks.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import logging
2-
from typing import List
32

43
import tqdm
54

@@ -41,7 +40,7 @@ def get_all_feedstocks_from_github():
4140
}
4241

4342

44-
def get_all_feedstocks(cached: bool = False) -> List[str]:
43+
def get_all_feedstocks(cached: bool = False) -> list[str]:
4544
if cached:
4645
logger.info("reading cached feedstocks")
4746
with open("all_feedstocks.json") as f:
@@ -52,7 +51,7 @@ def get_all_feedstocks(cached: bool = False) -> List[str]:
5251
return names
5352

5453

55-
def get_archived_feedstocks(cached: bool = False) -> List[str]:
54+
def get_archived_feedstocks(cached: bool = False) -> list[str]:
5655
if cached:
5756
logger.info("reading cached archived feedstocks")
5857
with open("all_feedstocks.json") as f:

conda_forge_tick/cli.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import logging
22
import time
3-
from typing import Optional
43

54
import click
65
from click import Context, IntRange
@@ -150,7 +149,7 @@ def make_graph(
150149
)
151150
@pass_context
152151
def update_upstream_versions(
153-
ctx: CliContext, job: int, n_jobs: int, package: Optional[str]
152+
ctx: CliContext, job: int, n_jobs: int, package: str | None
154153
) -> None:
155154
"""
156155
Update the upstream versions of feedstocks in the graph.

conda_forge_tick/config_schema.py

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from enum import StrEnum
33
from inspect import cleandoc
44
from pathlib import Path
5-
from typing import Optional, Union
65

76
from pydantic import BaseModel, ConfigDict, Field
87

@@ -46,14 +45,14 @@ class BotConfigVersionUpdatesNVIDIA(BaseModel):
4645
updates using the NVIDIA source.
4746
"""
4847

49-
compute_subdir: Optional[str] = Field(
48+
compute_subdir: str | None = Field(
5049
default=None,
5150
description="For sources from `developer.download.nvidia.com/compute`, this string"
5251
"defines the subdirectory in which to find the JSON blob containing metadata"
5352
"about the latest releases of a package.",
5453
)
5554

56-
json_name: Optional[str] = Field(
55+
json_name: str | None = Field(
5756
default=None,
5857
description="For sources from `developer.download.nvidia.com/compute`, this string"
5958
"defines the name of the package in the JSON blob containing metadata"
@@ -69,18 +68,18 @@ class BotConfigVersionUpdates(BaseModel):
6968

7069
model_config: ConfigDict = ConfigDict(extra="forbid")
7170

72-
random_fraction_to_keep: Optional[float] = Field(
71+
random_fraction_to_keep: float | None = Field(
7372
None,
7473
description="Fraction of versions to keep for frequently updated packages",
7574
)
7675

77-
exclude: Optional[list[str]] = Field(
76+
exclude: list[str] | None = Field(
7877
default=[],
7978
description="List of versions to exclude. "
8079
"Make sure branch names are `str` by quoting the value.",
8180
)
8281

83-
sources: Optional[list[BotConfigVersionUpdatesSourcesChoice]] = Field(
82+
sources: list[BotConfigVersionUpdatesSourcesChoice] | None = Field(
8483
None,
8584
description=cleandoc(
8685
"""
@@ -111,35 +110,35 @@ class BotConfigVersionUpdates(BaseModel):
111110
),
112111
)
113112

114-
skip: Optional[bool] = Field(
113+
skip: bool | None = Field(
115114
default=False,
116115
description="Skip automatic version updates. "
117116
"Useful in cases where the source project's version numbers don't conform to "
118117
"PEP440.",
119118
)
120119

121-
even_odd_versions: Optional[bool] = Field(
120+
even_odd_versions: bool | None = Field(
122121
default=None,
123122
description="For projects that follow even/odd versioning schemes (like GNOME), "
124123
"set to true to only accept stable versions (even minor numbers: 1.2.x, 1.4.x) "
125124
"and ignore development versions (odd minor numbers: 1.1.x, 1.3.x). "
126125
"Leave unset for projects that don't follow this versioning scheme.",
127126
)
128127

129-
allowed_tag_globs: Optional[Union[str, list[str]]] = Field(
128+
allowed_tag_globs: str | list[str] | None = Field(
130129
default=None,
131130
description="For version sources that parse repo/vcs tags (e.g., "
132131
"`gittags`, `github`, `githubreleases`), "
133132
"the list of glob patterns that define which tags are allowed. This field can be used to "
134133
"filter the set of tags to only those relevant for the feedstock.",
135134
)
136135

137-
nvidia: Optional[BotConfigVersionUpdatesNVIDIA] = Field(
136+
nvidia: BotConfigVersionUpdatesNVIDIA | None = Field(
138137
default_factory=BotConfigVersionUpdatesNVIDIA,
139138
description="Bot config for version update PRs using the NVIDIA updater.",
140139
)
141140

142-
use_curl: Optional[bool] = Field(
141+
use_curl: bool | None = Field(
143142
None,
144143
description="If True, use `curl` to test if URLs exist, otherwise use `wget`.",
145144
)
@@ -199,38 +198,38 @@ class BotConfig(BaseModel):
199198

200199
model_config: ConfigDict = ConfigDict(extra="forbid")
201200

202-
automerge: Optional[Union[bool, BotConfigAutoMergeChoice]] = Field(
201+
automerge: bool | BotConfigAutoMergeChoice | None = Field(
203202
False,
204203
description="Automatically merge PRs if possible",
205204
)
206205

207-
check_solvable: Optional[bool] = Field(
206+
check_solvable: bool | None = Field(
208207
default=True,
209208
description="Open PRs only if resulting environment is solvable.",
210209
)
211210

212-
inspection: Optional[BotConfigInspectionChoice] = Field(
211+
inspection: BotConfigInspectionChoice | None = Field(
213212
default="hint",
214213
description="Method for generating hints or updating recipe",
215214
)
216215

217-
abi_migration_branches: Optional[list[str]] = Field(
216+
abi_migration_branches: list[str] | None = Field(
218217
default=[],
219218
description="List of branches for additional bot migration PRs. "
220219
"Make sure branch names are `str` by quoting the value.",
221220
)
222221

223-
run_deps_from_wheel: Optional[bool] = Field(
222+
run_deps_from_wheel: bool | None = Field(
224223
default=False,
225224
description="Update run dependencies from the pip wheel",
226225
)
227226

228-
version_updates: Optional[BotConfigVersionUpdates] = Field(
227+
version_updates: BotConfigVersionUpdates | None = Field(
229228
default_factory=BotConfigVersionUpdates,
230229
description="Bot config for version update PRs",
231230
)
232231

233-
update_static_libs: Optional[bool] = Field(
232+
update_static_libs: bool | None = Field(
234233
default=False,
235234
description="Update packages in `host` that are used for static "
236235
"linking. For bot to issue update PRs, you must have both an "
@@ -241,7 +240,7 @@ class BotConfig(BaseModel):
241240
"latest package.",
242241
)
243242

244-
remake_prs_with_conflicts: Optional[bool] = Field(
243+
remake_prs_with_conflicts: bool | None = Field(
245244
default=True,
246245
description="Automatically remake untouched bot PRs with conflicts.",
247246
)

conda_forge_tick/feedstock_parser.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import zipfile
1010
from collections import defaultdict
1111
from pathlib import Path
12-
from typing import Optional, Set, Tuple, Union
12+
from typing import Union
1313

1414
import requests
1515
import yaml
@@ -87,7 +87,7 @@ def _get_requirements(
8787
build: bool = True,
8888
host: bool = True,
8989
run: bool = True,
90-
outputs_to_keep: Optional[Set["PackageName"]] = None,
90+
outputs_to_keep: set["PackageName"] | None = None,
9191
) -> set[PackageName]:
9292
"""Get the list of recipe requirements from a meta.yaml dict.
9393
@@ -124,7 +124,7 @@ def _get_requirements(
124124

125125

126126
def _parse_requirements(
127-
req: Union[None, typing.List[str], "RequirementsTypedDict"],
127+
req: Union[None, list[str], "RequirementsTypedDict"],
128128
build: bool = True,
129129
host: bool = True,
130130
run: bool = True,
@@ -541,7 +541,7 @@ def populate_feedstock_attributes(
541541
source = yaml_dict.get("source", [])
542542
if isinstance(source, collections.abc.Mapping):
543543
source = [source]
544-
source_keys: Set[str] = set()
544+
source_keys: set[str] = set()
545545
for s in source:
546546
if not node_attrs.get("url"):
547547
node_attrs["url"] = s.get("url")
@@ -556,7 +556,7 @@ def populate_feedstock_attributes(
556556

557557
def _get_feedstock_commit_hash_and_timestamp(
558558
name: str,
559-
) -> Tuple[str | None, int | None]:
559+
) -> tuple[str | None, int | None]:
560560
git_url = f"https://github.com/{settings().conda_forge_org}/{name}-feedstock"
561561
with tempfile.TemporaryDirectory() as tmpdir, pushd(tmpdir):
562562
try:

conda_forge_tick/git_utils.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@
1111
import threading
1212
import time
1313
from abc import ABC, abstractmethod
14-
from collections.abc import Sequence
14+
from collections.abc import Iterator, Sequence
1515
from datetime import datetime
1616
from email import utils
1717
from functools import cached_property
1818
from pathlib import Path
19-
from typing import Dict, Iterator, Optional, Union
2019

2120
import backoff
2221
import dateutil.parser
@@ -1551,9 +1550,9 @@ def delete_branch(pr_json: LazyJson | dict, dry_run: bool = False) -> None:
15511550

15521551

15531552
def trim_pr_json_keys(
1554-
pr_json: Union[Dict, LazyJson],
1555-
src_pr_json: Optional[Union[Dict, LazyJson]] = None,
1556-
) -> Union[Dict, LazyJson]:
1553+
pr_json: dict | LazyJson,
1554+
src_pr_json: dict | LazyJson | None = None,
1555+
) -> dict | LazyJson:
15571556
"""Trim the set of keys in the PR json. The keys kept are defined by the global
15581557
PR_KEYS_TO_KEEP.
15591558
@@ -1591,8 +1590,8 @@ def _munge_dict(dest, src, keys):
15911590

15921591

15931592
def lazy_update_pr_json(
1594-
pr_json: Union[Dict, LazyJson], force: bool = False
1595-
) -> Union[Dict, LazyJson]:
1593+
pr_json: dict | LazyJson, force: bool = False
1594+
) -> dict | LazyJson:
15961595
"""Lazily update a GitHub PR.
15971596
15981597
This function will use the Last-Modified field in the GitHub API to update
@@ -1663,7 +1662,7 @@ def lazy_update_pr_json(
16631662
def refresh_pr(
16641663
pr_json: LazyJson | dict,
16651664
dry_run: bool = False,
1666-
) -> Optional[dict]:
1665+
) -> dict | None:
16671666
from conda_forge_tick.settings import settings
16681667

16691668
pr_refresh_age_days = settings().pr_refresh_age_days
@@ -1711,7 +1710,7 @@ def refresh_pr(
17111710

17121711

17131712
def get_pr_obj_from_pr_json(
1714-
pr_json: Union[Dict, LazyJson],
1713+
pr_json: dict | LazyJson,
17151714
gh: github3.GitHub,
17161715
) -> github3.pulls.PullRequest:
17171716
"""Produce a github3 pull request object from pr_json.
@@ -1741,7 +1740,7 @@ def get_pr_obj_from_pr_json(
17411740
def close_out_labels(
17421741
pr_json: LazyJson | dict,
17431742
dry_run: bool = False,
1744-
) -> Optional[dict]:
1743+
) -> dict | None:
17451744
# run this twice so we always have the latest info (eg a thing was already closed)
17461745
if pr_json["state"] != "closed" and "bot-rerun" in [
17471746
lab["name"] for lab in pr_json.get("labels", [])
@@ -1782,7 +1781,7 @@ def close_out_labels(
17821781
def close_out_dirty_prs(
17831782
pr_json: LazyJson | dict,
17841783
dry_run: bool = False,
1785-
) -> Optional[dict]:
1784+
) -> dict | None:
17861785
# run this twice so we always have the latest info (eg a thing was already closed)
17871786
if pr_json["state"] != "closed" and pr_json["mergeable_state"] == "dirty":
17881787
# update

conda_forge_tick/import_to_pkg.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from concurrent.futures import ProcessPoolExecutor, as_completed
88
from functools import lru_cache
99
from itertools import chain, groupby
10-
from typing import List
1110

1211
import orjson
1312
import requests
@@ -283,7 +282,7 @@ def _get_imports_and_files(file):
283282
if data is None:
284283
return set(), []
285284

286-
pkg_files: List[str] = _extract_importable_files(data.get("files", []))
285+
pkg_files: list[str] = _extract_importable_files(data.get("files", []))
287286
# TODO: handle top level things that are stand alone .py files
288287
return (
289288
{

conda_forge_tick/lazy_json_backends.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,18 @@
1212
import time
1313
import urllib
1414
from abc import ABC, abstractmethod
15-
from collections.abc import Callable, Collection, MutableMapping
16-
from typing import (
17-
IO,
18-
Any,
15+
from collections.abc import (
16+
Callable,
17+
Collection,
1918
Iterable,
2019
Iterator,
2120
Mapping,
21+
MutableMapping,
22+
)
23+
from typing import (
24+
IO,
25+
Any,
2226
Self,
23-
Set,
2427
)
2528

2629
import github
@@ -1176,7 +1179,7 @@ def default(obj: Any) -> Any:
11761179
"""
11771180
if isinstance(obj, LazyJson):
11781181
return obj.json_ref
1179-
elif isinstance(obj, Set):
1182+
elif isinstance(obj, set):
11801183
return {"__set__": True, "elements": sorted(obj)}
11811184
elif isinstance(obj, nx.DiGraph):
11821185
nld = nx.node_link_data(obj, edges="links")

conda_forge_tick/lazy_json_backups.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424

2525
def make_lazy_json_backup(verbose=False):
26-
ts = str(int(datetime.datetime.now(tz=datetime.timezone.utc).timestamp()))
26+
ts = str(int(datetime.datetime.now(tz=datetime.UTC).timestamp()))
2727
slink = f"cf_graph_{ts}"
2828
try:
2929
subprocess.run(
@@ -85,11 +85,11 @@ def prune_timestamps(
8585
one_week = datetime.timedelta(weeks=1)
8686
one_month = datetime.timedelta(weeks=4)
8787

88-
now = datetime.datetime.now(tz=datetime.timezone.utc)
88+
now = datetime.datetime.now(tz=datetime.UTC)
8989

9090
tot = 0
9191
for ts in sorted(timestamps)[::-1]:
92-
dt = datetime.datetime.fromtimestamp(int(ts), tz=datetime.timezone.utc)
92+
dt = datetime.datetime.fromtimestamp(int(ts), tz=datetime.UTC)
9393
for i in range(nhours):
9494
key = f"h{i}"
9595
dt_high = now - i * one_hour

0 commit comments

Comments
 (0)