From b2a66d4f8481bdb2f7d6d007d6844d092adb7c68 Mon Sep 17 00:00:00 2001 From: Ninette Adhikari Date: Thu, 20 Jun 2024 11:09:45 -0400 Subject: [PATCH] chore: Reformat files with black and add news entry --- conda_smithy/anaconda_token_rotation.py | 6 +--- conda_smithy/configure_feedstock.py | 33 ++++++----------- conda_smithy/feedstock_io.py | 11 ++---- conda_smithy/lint_recipe.py | 8 +++-- conda_smithy/schema.py | 47 +++++++++++++------------ conda_smithy/utils.py | 6 +--- conda_smithy/validate_schema.py | 15 ++++---- conda_smithy/variant_algebra.py | 2 +- news/1957_add_typing.rst | 23 ++++++++++++ tests/test_feedstock_io.py | 4 +-- 10 files changed, 78 insertions(+), 77 deletions(-) create mode 100644 news/1957_add_typing.rst diff --git a/conda_smithy/anaconda_token_rotation.py b/conda_smithy/anaconda_token_rotation.py index e822bc288..63e537b9f 100644 --- a/conda_smithy/anaconda_token_rotation.py +++ b/conda_smithy/anaconda_token_rotation.py @@ -13,11 +13,7 @@ import sys from contextlib import redirect_stderr, redirect_stdout from github import Github -from typing import ( - List, - Optional, - Union -) +from typing import List, Optional, Union import requests diff --git a/conda_smithy/configure_feedstock.py b/conda_smithy/configure_feedstock.py index f475b893b..af98ad267 100644 --- a/conda_smithy/configure_feedstock.py +++ b/conda_smithy/configure_feedstock.py @@ -42,7 +42,7 @@ try: import simplejson as json except ImportError: - import json # type: ignore + import json # type: ignore from conda.models.match_spec import MatchSpec from conda.models.version import VersionOrder @@ -107,10 +107,7 @@ def warn_once(msg: str): def package_key( - config: Dict[ - str, - Union[List[str], List[List[str]], OrderedDict] - ], + config: Dict[str, Union[List[str], List[List[str]], OrderedDict]], used_loop_vars: Set[str], subdir: str, ) -> str: @@ -178,9 +175,7 @@ def merge_list_of_dicts( return squished_dict -def argsort( - seq: List[tuple] -) -> List[int]: +def argsort(seq: List[tuple]) -> List[int]: return sorted(range(len(seq)), key=seq.__getitem__) @@ -346,9 +341,7 @@ def _trim_unused_zip_keys(all_used_vars): del all_used_vars["zip_keys"] -def _trim_unused_pin_run_as_build( - all_used_vars: dict -): +def _trim_unused_pin_run_as_build(all_used_vars: dict): """Remove unused keys in pin_run_as_build sets""" pkgs = all_used_vars.get("pin_run_as_build", {}) used_pkgs = {} @@ -370,10 +363,7 @@ def _get_used_key_values_by_input_order( Union[set, dict, list, tuple], ], ], - squished_used_variants: Union[ - OrderedDict, - dict - ], + squished_used_variants: Union[OrderedDict, dict], all_used_vars: Set[str], ) -> tuple: used_key_values = { @@ -737,9 +727,7 @@ def _collapse_subpackage_variants( ) -def _yaml_represent_ordereddict( - yaml_representer, data: OrderedDict -): +def _yaml_represent_ordereddict(yaml_representer, data: OrderedDict): # represent_dict processes dict-likes with a .sort() method or plain iterables of key-value # pairs. Only for the latter it never sorts and retains the order of the OrderedDict. return yaml.representer.SafeRepresenter.represent_dict( @@ -969,9 +957,10 @@ def migrate_combined_spec( def _conda_build_api_render_for_smithy( recipe_path: str, - config = None, - variants: Optional[Dict[str, Union[List[str], List[List[str]], Dict[str, Dict[str, str]]]]] - = None, + config=None, + variants: Optional[ + Dict[str, Union[List[str], List[List[str]], Dict[str, Dict[str, str]]]] + ] = None, permit_unsatisfiable_variants: bool = True, finalize: bool = True, bypass_env_check: bool = False, @@ -2261,7 +2250,7 @@ def render_README( err ) ) - except json.decoder.JSONDecodeError: # type: ignore + except json.decoder.JSONDecodeError: # type: ignore azure_build_id_from_token(forge_config) logger.debug("README") diff --git a/conda_smithy/feedstock_io.py b/conda_smithy/feedstock_io.py index dcc33b06b..9ae74f4fe 100644 --- a/conda_smithy/feedstock_io.py +++ b/conda_smithy/feedstock_io.py @@ -4,17 +4,10 @@ import shutil import stat from io import TextIOWrapper -from typing import ( - Iterator, - Optional, - Any, - Union -) +from typing import Iterator, Optional, Any, Union -def get_repo( - path: str, search_parent_directories: bool = True -): +def get_repo(path: str, search_parent_directories: bool = True): repo = None try: import git diff --git a/conda_smithy/lint_recipe.py b/conda_smithy/lint_recipe.py index d1c585e07..954398baa 100644 --- a/conda_smithy/lint_recipe.py +++ b/conda_smithy/lint_recipe.py @@ -131,7 +131,9 @@ def lint_section_order( lambda s: "'%s'" % s, section_order_sorted ) section_order_sorted_str_joined = ", ".join(section_order_sorted_str) - section_order_sorted_str_with_brackets = "[" + section_order_sorted_str_joined + "]" + section_order_sorted_str_with_brackets = ( + "[" + section_order_sorted_str_joined + "]" + ) lints.append( "The top level meta keys are in an unexpected order. " "Expecting {}.".format(section_order_sorted_str_with_brackets) @@ -839,7 +841,7 @@ def check_pins_build_and_requirements(top_level): cmd + shell_scripts, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, - env={ # type: ignore + env={ # type: ignore "PATH": os.getenv("PATH") }, # exclude other env variables to protect against token leakage ) @@ -1354,7 +1356,7 @@ def jinja_lines(lines: TextIOWrapper) -> Iterator[Tuple[str, int]]: yield line, i -def _format_validation_msg(error: "jsonschema.ValidationError") -> str: # type: ignore +def _format_validation_msg(error: "jsonschema.ValidationError") -> str: # type: ignore """Use the data on the validation error to generate improved reporting. If available, get the help URL from the first level of the JSON path: diff --git a/conda_smithy/schema.py b/conda_smithy/schema.py index 4a440cfeb..80fdd1987 100644 --- a/conda_smithy/schema.py +++ b/conda_smithy/schema.py @@ -12,7 +12,7 @@ from conda.base.constants import KNOWN_SUBDIRS try: - from enum import StrEnum # type: ignore + from enum import StrEnum # type: ignore except ImportError: from backports.strenum import StrEnum @@ -371,7 +371,7 @@ class BotConfig(BaseModel): ) version_updates: Optional[BotConfigVersionUpdates] = Field( - default_factory=BotConfigVersionUpdates, # type: ignore + default_factory=BotConfigVersionUpdates, # type: ignore description="Bot config for version update PRs", ) @@ -467,20 +467,21 @@ class DefaultTestPlatforms(StrEnum): native = "native" native_and_emulated = "native_and_emulated" + buildPlatform_fields: Dict[str, Any] = { - platform.value: (Optional[Platforms], Field(default=platform.value)) - for platform in Platforms - } + platform.value: (Optional[Platforms], Field(default=platform.value)) + for platform in Platforms +} BuildPlatform = create_model( "build_platform", **buildPlatform_fields, ) OSVersion_fields: Dict[str, Any] = { - platform.value: (Optional[Union[str, Nullable]], Field(default=None)) - for platform in Platforms - if platform.value.startswith("linux") - } + platform.value: (Optional[Union[str, Nullable]], Field(default=None)) + for platform in Platforms + if platform.value.startswith("linux") +} OSVersion = create_model( "os_version", **OSVersion_fields, @@ -489,15 +490,15 @@ class DefaultTestPlatforms(StrEnum): ProviderType = Union[List[CIservices], CIservices, bool, Nullable] provider_fields: Dict[str, Any] = dict( - [ - (str(plat), (Optional[ProviderType], Field(default=None))) - for plat in list(PlatformsAliases) + list(Platforms) - ] - + [ - (str(plat), (Optional[ProviderType], Field(default="azure"))) - for plat in ("linux_64", "osx_64", "win_64") - ] - ) + [ + (str(plat), (Optional[ProviderType], Field(default=None))) + for plat in list(PlatformsAliases) + list(Platforms) + ] + + [ + (str(plat), (Optional[ProviderType], Field(default="azure"))) + for plat in ("linux_64", "osx_64", "win_64") + ] +) Provider = create_model( "provider", **provider_fields, @@ -596,7 +597,7 @@ class ConfigModel(BaseModel): ) bot: Optional[BotConfig] = Field( - default_factory=BotConfig, # type: ignore + default_factory=BotConfig, # type: ignore description=cleandoc( """ This dictates the behavior of the conda-forge auto-tick bot which issues @@ -644,7 +645,7 @@ class ConfigModel(BaseModel): ), ) - build_platform: Optional[BuildPlatform] = Field( # type: ignore + build_platform: Optional[BuildPlatform] = Field( # type: ignore default_factory=BuildPlatform, description=cleandoc( """ @@ -738,7 +739,7 @@ class ConfigModel(BaseModel): ), ) - noarch_platforms: Optional[Union[Platforms, List[Platforms]]] = Field( # type: ignore + noarch_platforms: Optional[Union[Platforms, List[Platforms]]] = Field( # type: ignore default_factory=lambda: ["linux_64"], description=cleandoc( """ @@ -761,7 +762,7 @@ class ConfigModel(BaseModel): ), ) - os_version: Optional[OSVersion] = Field( # type: ignore + os_version: Optional[OSVersion] = Field( # type: ignore default_factory=OSVersion, description=cleandoc( """ @@ -779,7 +780,7 @@ class ConfigModel(BaseModel): ), ) - provider: Optional[Provider] = Field( # type: ignore + provider: Optional[Provider] = Field( # type: ignore default_factory=Provider, description=cleandoc( """ diff --git a/conda_smithy/utils.py b/conda_smithy/utils.py index 73e0e05a7..ee65ab29b 100644 --- a/conda_smithy/utils.py +++ b/conda_smithy/utils.py @@ -10,11 +10,7 @@ from collections import defaultdict from contextlib import contextmanager from conda_build.metadata import MetaData -from typing import ( - Dict, - Union, - Any -) +from typing import Dict, Union, Any import ruamel.yaml from ruamel.yaml.comments import CommentedMap diff --git a/conda_smithy/validate_schema.py b/conda_smithy/validate_schema.py index 450b790e6..137be37a5 100644 --- a/conda_smithy/validate_schema.py +++ b/conda_smithy/validate_schema.py @@ -46,13 +46,16 @@ def get_validator_class(): def validate_json_schema( config: Union[ CommentedMap, - Dict[str, Union[ - bool, + Dict[ str, - List[str], - Dict[str, bool], - Dict[str, Dict[str, str]] - ]] + Union[ + bool, + str, + List[str], + Dict[str, bool], + Dict[str, Dict[str, str]], + ], + ], ], schema_file: Optional[Path], ) -> tuple: diff --git a/conda_smithy/variant_algebra.py b/conda_smithy/variant_algebra.py index 539137159..0f0e8cdd8 100644 --- a/conda_smithy/variant_algebra.py +++ b/conda_smithy/variant_algebra.py @@ -78,7 +78,7 @@ def variant_key_add( v_left: Union[List[str], List[float]], v_right: Union[List[str], List[float]], ordering: Optional[List[str]] = None, -) -> List[Union[str,float]]: +) -> List[Union[str, float]]: """Version summation adder. This takes the higher version of the two things. diff --git a/news/1957_add_typing.rst b/news/1957_add_typing.rst new file mode 100644 index 000000000..40d3195e7 --- /dev/null +++ b/news/1957_add_typing.rst @@ -0,0 +1,23 @@ +**Added:** + +* + +**Changed:** + +* Added typing to conda_smithy and tests files + +**Deprecated:** + +* + +**Removed:** + +* + +**Fixed:** + +* + +**Security:** + +* diff --git a/tests/test_feedstock_io.py b/tests/test_feedstock_io.py index bb7da7f19..e367d966d 100644 --- a/tests/test_feedstock_io.py +++ b/tests/test_feedstock_io.py @@ -24,9 +24,7 @@ def keep_dir(dirname: str): fh.write("") -def parameterize() -> ( - Iterator[tuple] -): +def parameterize() -> Iterator[tuple]: for pathfunc in [ lambda pth, tmp_dir: os.path.relpath(pth, tmp_dir), lambda pth, tmp_dir: pth,