feat: support command python -m aerich (#417)

* feat: support command `python -m aerich`

* docs: update changelog
This commit is contained in:
Waket Zheng 2025-02-18 15:44:02 +08:00 committed by GitHub
parent 7f8c5dcddc
commit 557271c8e1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 23 additions and 12 deletions

View File

@ -5,6 +5,7 @@
### [0.8.2]**(Unreleased)** ### [0.8.2]**(Unreleased)**
#### Added #### Added
- feat: support command `python -m aerich`. ([#417])
- feat: add --fake to upgrade/downgrade. ([#398]) - feat: add --fake to upgrade/downgrade. ([#398])
#### Fixed #### Fixed
@ -18,6 +19,7 @@
[#401]: https://github.com/tortoise/aerich/pull/401 [#401]: https://github.com/tortoise/aerich/pull/401
[#412]: https://github.com/tortoise/aerich/pull/412 [#412]: https://github.com/tortoise/aerich/pull/412
[#415]: https://github.com/tortoise/aerich/pull/415 [#415]: https://github.com/tortoise/aerich/pull/415
[#417]: https://github.com/tortoise/aerich/pull/417
### [0.8.1](../../releases/tag/v0.8.1) - 2024-12-27 ### [0.8.1](../../releases/tag/v0.8.1) - 2024-12-27

3
aerich/__main__.py Normal file
View File

@ -0,0 +1,3 @@
from .cli import main
main()

View File

@ -1,6 +1,8 @@
import contextlib import contextlib
import os import os
import shlex
import shutil import shutil
import subprocess
import sys import sys
from pathlib import Path from pathlib import Path
@ -68,3 +70,12 @@ class Dialect:
def is_sqlite(cls) -> bool: def is_sqlite(cls) -> bool:
cls.load_env() cls.load_env()
return not cls.test_db_url or "sqlite" in cls.test_db_url return not cls.test_db_url or "sqlite" in cls.test_db_url
def run_shell(command: str, capture_output=True, **kw) -> str:
r = subprocess.run(shlex.split(command), capture_output=capture_output)
if r.returncode != 0 and r.stderr:
return r.stderr.decode()
if not r.stdout:
return ""
return r.stdout.decode()

View File

@ -2,8 +2,6 @@ from __future__ import annotations
import os import os
import re import re
import shlex
import subprocess
import sys import sys
from pathlib import Path from pathlib import Path
@ -11,16 +9,7 @@ import pytest
from aerich.ddl.sqlite import SqliteDDL from aerich.ddl.sqlite import SqliteDDL
from aerich.migrate import Migrate from aerich.migrate import Migrate
from tests._utils import chdir, copy_files from tests._utils import chdir, copy_files, run_shell
def run_shell(command: str, capture_output=True, **kw) -> str:
r = subprocess.run(shlex.split(command), capture_output=capture_output)
if r.returncode != 0 and r.stderr:
return r.stderr.decode()
if not r.stdout:
return ""
return r.stdout.decode()
@pytest.fixture @pytest.fixture

6
tests/test_python_m.py Normal file
View File

@ -0,0 +1,6 @@
from aerich.version import __version__
from tests._utils import run_shell
def test_python_m_aerich():
assert __version__ in run_shell("python -m aerich --version")