table_name: str,
schema: Optional[str] = None,
recreate: Literal["auto", "always", "never"] = "auto",
- partial_reordering: Optional[list[tuple[str, ...]]] = None,
+ partial_reordering: list[tuple[str, ...]] | None = None,
copy_from: Optional[Table] = None,
table_args: Tuple[Any, ...] = (),
table_kwargs: Mapping[str, Any] = immutabledict({}),
table_name: str,
schema: Optional[str] = None,
recreate: Literal["auto", "always", "never"] = "auto",
- partial_reordering: Optional[list[tuple[str, ...]]] = None,
+ partial_reordering: list[tuple[str, ...]] | None = None,
copy_from: Optional[Table] = None,
table_args: Tuple[Any, ...] = (),
table_kwargs: Mapping[str, Any] = util.immutabledict(),
@register("console_scripts")
def console_scripts(
- path: str, options: dict, ignore_output: bool = False
+ path: str,
+ options: dict,
+ ignore_output: bool = False,
+ verify_version: tuple[int, ...] | None = None,
) -> None:
entrypoint_name = _get_required_option(options, "entrypoint")
for entry in compat.importlib_metadata_get("console_scripts"):
f"Could not find entrypoint console_scripts.{entrypoint_name}"
)
- command = [
- sys.executable,
- "-c",
- f"import {impl.module}; {impl.module}.{impl.attr}()",
- ]
+ if verify_version:
+ pyscript = (
+ f"import {impl.module}; "
+ f"assert tuple(int(x) for x in {impl.module}.__version__.split('.')) >= {verify_version}, " # noqa: E501
+ f"'need exactly version {verify_version} of {impl.name}'; "
+ f"{impl.module}.{impl.attr}()"
+ )
+ else:
+ pyscript = f"import {impl.module}; {impl.module}.{impl.attr}()"
+
+ command = [sys.executable, "-c", pyscript]
_run_hook(path, options, ignore_output, command)
from dataclasses import field
from pathlib import Path
import re
+import shutil
import sys
from tempfile import NamedTemporaryFile
import textwrap
from alembic.operations import ops
import sqlalchemy as sa
+BLACK_VERSION = (25, 9, 0)
+PYTHON_VERSIONS = (3, 12), (3, 14)
+
+
TRIM_MODULE = [
"alembic.autogenerate.api.",
"alembic.operations.base.",
def generate_pyi_for_proxy(
file_info: FileInfo, destination_path: Path, ignore_output: bool
):
- if sys.version_info < (3, 11):
+ lower_python, upper_python = PYTHON_VERSIONS
+ if sys.version_info < lower_python or sys.version_info >= upper_python:
raise RuntimeError(
- "This script must be run with Python 3.11 or higher"
+ f"Script supports at least python "
+ f"{".".join(str(x) for x in lower_python)} "
+ f"but less than {".".join(str(x) for x in upper_python)} "
+ "right now."
)
progname = Path(sys.argv[0]).as_posix()
str(destination_path),
{"entrypoint": "black", "options": "-l79 --target-version py39"},
ignore_output=ignore_output,
+ verify_version=BLACK_VERSION,
)
def _formatannotation(annotation, base_module=None):
if getattr(annotation, "__module__", None) == "typing":
retval = repr(annotation).replace("typing.", "")
+ elif getattr(annotation, "__module__", None) == "types":
+ retval = repr(annotation).replace("types.", "")
elif isinstance(annotation, type):
retval = annotation.__qualname__
elif isinstance(annotation, typing.TypeVar):
else:
retval = annotation
+ assert isinstance(retval, str)
+
retval = re.sub(r"TypeEngine\b", "TypeEngine[Any]", retval)
retval = retval.replace("~", "") # typevar repr as "~T"
def run_file(finfo: FileInfo, stdout: bool):
if not stdout:
- generate_pyi_for_proxy(
- finfo, destination_path=finfo.path, ignore_output=False
- )
+ with NamedTemporaryFile(delete=False, suffix=finfo.path.suffix) as f:
+ f.close()
+ f_path = Path(f.name)
+ generate_pyi_for_proxy(
+ finfo, destination_path=f_path, ignore_output=False
+ )
+ shutil.move(f_path, finfo.path)
+
else:
with NamedTemporaryFile(delete=False, suffix=finfo.path.suffix) as f:
f.close()