Skip to content

Commit

Permalink
Fix deprecation/removal warning.
Browse files Browse the repository at this point in the history
  • Loading branch information
liffiton committed Jul 26, 2024
1 parent e8222af commit 8807f1c
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/gened/migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@
from collections.abc import Iterable
from datetime import datetime
from importlib import resources
from importlib.abc import Traversable
from pathlib import Path
from typing import TypedDict

try:
from importlib.resources.abc import Traversable # 3.12+
except ImportError:
from importlib.abc import Traversable # - Deprecated in 3.12, removed in 3.14

import click
from flask import current_app
from flask.app import Flask
Expand All @@ -19,7 +23,6 @@

class MigrationDict(TypedDict):
name: str
path: Path
contents: str
mtime: float
applied_on: str | None
Expand Down Expand Up @@ -94,7 +97,6 @@ def _migration_info(resource: Traversable) -> MigrationDict:
name = path.name
info: MigrationDict = {
'name': name,
'path': path,
'contents': f.read(),
'mtime': path.stat().st_mtime,
'applied_on': None,
Expand All @@ -114,14 +116,14 @@ def _get_migrations() -> list[MigrationDict]:
# Pull shared Gen-ed migrations and app-specific migrations
gened_migrations = resources.files('gened').joinpath("migrations")
app_migrations = resources.files(current_app.name).joinpath("migrations")
migration_files = itertools.chain(
migration_resources = itertools.chain(
*(x.iterdir() for x in (gened_migrations, app_migrations) if x.is_dir())
)

# Collect info and sort by name and modified time (to apply migrations in order)
migrations = [
_migration_info(res)
for res in migration_files
for res in migration_resources
if not res.name.startswith('.') and res.name.endswith('.sql')
]
migrations.sort(key=lambda x: (x['name'], x['mtime']))
Expand Down

0 comments on commit 8807f1c

Please sign in to comment.