Skip to content

Commit

Permalink
use python3.10 conveniences
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-shields committed Apr 4, 2024
1 parent c1a8991 commit 19bd8f0
Show file tree
Hide file tree
Showing 25 changed files with 70 additions and 95 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-python@v1
with:
python-version: "3.9"
python-version: "3.10"
architecture: x64
- name: Setup Graphviz
uses: ts-graphviz/setup-graphviz@v1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-python@v1
with:
python-version: "3.9"
python-version: "3.10"
architecture: x64
- name: Setup Graphviz
uses: ts-graphviz/setup-graphviz@v1
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ jobs:
- ubuntu-latest
- windows-latest
python:
- "3.9"
- "3.10"
- "3.11"
steps:
Expand Down
2 changes: 1 addition & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ sphinx:
configuration: docs/conf.py
formats: all
python:
version: 3.8
version: 3.10
install:
- requirements: docs/requirements.txt
- path: .
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ version = "1.0.1"
[tool.poetry.dependencies]
networkx = "^2.5"
nxv = "^0.1.3"
python = "^3.8"
python = "^3.10"

[tool.poetry.dev-dependencies]
black = "^22.8"
Expand Down
21 changes: 11 additions & 10 deletions src/uberjob/_execution/run_physical.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
# limitations under the License.
#
"""Functionality for executing a physical plan"""
from typing import Any, Callable, NamedTuple, Optional
from collections.abc import Callable
from typing import Any, NamedTuple

from uberjob._errors import NodeError, create_chained_call_error
from uberjob._execution.run_function_on_graph import run_function_on_graph
Expand Down Expand Up @@ -55,7 +56,7 @@ def _create_bound_call(


def _create_bound_call_lookup_and_output_slot(
plan: Plan, output_node: Optional[Node] = None
plan: Plan, output_node: Node | None = None
):
result_lookup = {
node: node if type(node) is Literal else Slot(None)
Expand All @@ -81,9 +82,9 @@ def prep_run_physical(
plan: Plan,
*,
inplace: bool,
output_node: Optional[Node] = None,
retry: Optional[Callable[[Callable], Callable]] = None,
progress_observer: Optional[ProgressObserver] = None,
output_node: Node | None = None,
retry: Callable[[Callable], Callable] | None = None,
progress_observer: ProgressObserver | None = None,
):
bound_call_lookup, output_slot = _create_bound_call_lookup_and_output_slot(
plan, output_node
Expand Down Expand Up @@ -119,11 +120,11 @@ def run_physical(
plan: Plan,
*,
inplace: bool,
output_node: Optional[Node] = None,
retry: Optional[Callable[[Callable], Callable]] = None,
max_workers: Optional[int] = None,
max_errors: Optional[int] = 0,
scheduler: Optional[str] = None,
output_node: Node | None = None,
retry: Callable[[Callable], Callable] | None = None,
max_workers: int | None = None,
max_errors: int | None = 0,
scheduler: str | None = None,
progress_observer: ProgressObserver,
) -> Any:
_, output_slot, process, plan = prep_run_physical(
Expand Down
3 changes: 1 addition & 2 deletions src/uberjob/_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@
# limitations under the License.
#
import operator
from collections.abc import Generator
from collections.abc import Callable, Generator
from contextlib import contextmanager
from threading import RLock
from typing import Callable

from uberjob import _builtins
from uberjob._util import validation
Expand Down
2 changes: 1 addition & 1 deletion src/uberjob/_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def __getitem__(self, node: Node) -> ValueStore:
"""
return self.mapping[node].value_store

def get(self, node: Node) -> typing.Optional[ValueStore]:
def get(self, node: Node) -> ValueStore | None:
"""
Get the :class:`~uberjob.ValueStore` for a :class:`~uberjob.graph.Node` if it has one, or ``None``.
Expand Down
8 changes: 4 additions & 4 deletions src/uberjob/_rendering.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,13 @@ class Scope:


def render(
plan: typing.Union[Plan, Graph, tuple[Plan, typing.Optional[Node]]],
plan: Plan | Graph | tuple[Plan, Node | None],
*,
registry: Registry = None,
predicate: typing.Callable[[Node, dict], bool] = None,
level: typing.Optional[int] = None,
format: typing.Optional[str] = None
) -> typing.Optional[bytes]:
level: int | None = None,
format: str | None = None
) -> bytes | None:
"""
Use :mod:`nxv` to render a plan's symbolic call graph.
Expand Down
27 changes: 12 additions & 15 deletions src/uberjob/_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
#
import collections
import datetime as dt
from collections.abc import Iterable
from typing import Callable, Optional, Union
from collections.abc import Callable, Iterable

from uberjob._errors import CallError
from uberjob._execution.run_function_on_graph import NodeError
Expand Down Expand Up @@ -47,9 +46,7 @@ def _update_run_totals(plan: Plan, progress_observer: ProgressObserver) -> None:
progress_observer.increment_total(section="run", scope=scope, amount=count)


def _coerce_progress(
progress: Union[None, bool, Progress, Iterable[Progress]]
) -> Progress:
def _coerce_progress(progress: None | bool | Progress | Iterable[Progress]) -> Progress:
if not progress:
return null_progress
try:
Expand All @@ -66,7 +63,7 @@ def _coerce_progress(


def _coerce_retry(
retry: Union[None, int, Callable[[Callable], Callable]]
retry: None | int | Callable[[Callable], Callable]
) -> Callable[[Callable], Callable]:
if callable(retry):
return retry
Expand All @@ -77,16 +74,16 @@ def run(
plan: Plan,
*,
output=None,
registry: Optional[Registry] = None,
registry: Registry | None = None,
dry_run: bool = False,
max_workers: Optional[int] = None,
max_errors: Optional[int] = 0,
retry: Union[None, int, Callable[[Callable], Callable]] = None,
fresh_time: Optional[dt.datetime] = None,
progress: Union[None, bool, Progress, Iterable[Progress]] = True,
scheduler: Optional[str] = None,
transform_physical: Optional[Callable[[Plan, Node], tuple[Plan, Node]]] = None,
stale_check_max_workers: Optional[int] = None,
max_workers: int | None = None,
max_errors: int | None = 0,
retry: None | int | Callable[[Callable], Callable] = None,
fresh_time: dt.datetime | None = None,
progress: None | bool | Progress | Iterable[Progress] = True,
scheduler: str | None = None,
transform_physical: Callable[[Plan, Node], tuple[Plan, Node]] | None = None,
stale_check_max_workers: int | None = None,
):
"""
Run a :class:`~uberjob.Plan`.
Expand Down
2 changes: 1 addition & 1 deletion src/uberjob/_testing/test_mounted_file_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def copy_to_local(self, local_path):
with open(local_path, "wb") as f:
f.write(self.remote_store.read())

def get_modified_time(self) -> typing.Optional[dt.datetime]:
def get_modified_time(self) -> dt.datetime | None:
return self.remote_store.get_modified_time()

def __repr__(self):
Expand Down
3 changes: 1 addition & 2 deletions src/uberjob/_testing/test_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
# limitations under the License.
#
import datetime as dt
import typing

from uberjob._util import Missing, repr_helper
from uberjob._value_store import ValueStore
Expand Down Expand Up @@ -79,7 +78,7 @@ def write(self, value):
self.value = value
self.modified_time = dt.datetime.utcnow()

def get_modified_time(self) -> typing.Optional[dt.datetime]:
def get_modified_time(self) -> dt.datetime | None:
if not self.can_get_modified_time:
raise Exception("This test store cannot get modified time.")
return self.modified_time
Expand Down
17 changes: 8 additions & 9 deletions src/uberjob/_transformations/caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#
import collections
import datetime as dt
from typing import Optional

from uberjob._errors import NodeError, create_chained_call_error
from uberjob._execution.run_function_on_graph import run_function_on_graph
Expand All @@ -39,7 +38,7 @@ def __repr__(self):
Barrier = BarrierType()


def _to_naive_utc_time(value: Optional[dt.datetime]) -> Optional[dt.datetime]:
def _to_naive_utc_time(value: dt.datetime | None) -> dt.datetime | None:
return (
value.astimezone(dt.timezone.utc).replace(tzinfo=None)
if value and value.tzinfo
Expand All @@ -60,8 +59,8 @@ def _get_stale_nodes(
registry: Registry,
*,
retry,
max_workers: Optional[int] = None,
fresh_time: Optional[dt.datetime] = None,
max_workers: int | None = None,
fresh_time: dt.datetime | None = None,
progress_observer: ProgressObserver,
) -> set[Node]:
plan = prune_source_literals(
Expand Down Expand Up @@ -132,7 +131,7 @@ def process_with_callbacks(node):

def _add_value_store(
plan: Plan, node: Node, registry_value: RegistryValue, *, is_stale: bool
) -> tuple[Optional[Node], Node]:
) -> tuple[Node | None, Node]:
def nested_call(*args):
call = plan._call(registry_value.stack_frame, *args)
if type(node) is Call:
Expand Down Expand Up @@ -185,13 +184,13 @@ def plan_with_value_stores(
plan: Plan,
registry: Registry,
*,
output_node: Optional[Node],
max_workers: Optional[int] = None,
output_node: Node | None,
max_workers: int | None = None,
retry,
fresh_time: Optional[dt.datetime] = None,
fresh_time: dt.datetime | None = None,
inplace: bool,
progress_observer,
) -> tuple[Plan, Optional[Node]]:
) -> tuple[Plan, Node | None]:
_update_stale_totals(plan, registry, progress_observer)
plan = get_mutable_plan(plan, inplace=inplace)
stale_nodes = _get_stale_nodes(
Expand Down
7 changes: 3 additions & 4 deletions src/uberjob/_transformations/pruning.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
# limitations under the License.
#
import itertools
from collections.abc import Iterable
from typing import Callable, Optional
from collections.abc import Callable, Iterable

from uberjob._plan import Plan
from uberjob._transformations import get_mutable_plan
Expand All @@ -27,7 +26,7 @@ def prune_plan(
plan: Plan,
*,
required_nodes: Iterable[Node],
output_node: Optional[Node],
output_node: Node | None,
inplace: bool
) -> Plan:
required_nodes = set(required_nodes)
Expand Down Expand Up @@ -73,7 +72,7 @@ def _prune_literal_if_trivial(plan: Plan, literal: Literal) -> None:


def prune_source_literals(
plan: Plan, *, inplace: bool, predicate: Optional[Callable[[Literal], bool]] = None
plan: Plan, *, inplace: bool, predicate: Callable[[Literal], bool] | None = None
) -> Plan:
"""
Prunes source literals. When predicate is present, the literal will only be pruned if it returns true.
Expand Down
3 changes: 1 addition & 2 deletions src/uberjob/_value_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
# limitations under the License.
#
import datetime as dt
import typing
from abc import ABC, abstractmethod


Expand All @@ -36,5 +35,5 @@ def write(self, value) -> None:
"""

@abstractmethod
def get_modified_time(self) -> typing.Optional[dt.datetime]:
def get_modified_time(self) -> dt.datetime | None:
"""Get the modified time of the stored value, or ``None`` if there is no stored value."""
2 changes: 1 addition & 1 deletion src/uberjob/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#
"""Provides the underlying graph, node, and edge classes used by the :class:`~uberjob.Plan`."""
import warnings
from typing import Callable
from collections.abc import Callable

import networkx as nx

Expand Down
6 changes: 2 additions & 4 deletions src/uberjob/progress/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#
"""The state of a running Plan can be observed through the use of Progress."""
import pathlib
from collections.abc import Callable
from functools import partial
from typing import Callable, Union

from uberjob._util import is_ipython

Expand Down Expand Up @@ -54,9 +54,7 @@
"""Display observed progress using IPython widgets."""


def html_progress(
output: Union[str, pathlib.Path, Callable[[bytes], None]]
) -> Progress:
def html_progress(output: str | pathlib.Path | Callable[[bytes], None]) -> Progress:
"""
Write observed progress to an HTML file.
Expand Down
4 changes: 2 additions & 2 deletions src/uberjob/progress/_html_progress_observer.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
import datetime as dt
import pathlib
import traceback
from collections.abc import Callable
from html import escape
from typing import Callable, Union

from uberjob.progress._simple_progress_observer import (
ScopeState,
Expand Down Expand Up @@ -209,7 +209,7 @@ class HtmlProgressObserver(SimpleProgressObserver):

def __init__(
self,
output: Union[str, pathlib.Path, Callable[[bytes], None]],
output: str | pathlib.Path | Callable[[bytes], None],
*,
initial_update_delay,
min_update_interval,
Expand Down
2 changes: 1 addition & 1 deletion src/uberjob/progress/_progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
from typing import Callable
from collections.abc import Callable

from uberjob.progress._progress_observer import ProgressObserver

Expand Down
Loading

0 comments on commit 19bd8f0

Please sign in to comment.