Skip to content

Commit

Permalink
Merge pull request #2149 from xhochy/typing-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
beckermr committed Feb 20, 2024
2 parents 9675f1e + 3c84ada commit 49da25c
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 28 deletions.
25 changes: 12 additions & 13 deletions conda_forge_tick/auto_tick.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from subprocess import CalledProcessError
from textwrap import dedent
from typing import (
List,
Mapping,
MutableMapping,
MutableSequence,
Expand All @@ -22,6 +23,7 @@
Set,
Tuple,
Union,
cast,
)

import tqdm
Expand Down Expand Up @@ -127,7 +129,7 @@
),
}

BOT_HOME_DIR = None
BOT_HOME_DIR: str = os.getcwd()

# migrator runs on loop so avoid any seeds at current time should that happen
random.seed(os.urandom(64))
Expand Down Expand Up @@ -650,7 +652,7 @@ def add_rebuild_migration_yaml(
# Some packages don't have a host section so we use their
# build section in its place.

feedstock_names = set()
feedstock_names: Set[str] = set()
for p in package_names:
feedstock_names |= output_to_feedstock.get(p, {p})

Expand Down Expand Up @@ -983,12 +985,12 @@ def initialize_migrators(
) -> Tuple[MigratorSessionContext, list, MutableSequence[Migrator]]:
temp = glob.glob("/tmp/*")
gx = load_existing_graph()
smithy_version = eval_cmd("conda smithy --version").strip()
pinning_version = json.loads(eval_cmd("conda list conda-forge-pinning --json"))[0][
"version"
]
smithy_version: str = eval_cmd("conda smithy --version").strip()
pinning_version: str = cast(
str, json.loads(eval_cmd("conda list conda-forge-pinning --json"))[0]["version"]
)

migrators = []
migrators: List[Migrator] = []

with fold_log_lines("making alt-arch migrators"):
add_arch_migrate(migrators, gx)
Expand All @@ -997,13 +999,13 @@ def initialize_migrators(
add_replacement_migrator(
migrators,
gx,
"build",
"python-build",
cast("PackageName", "build"),
cast("PackageName", "python-build"),
"The conda package name 'build' is deprecated "
"and too generic. Use 'python-build instead.'",
)

pinning_migrators = []
pinning_migrators: List[Migrator] = []
with fold_log_lines("making pinning migrators"):
migration_factory(pinning_migrators, gx)

Expand Down Expand Up @@ -1562,9 +1564,6 @@ def _update_graph_with_pr_info():
def main(ctx: CliContext) -> None:
_setup_limits()

global BOT_HOME_DIR
BOT_HOME_DIR = os.getcwd()

with fold_log_lines("updating graph with PR info"):
_update_graph_with_pr_info()

Expand Down
4 changes: 3 additions & 1 deletion conda_forge_tick/migrators/pip_wheel_dep.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ def filter(self, attrs: "AttrsTypedDict", not_bad_str_start: str = "") -> bool:
if "python" not in run_reqs:
return True

version = attrs.get("version_pr_info", {}).get("new_version", "") or attrs.get(
version: str = attrs.get("version_pr_info", {}).get(
"new_version", ""
) or attrs.get(
"version",
"",
)
Expand Down
4 changes: 2 additions & 2 deletions conda_forge_tick/os_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

# https://stackoverflow.com/questions/6194499/pushd-through-os-system
@contextlib.contextmanager
def pushd(new_dir):
def pushd(new_dir: str):
previous_dir = os.getcwd()
os.chdir(new_dir)
try:
Expand All @@ -15,7 +15,7 @@ def pushd(new_dir):
os.chdir(previous_dir)


def eval_cmd(cmd, **kwargs):
def eval_cmd(cmd: str, **kwargs) -> str:
"""run a command capturing stdout
stderr is printed for debugging
Expand Down
2 changes: 1 addition & 1 deletion conda_forge_tick/status_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def _ok_version(ver):
def write_version_migrator_status(migrator, mctx):
"""write the status of the version migrator"""

out = {
out: Dict[str, Any] = {
"queued": set(),
"errored": set(),
"errors": {},
Expand Down
18 changes: 9 additions & 9 deletions conda_forge_tick/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import typing
import warnings
from collections import defaultdict
from typing import Any, Iterable, Optional, Set, Tuple
from typing import Any, Dict, Iterable, Optional, Set, Tuple, cast

import github3
import jinja2
Expand Down Expand Up @@ -51,8 +51,8 @@
)


def _munge_dict_repr(d):
d = repr(d)
def _munge_dict_repr(dct: Dict[Any, Any]) -> str:
d = repr(dct)
d = "__dict__" + d[1:-1].replace(":", "@").replace(" ", "$$") + "__dict__"
return d

Expand Down Expand Up @@ -92,7 +92,7 @@ def fold_log_lines(title):
print("::endgroup::", flush=True)


def parse_munged_run_export(p):
def parse_munged_run_export(p: str) -> Dict:
if len(p) <= len("__dict__"):
logger.info("could not parse run export for pinning: %r", p)
return {}
Expand All @@ -104,9 +104,9 @@ def parse_munged_run_export(p):

if p.startswith("__dict__"):
p = "{" + p[len("__dict__") :].replace("$$", " ").replace("@", ":") + "}"
p = yaml_safe_load(p)
logger.debug("parsed run export for pinning: %r", p)
return p
dct = cast(Dict, yaml_safe_load(p))
logger.debug("parsed run export for pinning: %r", dct)
return dct
else:
logger.info("could not parse run export for pinning: %r", p_orig)
return {}
Expand All @@ -124,7 +124,7 @@ def yaml_safe_dump(data, stream=None):
return yaml.dump(data, stream=stream)


def render_meta_yaml(text: str, for_pinning=False, **kwargs) -> str:
def render_meta_yaml(text: str, for_pinning: bool = False, **kwargs) -> str:
"""Render the meta.yaml with Jinja2 variables.
Parameters
Expand Down Expand Up @@ -601,7 +601,7 @@ def _get_source_code(recipe_dir):
raise RuntimeError("conda build src exception:" + str(e))


def sanitize_string(instr):
def sanitize_string(instr: str) -> str:
with sensitive_env() as env:
tokens = [env.get("PASSWORD", None)]
for token in tokens:
Expand Down
18 changes: 16 additions & 2 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,22 @@
# disallow_untyped_defs = True
check_untyped_defs = True
warn_unreachable = True
follow_imports=error
files = "conda_forge_tick/*/*.py,conda_forge_tick/*/*/*.py"
files = conda_forge_tick/**/*.py

[mypy-depfinder.*]
ignore_missing_imports = True

[mypy-conda_forge_metadata.*]
ignore_missing_imports = True

[mypy-conda_forge_feedstock_check_solvable.*]
ignore_missing_imports = True

[mypy-yaml.*]
ignore_missing_imports = True

[mypy-rapidjson.*]
ignore_missing_imports = True

[mypy-networkx.*]
ignore_missing_imports = True
Expand Down

0 comments on commit 49da25c

Please sign in to comment.