Skip to content

Commit

Permalink
Update to python>=3.9 (#2180)
Browse files Browse the repository at this point in the history
* Update to py>=3.9; add pyupgrade

* Update .pre-commit-config.yaml

* Update news/python3.9.rst

Co-authored-by: jaimergp <jaimergp@users.noreply.github.com>

---------

Co-authored-by: Matthew R. Becker <beckermr@users.noreply.github.com>
Co-authored-by: jaimergp <jaimergp@users.noreply.github.com>
  • Loading branch information
3 people authored Dec 5, 2024
1 parent bf12173 commit d3fd836
Show file tree
Hide file tree
Showing 15 changed files with 110 additions and 112 deletions.
9 changes: 4 additions & 5 deletions conda_smithy/azure_ci_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import typing
import warnings

from msrest.authentication import Authentication, BasicAuthentication
Expand Down Expand Up @@ -85,7 +84,7 @@ def get_service_endpoint(config: AzureConfig = default_config):
service_endpoint_client = ServiceEndpointClient(
base_url=config.instance_base_url, creds=config.credentials
)
endpoints: typing.List[ServiceEndpoint] = (
endpoints: list[ServiceEndpoint] = (
service_endpoint_client.get_service_endpoints(
project=config.project_name, type="GitHub"
)
Expand All @@ -99,7 +98,7 @@ def get_service_endpoint(config: AzureConfig = default_config):

def get_queues(
config: AzureConfig = default_config,
) -> typing.List[TaskAgentQueue]:
) -> list[TaskAgentQueue]:
aclient = TaskAgentClient(config.instance_base_url, config.credentials)
return aclient.get_agent_queues(config.project_name)

Expand Down Expand Up @@ -227,7 +226,7 @@ def register_repo(github_org, repo_name, config: AzureConfig = default_config):
)

# clean up existing builds for the same feedstock if present
existing_definitions: typing.List[BuildDefinitionReference] = (
existing_definitions: list[BuildDefinitionReference] = (
bclient.get_definitions(project=config.project_name, name=repo_name)
)
if existing_definitions:
Expand All @@ -253,7 +252,7 @@ def build_client(config: AzureConfig = default_config) -> BuildClient:
def repo_registered(
github_org: str, repo_name: str, config: AzureConfig = default_config
) -> bool:
existing_definitions: typing.List[BuildDefinitionReference] = build_client(
existing_definitions: list[BuildDefinitionReference] = build_client(
config
).get_definitions(project=config.project_name, name=repo_name)

Expand Down
16 changes: 8 additions & 8 deletions conda_smithy/cirun_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""

from functools import lru_cache
from typing import Any, Dict, List, Optional
from typing import Any, Optional

from cirun import Cirun

Expand All @@ -29,7 +29,7 @@ def get_cirun_installation_id(owner: str) -> int:
raise ValueError(f"cirun not found for owner {owner}")


def enable_cirun_for_project(owner: str, repo: str) -> Dict[str, Any]:
def enable_cirun_for_project(owner: str, repo: str) -> dict[str, Any]:
"""Enable the cirun.io Github Application for a particular repository."""
print(f"Enabling cirun for {owner}/{repo} ...")
cirun = _get_cirun_client()
Expand All @@ -41,15 +41,15 @@ def enable_cirun_for_project(owner: str, repo: str) -> Dict[str, Any]:
def add_repo_to_cirun_resource(
owner: str,
repo: str,
resources: List[str],
teams: List,
roles: List,
resources: list[str],
teams: list,
roles: list,
users_from_json: Optional[str] = None,
cirun_policy_args: Optional[List[str]] = None,
) -> Dict[str, Any]:
cirun_policy_args: Optional[list[str]] = None,
) -> dict[str, Any]:
"""Grant access to a cirun resource to a particular repository, with a particular policy."""
cirun = _get_cirun_client()
policy_args: Optional[Dict[str, Any]] = None
policy_args: Optional[dict[str, Any]] = None
if cirun_policy_args and "pull_request" in cirun_policy_args:
policy_args = {"pull_request": True}
print(
Expand Down
3 changes: 1 addition & 2 deletions conda_smithy/configure_feedstock.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from itertools import chain, product
from os import fspath
from pathlib import Path, PurePath
from typing import Dict

import requests
import yaml
Expand Down Expand Up @@ -697,7 +696,7 @@ def _sanitize_remote_ci_setup(remote_ci_setup):

def _sanitize_build_tool_deps_as_dict(
forge_dir, forge_config
) -> Dict[str, str]:
) -> dict[str, str]:
"""
Aggregates different sources of build tool dependencies in
mapping of package names to OR-merged version constraints.
Expand Down
16 changes: 7 additions & 9 deletions conda_smithy/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,9 @@ def configure_github_team(meta, gh_repo, org, feedstock_name, remove=True):
]

maintainers = set(meta.meta.get("extra", {}).get("recipe-maintainers", []))
maintainers = set(maintainer.lower() for maintainer in maintainers)
maintainer_teams = set(m for m in maintainers if "/" in m)
maintainers = set(m for m in maintainers if "/" not in m)
maintainers = {maintainer.lower() for maintainer in maintainers}
maintainer_teams = {m for m in maintainers if "/" in m}
maintainers = {m for m in maintainers if "/" not in m}

# Try to get team or create it if it doesn't exist.
team_name = feedstock_name
Expand All @@ -287,7 +287,7 @@ def configure_github_team(meta, gh_repo, org, feedstock_name, remove=True):
)
fs_team.add_to_repos(gh_repo)

current_maintainers = set([e.login.lower() for e in fs_team.get_members()])
current_maintainers = {e.login.lower() for e in fs_team.get_members()}

# Get the all-members team
description = f"All of the awesome {org.login} contributors!"
Expand All @@ -309,17 +309,15 @@ def configure_github_team(meta, gh_repo, org, feedstock_name, remove=True):
remove_membership(fs_team, old_maintainer)

# Add any new maintainer teams
maintainer_teams = set(
maintainer_teams = {
m.split("/")[1]
for m in maintainer_teams
if m.startswith(str(org.login))
)
}
current_maintainer_team_objs = {
team.slug: team for team in current_maintainer_teams
}
current_maintainer_teams = set(
[team.slug for team in current_maintainer_teams]
)
current_maintainer_teams = {team.slug for team in current_maintainer_teams}
for new_team in maintainer_teams - current_maintainer_teams:
team = org.get_team_by_slug(new_team)
team.add_to_repos(gh_repo)
Expand Down
4 changes: 2 additions & 2 deletions conda_smithy/lint_recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from inspect import cleandoc
from pathlib import Path
from textwrap import indent
from typing import Any, List, Optional, Tuple
from typing import Any, Optional

import github
import github.Auth
Expand Down Expand Up @@ -113,7 +113,7 @@ def lintify_meta_yaml(
recipe_dir: Optional[str] = None,
conda_forge: bool = False,
recipe_version: int = 0,
) -> Tuple[List[str], List[str]]:
) -> tuple[list[str], list[str]]:
lints = []
hints = []
major_sections = list(meta.keys())
Expand Down
26 changes: 13 additions & 13 deletions conda_smithy/linter/conda_recipe_v1_linter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import re
from typing import Any, Dict, List, Optional
from typing import Any, Optional

from rattler_build_conda_compat.jinja.jinja import (
RecipeWithContext,
Expand Down Expand Up @@ -39,10 +39,10 @@

def lint_recipe_tests(
recipe_dir: Optional[str],
test_section: List[Dict[str, Any]],
outputs_section: List[Dict[str, Any]],
lints: List[str],
hints: List[str],
test_section: list[dict[str, Any]],
outputs_section: list[dict[str, Any]],
lints: list[str],
hints: list[str],
):
tests_lints = []
tests_hints = []
Expand Down Expand Up @@ -72,9 +72,9 @@ def lint_recipe_tests(


def hint_noarch_usage(
build_section: Dict[str, Any],
requirement_section: Dict[str, Any],
hints: List[str],
build_section: dict[str, Any],
requirement_section: dict[str, Any],
hints: list[str],
):
build_reqs = requirement_section.get("build", None)
if (
Expand Down Expand Up @@ -131,7 +131,7 @@ def get_recipe_version(recipe_content: RecipeWithContext) -> Optional[str]:

def lint_recipe_name(
recipe_content: RecipeWithContext,
lints: List[str],
lints: list[str],
) -> None:
name = get_recipe_name(recipe_content)

Expand All @@ -142,7 +142,7 @@ def lint_recipe_name(

def lint_package_version(
recipe_content: RecipeWithContext,
lints: List[str],
lints: list[str],
) -> None:
version = get_recipe_version(recipe_content)

Expand All @@ -154,10 +154,10 @@ def lint_package_version(

def lint_usage_of_selectors_for_noarch(
noarch_value: str,
requirements_section: Dict[str, Any],
build_section: Dict[str, Any],
requirements_section: dict[str, Any],
build_section: dict[str, Any],
noarch_platforms: bool,
lints: List[str],
lints: list[str],
):
for section in requirements_section:
section_requirements = requirements_section[section]
Expand Down
8 changes: 4 additions & 4 deletions conda_smithy/linter/hints.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import subprocess
import sys
from glob import glob
from typing import Any, Dict, List
from typing import Any

from conda_smithy.linter import conda_recipe_v1_linter
from conda_smithy.linter.errors import HINT_NO_ARCH
Expand All @@ -31,7 +31,7 @@ def hint_pip_usage(build_section, hints):


def hint_sources_should_not_mention_pypi_io_but_pypi_org(
sources_section: List[Dict[str, Any]], hints: List[str]
sources_section: list[dict[str, Any]], hints: list[str]
):
"""
Grayskull and conda-forge default recipe used to have pypi.io as a default,
Expand Down Expand Up @@ -181,12 +181,12 @@ def hint_check_spdx(about_section, hints):

with open(os.path.join(os.path.dirname(__file__), "licenses.txt")) as f:
expected_licenses = f.readlines()
expected_licenses = set([li.strip() for li in expected_licenses])
expected_licenses = {li.strip() for li in expected_licenses}
with open(
os.path.join(os.path.dirname(__file__), "license_exceptions.txt")
) as f:
expected_exceptions = f.readlines()
expected_exceptions = set([li.strip() for li in expected_exceptions])
expected_exceptions = {li.strip() for li in expected_exceptions}
if set(filtered_licenses) - expected_licenses:
hints.append(
"License is not an SPDX identifier (or a custom LicenseRef) nor an SPDX license expression.\n\n"
Expand Down
44 changes: 22 additions & 22 deletions conda_smithy/linter/lints.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import re
import tempfile
from collections.abc import Sequence
from typing import Any, Dict, List, Literal, Optional
from typing import Any, Literal, Optional

from conda.exceptions import InvalidVersionSpec
from conda.models.version import VersionOrder
Expand Down Expand Up @@ -33,8 +33,8 @@


def lint_section_order(
major_sections: List[str],
lints: List[str],
major_sections: list[str],
lints: list[str],
recipe_version: int = 0,
):
if recipe_version == 0:
Expand Down Expand Up @@ -89,10 +89,10 @@ def lint_recipe_maintainers(extra_section, lints):

def lint_recipe_have_tests(
recipe_dir: str,
test_section: List[Dict[str, Any]],
outputs_section: List[Dict[str, Any]],
lints: List[str],
hints: List[str],
test_section: list[dict[str, Any]],
outputs_section: list[dict[str, Any]],
lints: list[str],
hints: list[str],
recipe_version: int = 0,
):
if recipe_version == 1:
Expand Down Expand Up @@ -203,7 +203,7 @@ def lint_build_section_should_be_before_run(requirements_section, lints):


def lint_sources_should_have_hash(
sources_section: List[Dict[str, Any]], lints: List[str]
sources_section: list[dict[str, Any]], lints: list[str]
):
for source_section in sources_section:
if "url" in source_section and not (
Expand Down Expand Up @@ -249,10 +249,10 @@ def lint_should_be_empty_line(meta_fname, lints):


def lint_license_family_should_be_valid(
about_section: Dict[str, Any],
about_section: dict[str, Any],
license: str,
needed_families: List[str],
lints: List[str],
needed_families: list[str],
lints: list[str],
recipe_version: int = 0,
) -> None:
lint_msg = "license_file entry is missing, but is required."
Expand All @@ -269,8 +269,8 @@ def lint_license_family_should_be_valid(


def lint_recipe_name(
package_section: Dict[str, Any],
lints: List[str],
package_section: dict[str, Any],
lints: list[str],
):
recipe_name = package_section.get("name", "").strip()
lint_msg = _lint_recipe_name(recipe_name)
Expand Down Expand Up @@ -326,10 +326,10 @@ def lint_noarch(noarch_value: Optional[str], lints):

def lint_recipe_v1_noarch_and_runtime_dependencies(
noarch_value: Optional[Literal["python", "generic"]],
raw_requirements_section: Dict[str, Any],
build_section: Dict[str, Any],
raw_requirements_section: dict[str, Any],
build_section: dict[str, Any],
noarch_platforms: bool,
lints: List[str],
lints: list[str],
) -> None:
if noarch_value:
conda_recipe_v1_linter.lint_usage_of_selectors_for_noarch(
Expand Down Expand Up @@ -702,8 +702,8 @@ def lint_check_usage_of_whls(meta_fname, noarch_value, lints, hints):


def lint_rust_licenses_are_bundled(
build_reqs: Optional[List[str]],
lints: List[str],
build_reqs: Optional[list[str]],
lints: list[str],
recipe_version: int = 0,
):
if not build_reqs:
Expand All @@ -722,8 +722,8 @@ def lint_rust_licenses_are_bundled(


def lint_go_licenses_are_bundled(
build_reqs: Optional[List[str]],
lints: List[str],
build_reqs: Optional[list[str]],
lints: list[str],
recipe_version: int = 0,
):
if not build_reqs:
Expand Down Expand Up @@ -1008,8 +1008,8 @@ def sort_osx(versions):

def lint_recipe_is_parsable(
recipe_text: str,
lints: List[str],
hints: List[str],
lints: list[str],
hints: list[str],
recipe_version: int = 0,
):
parse_results = {}
Expand Down
Loading

0 comments on commit d3fd836

Please sign in to comment.