Skip to content

Commit

Permalink
deprecate init_app args (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidism authored Jun 16, 2024
2 parents 8cd7e4f + 1eadb1d commit 8b89814
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ Unreleased
- Support Flask-SQLAlchemy-Lite and plain SQLAlchemy, in addition to
Flask-SQLAlchemy. {pr}`26`
- Support multiple databases, and multiple metadata per database. {pr}`26`
- The constructor args `run_mkdir` and `command_name` are keyword only. {pr}`27`
- Deprecate the `init_app` args `run_mkdir` and `command_name`. They can be
passed to the constructor instead. {pr}`27`

## Version 3.0.1

Expand Down
37 changes: 31 additions & 6 deletions src/flask_alembic/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,17 @@ class Alembic:
Flask-SQLAlchemy-Lite and plain SQLAlchemy in addition to
Flask-SQLAlchemy. Support multiple databases and multiple metadata per
database.
.. versionchanged:: 3.1
``run_mkdir`` and ``command_name`` are keyword-only arguments.
"""

def __init__(
self,
app: Flask | None = None,
*,
run_mkdir: bool = True,
command_name: str = "db",
*,
metadatas: sa.MetaData
| list[sa.MetaData]
| dict[str, sa.MetaData | list[sa.MetaData]]
Expand Down Expand Up @@ -126,8 +129,9 @@ def __init__(
def init_app(
self,
app: Flask,
run_mkdir: bool | None = None,
command_name: str | None = None,
*,
run_mkdir: None = None,
command_name: None = None,
) -> None:
"""Register this extension on an app. Will automatically set up
migration directory by default.
Expand All @@ -136,9 +140,10 @@ def init_app(
:meth:`__init__` if not ``None``.
:param app: App to register.
:param run_mkdir: Run :meth:`mkdir` automatically.
:param command_name: Register a Click command with this name, unless it
is the empty string.
.. versionchanged:: 3.1
``run_mkdir`` and ``command_name`` are deprecated and will be
removed in Flask-Alembic 3.2. Use them in the constructor instead.
"""
app.extensions["alembic"] = self

Expand All @@ -151,10 +156,30 @@ def init_app(
self._cache[app] = cache = _Cache()
app.teardown_appcontext(cache.clear)

if run_mkdir is not None:
import warnings

warnings.warn(
"The 'run_mkdir' argument is deprecated and will be removed in"
" Flask-Alembic 3.2. Pass it to the constructor instead.",
DeprecationWarning,
stacklevel=2,
)

if run_mkdir or (run_mkdir is None and self.run_mkdir):
with app.app_context():
self.mkdir()

if command_name is not None:
import warnings

warnings.warn(
"The 'command_name' argument is deprecated and will be removed"
" in Flask-Alembic 3.2. Pass it to the constructor instead.",
DeprecationWarning,
stacklevel=2,
)

if command_name or (command_name is None and self.command_name):
from .cli import cli

Expand Down

0 comments on commit 8b89814

Please sign in to comment.