summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorTilmanK <tilman.krummeck@googlemail.com>2021-09-14 15:43:30 -0400
committerFederico Caselli <cfederico87@gmail.com>2021-09-14 19:46:58 +0000
commit338fd68f1b33a143f9c9985be8b883f6ec4cd66d (patch)
tree3eb1f781e1f463676240c1a6af11178247aab560 /tools
parent1932b095444f4c69037f00c3251b3313d4bcddc6 (diff)
downloadalembic-338fd68f1b33a143f9c9985be8b883f6ec4cd66d.tar.gz
Adds exception when trying to run write_pyi.py with Python < 3.9
### Description write_pyi.py now raises an exception when someone tries to run the script with Python version 3.8 or smaller. This also fixes: - When using absolute Paths, i.e. on Windows, they are now converted to relative paths to avoid useless changes in the doc strings of the pyi files - Corrected destination_path argument type when calling `generate_pyi_for_proxy` in `run_file` - A comment typo Fixes: #915 Closes: #919 Pull-request: https://github.com/sqlalchemy/alembic/pull/919 Pull-request-sha: e885d27ac5509858c8cb2927310f6195fc1d6004 Change-Id: Ia33d32b2828e71185186afc49848ce89d48a8323
Diffstat (limited to 'tools')
-rw-r--r--tools/write_pyi.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/tools/write_pyi.py b/tools/write_pyi.py
index 61c3052..df2a55f 100644
--- a/tools/write_pyi.py
+++ b/tools/write_pyi.py
@@ -9,7 +9,7 @@ from mako.pygen import PythonPrinter
sys.path.append(str(Path(__file__).parent.parent))
-if True: # avoid flake/zimports missing with the order
+if True: # avoid flake/zimports messing with the order
from alembic.operations.base import Operations
from alembic.runtime.environment import EnvironmentContext
from alembic.script.write_hooks import console_scripts
@@ -36,6 +36,13 @@ def generate_pyi_for_proxy(
ignore_output: bool,
ignore_items: set,
):
+ if sys.version_info < (3, 9):
+ raise RuntimeError("This script must be run with Python 3.9 or higher")
+
+ # When using an absolute path on windows, this will generate the correct
+ # relative path that shall be written to the top comment of the pyi file.
+ if Path(progname).is_absolute():
+ progname = Path(progname).relative_to(Path().cwd()).as_posix()
imports = []
read_imports = False
@@ -154,15 +161,15 @@ def run_file(
else:
with NamedTemporaryFile(delete=False, suffix=".pyi") as f:
f.close()
+ f_path = Path(f.name)
generate_pyi_for_proxy(
cls_to_generate,
progname,
source_path=source_path,
- destination_path=f.name,
+ destination_path=f_path,
ignore_output=True,
ignore_items=ignore_items,
)
- f_path = Path(f.name)
sys.stdout.write(f_path.read_text())
f_path.unlink()