diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4c065e2..7d16ee7 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -24,7 +24,7 @@ repos: - id: trailing-whitespace - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.15.20 + rev: v0.16.1 hooks: - id: ruff-check types_or: [python, pyproject] diff --git a/_scripts/sync-releases.py b/_scripts/sync-releases.py index 55f7069..d5836ce 100755 --- a/_scripts/sync-releases.py +++ b/_scripts/sync-releases.py @@ -65,6 +65,10 @@ class Docs: ) +class SyncReleasesException(Exception): + pass + + def api_request(endpoint: str) -> Any: resp = requests.get( f'https://api.github.com/{endpoint}', @@ -105,7 +109,7 @@ def main() -> None: if version != prev['version']: cur = prev.copy() cur['version'] = version - cur['date'] = date.today().strftime('%Y-%m-%d') + cur['date'] = date.today().strftime('%Y-%m-%d') # noqa: DTZ011 releases[proj.id].insert(0, cur) # sync docs @@ -130,7 +134,9 @@ def main() -> None: expected_hash = artifact['digest'].replace('sha256:', '') found_hash = sha256(resp.content).hexdigest() if expected_hash != found_hash: - raise Exception(f'SHA-256 {found_hash} != {expected_hash}') + raise SyncReleasesException( + f'SHA-256 {found_hash} != {expected_hash}' + ) # unpack docdir = DOCROOT / proj.docs.subdir diff --git a/demo/_synctiles.py b/demo/_synctiles.py index fe0f43c..d8ba884 100755 --- a/demo/_synctiles.py +++ b/demo/_synctiles.py @@ -213,6 +213,10 @@ class StatusMetadata(TypedDict): stamp: str | None +class SyncTilesException(Exception): + pass + + def slugify(text: str) -> str: """Generate an ASCII-only slug.""" text = normalize('NFKD', text.lower()).encode('ascii', 'ignore').decode() @@ -450,7 +454,8 @@ def sync_slide( # Get current metadata try: resp = storage.object(metadata_key_name).get() - metadata: SlideMetadata | None = json.load(gzip.open(resp['Body'])) + with gzip.open(resp['Body']) as body: + metadata: SlideMetadata | None = json.load(body) except storage.NoSuchKey: metadata = None @@ -675,7 +680,8 @@ def start_retile( # If the stamp is changing, mark bucket dirty try: resp = storage.object(PurePath(METADATA_NAME)).get() - metadata: BucketMetadata = json.load(gzip.open(resp['Body'])) + with gzip.open(resp['Body']) as body: + metadata: BucketMetadata = json.load(body) old_stamp = metadata['stamp'] except storage.NoSuchKey: old_stamp = None @@ -709,7 +715,7 @@ def retile_slide( # Tile slide slide_info = context['slides'].get(slide_relpath.as_posix()) if slide_info is None: - raise Exception(f'No such slide {slide_relpath}') + raise SyncTilesException(f'No such slide {slide_relpath}') metadata = sync_slide( context['stamp'], storage, slide_relpath, slide_info, workers ) @@ -845,4 +851,4 @@ def finish_retile(ctxfile: TextIO, summarydir: Path) -> None: elif args.cmd == 'finish': finish_retile(args.context_file, args.summary_dir) else: - raise Exception('unimplemented subcommand') + raise SyncTilesException('unimplemented subcommand')