Skip to content

Commit

Permalink
BUILD: add support for Python 3.10 (#376)
Browse files Browse the repository at this point in the history
* BUILD: add support for Python 3.10

* BUILD: use Python 3.10 for pre-commit checks

* BUILD: use Python 3.10.14 for dev environment and min matrix test

* REFACTOR: use typing backports for Python 3.10

* REFACTOR: use gather instead of TaskGroup for Python 3.10

* API: recognize type special forms in Python 3.10

* BUILD: update typing_inspect to 0.9 in environment.yml
  • Loading branch information
j-ittner authored Jun 25, 2024
1 parent 7020229 commit 430b686
Show file tree
Hide file tree
Showing 19 changed files with 256 additions and 167 deletions.
21 changes: 16 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
repos:
- repo: https://github.com/asottile/pyupgrade
rev: v3.16.0
hooks:
- id: pyupgrade
args: [--py310-plus]

- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort

- repo: https://github.com/psf/black
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.4.2
hooks:
- id: black
language: python
language_version: python311
language_version: python310

- repo: https://github.com/pycqa/flake8
rev: 7.0.0
Expand All @@ -18,7 +24,7 @@ repos:
name: flake8
entry: flake8 --config tox.ini
language: python
language_version: python311
language_version: python310
additional_dependencies:
- flake8-comprehensions ~= 3.10
types: [ python ]
Expand All @@ -37,8 +43,13 @@ repos:
rev: v1.10.0
hooks:
- id: mypy
files: src|sphinx|test
entry: mypy src/ test/ sphinx/
args: [--config-file, pyproject.toml]
files: \.pyi?$
language: python
language_version: python311
language_version: python310
pass_filenames: false
additional_dependencies:
- numpy~=1.24
- pytest
- packaging
7 changes: 6 additions & 1 deletion RELEASE_NOTES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ Release Notes
-------------

*pytools* 3.0 adds support for language features introduced up to and including
Python 3.11, and drops support for Python versions.
Python 3.10, and drops support for Python versions.

*pytools* 3.0.1
~~~~~~~~~~~~~~~

- BUILD: add support for Python 3.10


*pytools* 3.0.0
Expand Down
52 changes: 29 additions & 23 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ stages:
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '3.11'
displayName: 'use Python 3.11'
versionSpec: '3.10'
displayName: 'use Python 3.10'
- script: |
python -m pip install isort~=5.12
python -m isort --check --diff .
Expand All @@ -62,8 +62,8 @@ stages:
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '3.11'
displayName: 'use Python 3.11'
versionSpec: '3.10'
displayName: 'use Python 3.10'
- script: |
python -m pip install black~=24.4.2
python -m black --check .
Expand All @@ -73,8 +73,8 @@ stages:
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '3.11'
displayName: 'use Python 3.11'
versionSpec: '3.10'
displayName: 'use Python 3.10'
- script: |
python -m pip install flake8~=7.0 flake8-comprehensions~=3.10
python -m flake8 --config tox.ini -v .
Expand All @@ -84,11 +84,17 @@ stages:
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '3.11'
displayName: 'use Python 3.11'
versionSpec: '3.10'
displayName: 'use Python 3.10'
- script: |
python -m pip install mypy~=1.10.0 numpy~=1.24
python -m mypy src
# package dependencies for mypy
dependencies=(
numpy~=1.24
packaging
pytest
)
python -m pip install mypy "${dependencies[@]}"
python -m mypy src --config-file pyproject.toml
displayName: 'Run mypy'
# detect whether the build config (pyproject.toml) was changed -> then we must run a build test
Expand Down Expand Up @@ -144,8 +150,8 @@ stages:
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '3.11'
displayName: 'use Python 3.11'
versionSpec: '3.10'
displayName: 'use Python 3.10'

- checkout: self

Expand Down Expand Up @@ -223,7 +229,7 @@ stages:
BUILD_SYSTEM: 'conda'
PKG_DEPENDENCIES: 'max'
minimum_dependencies_tox:
FACET_V_PYTHON_BUILD: '=3.11'
FACET_V_PYTHON_BUILD: '=3.10'
BUILD_SYSTEM: 'tox'
PKG_DEPENDENCIES: 'min'
maximum_dependencies_tox:
Expand Down Expand Up @@ -305,23 +311,23 @@ stages:
strategy:
matrix:
default_dependencies_conda:
FACET_V_PYTHON_BUILD: '=3.11'
FACET_V_PYTHON_BUILD: '=3.10'
BUILD_SYSTEM: 'conda'
PKG_DEPENDENCIES: 'default'
minimum_dependencies_conda:
FACET_V_PYTHON_BUILD: '=3.11'
FACET_V_PYTHON_BUILD: '=3.10'
BUILD_SYSTEM: 'conda'
PKG_DEPENDENCIES: 'min'
maximum_dependencies_conda:
FACET_V_PYTHON_BUILD: '=3.12'
BUILD_SYSTEM: 'conda'
PKG_DEPENDENCIES: 'max'
default_dependencies_tox:
FACET_V_PYTHON_BUILD: '=3.11'
FACET_V_PYTHON_BUILD: '=3.10'
BUILD_SYSTEM: 'tox'
PKG_DEPENDENCIES: 'default'
minimum_dependencies_tox:
FACET_V_PYTHON_BUILD: '=3.11'
FACET_V_PYTHON_BUILD: '=3.10'
BUILD_SYSTEM: 'tox'
PKG_DEPENDENCIES: 'min'
maximum_dependencies_tox:
Expand Down Expand Up @@ -441,8 +447,8 @@ stages:
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '3.11'
displayName: 'use Python 3.11'
versionSpec: '3.10'
displayName: 'use Python 3.10'

- checkout: pytools
- checkout: self
Expand Down Expand Up @@ -506,8 +512,8 @@ stages:
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '3.11'
displayName: 'use Python 3.11'
versionSpec: '3.10'
displayName: 'use Python 3.10'

- checkout: pytools
- checkout: self
Expand Down Expand Up @@ -634,8 +640,8 @@ stages:
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '3.11'
displayName: 'use Python 3.11'
versionSpec: '3.10'
displayName: 'use Python 3.10'

- task: InstallSSHKey@0
inputs:
Expand Down
4 changes: 2 additions & 2 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ dependencies:
- matplotlib ~= 3.6
- numpy ~= 1.24
- pandas ~= 2.0
- python ~= 3.10
- python ~= 3.10.14
- scipy ~= 1.10
- typing_extensions ~= 4.3
- typing_inspect ~= 0.7
- typing_inspect ~= 0.9
# test
- pytest ~= 7.2.1
- pytest-cov ~= 2.12.1
Expand Down
37 changes: 19 additions & 18 deletions make.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
import sys
import warnings
from abc import ABCMeta, abstractmethod
from collections.abc import Collection, Iterator, Mapping
from glob import glob
from traceback import print_exc
from typing import Any, Collection, Dict, Iterator, List, Mapping, Set, cast
from typing import Any, cast
from urllib import request
from urllib.error import HTTPError
from xml.etree import ElementTree
Expand Down Expand Up @@ -160,7 +161,7 @@ def get_pyproject_toml(self) -> Mapping[str, Any]:
os.environ[FACET_PATH_ENV], self.project, "pyproject.toml"
)
log(f"Reading build configuration from {pyproject_toml_path}")
with open(pyproject_toml_path, "rt") as f:
with open(pyproject_toml_path) as f:
self.pyproject_toml = pyproject_toml = toml.load(f)

return pyproject_toml
Expand All @@ -184,7 +185,7 @@ def validate_release_version(self) -> None:

log(f"Testing package version: {package} {new_version}")

released_versions: List[Version] = self._get_existing_releases(package)
released_versions: list[Version] = self._get_existing_releases(package)

if new_version in released_versions:
raise AssertionError(
Expand Down Expand Up @@ -215,7 +216,7 @@ def validate_release_version(self) -> None:
f"release of major/minor version {new_version} can go ahead"
)

def _get_existing_releases(self, package: str) -> List[Version]:
def _get_existing_releases(self, package: str) -> list[Version]:
releases_uri = f"https://pypi.org/rss/project/{package}/releases.xml"
log(f"Getting existing releases from {releases_uri}")
try:
Expand All @@ -234,7 +235,7 @@ def _get_existing_releases(self, package: str) -> List[Version]:
tree = ElementTree.fromstring(releases_xml)
releases_nodes = tree.findall(path=".//channel//item//title")

released_versions: List[Version] = sorted(
released_versions: list[Version] = sorted(
Version(r) for r in [r.text for r in releases_nodes]
)

Expand All @@ -256,7 +257,7 @@ def expose_package_dependencies(self) -> Mapping[str, str]:

requirements_to_expose = self._get_requirements_to_expose()

environment_version_variables: Dict[str, str] = {
environment_version_variables: dict[str, str] = {
# replace non-word characters with '_' to make valid environment variable
# names
(
Expand All @@ -270,7 +271,7 @@ def expose_package_dependencies(self) -> Mapping[str, str]:
export_environment_variable(name=package, value=version)

# get packages to be built from source
build_no_binaries: List[str] = (
build_no_binaries: list[str] = (
self.get_pyproject_toml()[TOML_BUILD]
.get(TOML_NO_BINARY, {})
.get(self.dependency_type, [])
Expand Down Expand Up @@ -303,7 +304,7 @@ def _get_run_dependencies(self) -> Mapping[str, str]:
flit_metadata = self.get_pyproject_toml()[TOML_TOOL][TOML_FLIT][TOML_METADATA]

python_version = flit_metadata[TOML_REQUIRES_PYTHON]
run_dependencies: Dict[str, str] = {
run_dependencies: dict[str, str] = {
name: validate_pip_version_spec(
dependency_type=DEP_DEFAULT, package=name, spec=version.lstrip()
)
Expand All @@ -328,12 +329,12 @@ def _get_requirements_to_expose(self) -> Mapping[str, str]:

# get full project specification from the TOML file
# get the matrix test dependencies (min and max)
build_matrix_definition: Dict[str, Dict[str, str]] = self.get_pyproject_toml()[
build_matrix_definition: dict[str, dict[str, str]] = self.get_pyproject_toml()[
TOML_BUILD
][TOML_MATRIX]

def get_matrix_dependencies(matrix_type: str) -> Dict[str, str]:
dependencies: Dict[str, str] = build_matrix_definition.get(matrix_type, {})
def get_matrix_dependencies(matrix_type: str) -> dict[str, str]:
dependencies: dict[str, str] = build_matrix_definition.get(matrix_type, {})
if not dependencies:
return {}
return {
Expand All @@ -345,11 +346,11 @@ def get_matrix_dependencies(matrix_type: str) -> Dict[str, str]:
for name, version in dependencies.items()
}

min_dependencies: Dict[str, str] = get_matrix_dependencies(DEP_MIN)
max_dependencies: Dict[str, str] = get_matrix_dependencies(DEP_MAX)
min_dependencies: dict[str, str] = get_matrix_dependencies(DEP_MIN)
max_dependencies: dict[str, str] = get_matrix_dependencies(DEP_MAX)

# check that the min and max dependencies supersede all default dependencies
dependencies_not_covered_in_matrix: Set[str] = (
dependencies_not_covered_in_matrix: set[str] = (
run_dependencies.keys() - min_dependencies.keys()
) | (run_dependencies.keys() - max_dependencies.keys())

Expand Down Expand Up @@ -556,7 +557,7 @@ def build(self, exposed_package_dependencies: Mapping[str, str]) -> None:
for package in glob(os.path.join(project_repo_path, package_glob))
]
# store index.html
with open(project_index_html_path, "wt") as f:
with open(project_index_html_path, "w") as f:
f.writelines(package_file_links)

log(f"Local PyPi Index created at: {pypi_index_path}")
Expand Down Expand Up @@ -596,8 +597,8 @@ def _patch_tox_ini(self, exposed_version_variables: Collection[str]) -> str:
# file, unless they reference a facet dependency environment variable which
# has not been exported

removed_lines: List[str] = []
with open(tox_ini_path, "rt") as f_in, open(tox_ini_tmp_path, "wt") as f_out:
removed_lines: list[str] = []
with open(tox_ini_path) as f_in, open(tox_ini_tmp_path, "w") as f_out:
for line in f_in.readlines():
# get all environment variables referenced in the line
# these use the tox.ini `{env:` syntax and start with the
Expand Down Expand Up @@ -641,7 +642,7 @@ def get_projects_root_path() -> str:
return facet_path


def get_known_projects() -> Set[str]:
def get_known_projects() -> set[str]:
dir_entries: Iterator[os.DirEntry] = cast(
Iterator[os.DirEntry], os.scandir(get_projects_root_path())
)
Expand Down
33 changes: 0 additions & 33 deletions mypy.ini

This file was deleted.

Loading

0 comments on commit 430b686

Please sign in to comment.