Skip to content

Commit

Permalink
Use Python 3.12 for internal code (#2222)
Browse files Browse the repository at this point in the history
* Use Python 3.12 for internal code

* Add changelog entry
  • Loading branch information
mathbunnyru authored Feb 18, 2025
1 parent e570478 commit 80b7162
Show file tree
Hide file tree
Showing 15 changed files with 33 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .github/actions/create-dev-env/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ runs:
- name: Set Up Python 🐍
uses: actions/setup-python@v5
with:
python-version: "3.12"
python-version: 3.12

- name: Install Dev Dependencies 📦
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Set Up Python 🐍
uses: actions/setup-python@v5
with:
python-version: 3.x
python-version: 3.12

- name: Install pre-commit 📦
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/sphinx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
- name: Set Up Python 🐍
uses: actions/setup-python@v5
with:
python-version: 3.9
python-version: 3.12

- name: Install Doc Dependencies 📦
run: |
Expand Down
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ repos:
rev: v3.19.1
hooks:
- id: pyupgrade
args: [--py39-plus]
args: [--py312-plus]

# Automatically sort python imports
- repo: https://github.com/PyCQA/isort
Expand All @@ -31,7 +31,7 @@ repos:
rev: 25.1.0
hooks:
- id: black
args: [--target-version=py39]
args: [--target-version=py312]

# Check python code static typing
- repo: https://github.com/pre-commit/mirrors-mypy
Expand Down Expand Up @@ -141,10 +141,10 @@ repos:
rev: 1.9.1
hooks:
- id: nbqa-pyupgrade
args: [--py39-plus]
args: [--py312-plus]
- id: nbqa-isort
- id: nbqa-black
args: [--target-version=py39]
args: [--target-version=py312]
- id: nbqa-flake8

# Run black on python code blocks in documentation files.
Expand All @@ -156,7 +156,7 @@ repos:
# the python code blocks include jupyter-specific additions such as % or !
# See https://github.com/adamchainz/blacken-docs/issues/127 for an upstream
# feature request about this.
args: [--target-version=py39, --skip-errors]
args: [--target-version=py312, --skip-errors]

# pre-commit.ci config reference: https://pre-commit.ci/#configuration
ci:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Affected: all images.
- **Non-breaking:** don't create extra free space in runners for cuda images ([#2218](https://github.com/jupyter/docker-stacks/pull/2218)).
- **Non-breaking:** revert "Pin some packages to fix `r-notebook` and `datascience-notebook` under aarch64" ([#2220](https://github.com/jupyter/docker-stacks/pull/2220)).
- **Non-breaking:** Simplify and improve `test_packages.py` ([#2219](https://github.com/jupyter/docker-stacks/pull/2219)).
- **Non-breaking:** Use Python 3.12 for internal code ([#2222](https://github.com/jupyter/docker-stacks/pull/2222)).

## 2025-02-17

Expand Down
2 changes: 1 addition & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# We use mypy as part of pre-commit checks

[mypy]
python_version = 3.9
python_version = 3.12
follow_imports = error
strict = True
no_incremental = True
Expand Down
9 changes: 4 additions & 5 deletions tagging/docker_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# Distributed under the terms of the Modified BSD License.
import logging
from types import TracebackType
from typing import Optional

import docker
from docker.models.containers import Container
Expand All @@ -17,7 +16,7 @@ def __init__(
docker_client: docker.DockerClient = docker.from_env(),
command: str = "sleep infinity",
):
self.container: Optional[Container] = None
self.container: Container | None = None
self.image_name: str = image_name
self.command: str = command
self.docker_client: docker.DockerClient = docker_client
Expand All @@ -34,9 +33,9 @@ def __enter__(self) -> Container:

def __exit__(
self,
exc_type: Optional[type[BaseException]],
exc_val: Optional[BaseException],
exc_tb: Optional[TracebackType],
exc_type: type[BaseException] | None,
exc_val: BaseException | None,
exc_tb: TracebackType | None,
) -> None:
assert self.container is not None
LOGGER.info(f"Removing container {self.container.name} ...")
Expand Down
3 changes: 1 addition & 2 deletions tagging/get_taggers_and_manifests.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
from typing import Optional

from tagging.images_hierarchy import ALL_IMAGES
from tagging.manifests import ManifestInterface
from tagging.taggers import TaggerInterface


def get_taggers_and_manifests(
short_image_name: Optional[str],
short_image_name: str | None,
) -> tuple[list[TaggerInterface], list[ManifestInterface]]:
if short_image_name is None:
return [[], []] # type: ignore
Expand Down
3 changes: 1 addition & 2 deletions tagging/images_hierarchy.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
from dataclasses import dataclass, field
from typing import Optional

from tagging.manifests import (
AptPackagesManifest,
Expand Down Expand Up @@ -32,7 +31,7 @@

@dataclass
class ImageDescription:
parent_image: Optional[str]
parent_image: str | None
taggers: list[TaggerInterface] = field(default_factory=list)
manifests: list[ManifestInterface] = field(default_factory=list)

Expand Down
17 changes: 8 additions & 9 deletions tests/base-notebook/test_healthcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# Distributed under the terms of the Modified BSD License.
import logging
import time
from typing import Optional

import pytest # type: ignore

Expand Down Expand Up @@ -56,9 +55,9 @@
)
def test_healthy(
container: TrackedContainer,
env: Optional[list[str]],
cmd: Optional[list[str]],
user: Optional[str],
env: list[str] | None,
cmd: list[str] | None,
user: str | None,
) -> None:
running_container = container.run_detached(
tty=True,
Expand Down Expand Up @@ -104,9 +103,9 @@ def test_healthy(
)
def test_healthy_with_proxy(
container: TrackedContainer,
env: Optional[list[str]],
cmd: Optional[list[str]],
user: Optional[str],
env: list[str] | None,
cmd: list[str] | None,
user: str | None,
) -> None:
running_container = container.run_detached(
tty=True,
Expand Down Expand Up @@ -142,8 +141,8 @@ def test_healthy_with_proxy(
)
def test_not_healthy(
container: TrackedContainer,
env: Optional[list[str]],
cmd: Optional[list[str]],
env: list[str] | None,
cmd: list[str] | None,
) -> None:
running_container = container.run_detached(
tty=True,
Expand Down
3 changes: 1 addition & 2 deletions tests/base-notebook/test_start_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# Distributed under the terms of the Modified BSD License.
import logging
import time
from typing import Optional

import pytest # type: ignore
import requests
Expand Down Expand Up @@ -32,7 +31,7 @@
def test_start_notebook(
container: TrackedContainer,
http_client: requests.Session,
env: Optional[list[str]],
env: list[str] | None,
expected_command: str,
expected_start: bool,
expected_warnings: list[str],
Expand Down
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import os
import socket
from contextlib import closing
from typing import Any, Optional
from typing import Any

import docker
import pytest # type: ignore
Expand Down Expand Up @@ -72,7 +72,7 @@ def __init__(
image_name: str,
**kwargs: Any,
):
self.container: Optional[Container] = None
self.container: Container | None = None
self.docker_client: docker.DockerClient = docker_client
self.image_name: str = image_name
self.kwargs: Any = kwargs
Expand Down
3 changes: 1 addition & 2 deletions tests/docker-stacks-foundation/test_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@
"""

import logging
from collections.abc import Iterable
from typing import Callable
from collections.abc import Callable, Iterable

import pytest # type: ignore

Expand Down
3 changes: 1 addition & 2 deletions tests/images_hierarchy.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
from pathlib import Path
from typing import Optional

THIS_DIR = Path(__file__).parent.resolve()

Expand All @@ -23,7 +22,7 @@


def get_test_dirs(
short_image_name: Optional[str],
short_image_name: str | None,
) -> list[Path]:
if short_image_name is None:
return []
Expand Down
8 changes: 4 additions & 4 deletions tests/package_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import re
from collections import defaultdict
from itertools import chain
from typing import Any, Optional
from typing import Any

from docker.models.containers import Container
from tabulate import tabulate
Expand All @@ -44,9 +44,9 @@ def __init__(self, container: TrackedContainer):
self.running_container: Container = CondaPackageHelper.start_container(
container
)
self.requested: Optional[dict[str, set[str]]] = None
self.installed: Optional[dict[str, set[str]]] = None
self.available: Optional[dict[str, set[str]]] = None
self.requested: dict[str, set[str]] | None = None
self.installed: dict[str, set[str]] | None = None
self.available: dict[str, set[str]] | None = None
self.comparison: list[dict[str, str]] = []

@staticmethod
Expand Down

0 comments on commit 80b7162

Please sign in to comment.