Skip to content

Commit

Permalink
Merge pull request #62 from mrc-ide/modernize
Browse files Browse the repository at this point in the history
Modernize type annotations.
  • Loading branch information
plietar authored Nov 7, 2024
2 parents 733a7e0 + 44818ec commit 4f09967
Show file tree
Hide file tree
Showing 20 changed files with 95 additions and 105 deletions.
7 changes: 1 addition & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ generate-docs = [
]

[[tool.hatch.envs.all.matrix]]
python = ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
python = ["3.9", "3.10", "3.11", "3.12", "3.13"]

[tool.hatch.envs.lint]
extra-dependencies = [
Expand All @@ -104,12 +104,10 @@ all = [
]

[tool.black]
target-version = ["py37"]
line-length = 80
skip-string-normalization = true

[tool.ruff]
target-version = "py37"
line-length = 120

[tool.ruff.lint]
Expand Down Expand Up @@ -164,9 +162,6 @@ unfixable = [
"F401",
]

[tool.ruff.lint.isort]
known-first-party = ["outpack"]

[tool.ruff.lint.flake8-tidy-imports]
ban-relative-imports = "all"

Expand Down
14 changes: 7 additions & 7 deletions src/pyorderly/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from dataclasses import dataclass
from pathlib import Path
from types import SimpleNamespace
from typing import Dict, List, Union
from typing import Union

from dataclasses_json import dataclass_json

Expand All @@ -18,15 +18,15 @@
@dataclass
class Artefact:
name: str
files: List[str]
files: list[str]


@dataclass_json()
@dataclass
class Description:
display: str
long: str
custom: Dict[str, Union[str, int, bool]]
custom: dict[str, Union[str, int, bool]]

@staticmethod
def empty():
Expand Down Expand Up @@ -112,8 +112,8 @@ def resource(files):


def shared_resource(
files: Union[str, List[str], Dict[str, str]]
) -> Dict[str, str]:
files: Union[str, list[str], dict[str, str]]
) -> dict[str, str]:
"""Copy shared resources into a packet directory.
You can use this to share common resources (data or code) between multiple
Expand Down Expand Up @@ -151,8 +151,8 @@ def shared_resource(


def _copy_shared_resources(
root: Path, packet: Path, files: Dict[str, str]
) -> Dict[str, str]:
root: Path, packet: Path, files: dict[str, str]
) -> dict[str, str]:
shared_path = root / "shared"
if not shared_path.exists():
msg = "The shared resources directory 'shared' does not exist at orderly's root"
Expand Down
4 changes: 2 additions & 2 deletions src/pyorderly/outpack/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os.path
from dataclasses import dataclass, field
from typing import Dict, Optional
from typing import Optional

from dataclasses_json import config, dataclass_json

Expand Down Expand Up @@ -80,7 +80,7 @@ def __init__(self, name, type, args=None):
class Config:
schema_version: str
core: ConfigCore
location: Dict[str, Location] = field(
location: dict[str, Location] = field(
metadata=config(
encoder=_encode_location_dict, decoder=_decode_location_dict
)
Expand Down
7 changes: 3 additions & 4 deletions src/pyorderly/outpack/copy_files.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from dataclasses import dataclass
from pathlib import Path
from typing import Dict

from pyorderly.outpack.location_pull import (
location_build_pull_plan,
Expand All @@ -15,12 +14,12 @@
class Plan:
id: str
name: str
files: Dict[str, PacketFile]
files: dict[str, PacketFile]


def copy_files(
id: str,
files: Dict[str, str],
files: dict[str, str],
dest: Path,
options: SearchOptions,
root: OutpackRoot,
Expand All @@ -43,7 +42,7 @@ def copy_files(

def copy_files_from_remote(
id: str,
files: Dict[str, PacketFile],
files: dict[str, PacketFile],
dest: Path,
options: SearchOptions,
root: OutpackRoot,
Expand Down
19 changes: 9 additions & 10 deletions src/pyorderly/outpack/index.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import pathlib
from dataclasses import dataclass
from typing import Dict, List

from pyorderly.outpack.metadata import (
MetadataCore,
Expand All @@ -12,9 +11,9 @@

@dataclass
class IndexData:
metadata: Dict[str, MetadataCore]
location: Dict[str, Dict[str, PacketLocation]]
unpacked: List[str]
metadata: dict[str, MetadataCore]
location: dict[str, dict[str, PacketLocation]]
unpacked: list[str]

@staticmethod
def new():
Expand All @@ -34,24 +33,24 @@ def refresh(self):
self.data = _index_update(self._path, self.data)
return self

def all_metadata(self) -> Dict[str, MetadataCore]:
def all_metadata(self) -> dict[str, MetadataCore]:
return self.refresh().data.metadata

def metadata(self, id) -> MetadataCore:
if id in self.data.metadata:
return self.data.metadata[id]
return self.refresh().data.metadata[id]

def all_locations(self) -> Dict[str, Dict[str, PacketLocation]]:
def all_locations(self) -> dict[str, dict[str, PacketLocation]]:
return self.refresh().data.location

def location(self, name) -> Dict[str, PacketLocation]:
def location(self, name) -> dict[str, PacketLocation]:
return self.refresh().data.location.get(name, {})

def packets_in_location(self, name) -> List[str]:
def packets_in_location(self, name) -> list[str]:
return list(self.location(name).keys())

def unpacked(self) -> List[str]:
def unpacked(self) -> list[str]:
return self.refresh().data.unpacked


Expand All @@ -70,7 +69,7 @@ def _read_metadata(path_root, data):
return data


def _read_locations(path_root, data) -> Dict[str, Dict[str, PacketLocation]]:
def _read_locations(path_root, data) -> dict[str, dict[str, PacketLocation]]:
path = path_root / ".outpack" / "location"
for loc in path.iterdir():
if loc.name not in data:
Expand Down
6 changes: 3 additions & 3 deletions src/pyorderly/outpack/location_driver.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import builtins
from abc import abstractmethod
from contextlib import AbstractContextManager
from typing import Dict, List

from pyorderly.outpack.metadata import MetadataCore, PacketFile, PacketLocation

Expand All @@ -14,10 +14,10 @@ class LocationDriver(AbstractContextManager):
"""

@abstractmethod
def list(self) -> Dict[str, PacketLocation]: ...
def list(self) -> dict[str, PacketLocation]: ...

@abstractmethod
def metadata(self, packet_ids: List[str]) -> Dict[str, str]: ...
def metadata(self, packet_ids: builtins.list[str]) -> dict[str, str]: ...

@abstractmethod
def fetch_file(
Expand Down
6 changes: 3 additions & 3 deletions src/pyorderly/outpack/location_http.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import builtins
import shutil
from typing import Dict, List
from urllib.parse import urljoin

import requests
Expand Down Expand Up @@ -58,15 +58,15 @@ def __exit__(self, *args):
self._client.__exit__(*args)

@override
def list(self) -> Dict[str, PacketLocation]:
def list(self) -> dict[str, PacketLocation]:
response = self._client.get("metadata/list").json()
data = response["data"]
return {
entry["packet"]: PacketLocation.from_dict(entry) for entry in data
}

@override
def metadata(self, ids: List[str]) -> Dict[str, str]:
def metadata(self, ids: builtins.list[str]) -> dict[str, str]:
result = {}
for i in ids:
result[i] = self._client.get(f"metadata/{i}/text").text
Expand Down
4 changes: 2 additions & 2 deletions src/pyorderly/outpack/location_packit.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import re
import time
from dataclasses import dataclass
from typing import Dict, Optional, Union
from typing import Optional, Union
from urllib.parse import urljoin

import requests
Expand Down Expand Up @@ -165,7 +165,7 @@ def poll_access_token(
# - It should check for expiry of tokens and/or check for authentication errors
# and purge offending tokens from it.
@functools.cache
def packit_authorisation(url: str, token: Optional[str]) -> Dict[str, str]:
def packit_authorisation(url: str, token: Optional[str]) -> dict[str, str]:
# If a non-Github token is provided, we assume it is a native Packit token
# and use that directly.
if token is not None and not re.match("^gh._", token):
Expand Down
6 changes: 3 additions & 3 deletions src/pyorderly/outpack/location_path.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import builtins
import os
import shutil
from typing import Dict, List

from typing_extensions import override

Expand All @@ -24,11 +24,11 @@ def __exit__(self, exc_type, exc_value, exc_tb):
pass

@override
def list(self) -> Dict[str, PacketLocation]:
def list(self) -> dict[str, PacketLocation]:
return self.__root.index.location(LOCATION_LOCAL)

@override
def metadata(self, packet_ids: List[str]) -> Dict[str, str]:
def metadata(self, packet_ids: builtins.list[str]) -> dict[str, str]:
all_ids = self.__root.index.location(LOCATION_LOCAL).keys()
missing_ids = set(packet_ids).difference(all_ids)
if missing_ids:
Expand Down
Loading

0 comments on commit 4f09967

Please sign in to comment.