From 15a13dd90731211466dc6e85a4b1da14b7612839 Mon Sep 17 00:00:00 2001 From: Robert Craigie Date: Sat, 30 Nov 2024 12:30:05 -0500 Subject: [PATCH] feat(prisma): update to v6 --- README.md | 2 +- docs/index.md | 2 +- docs/reference/binaries.md | 2 +- docs/reference/config.md | 4 +-- pipelines/requirements/node.txt | 2 +- requirements/node.txt | 2 +- src/prisma/_compat.py | 8 +++--- src/prisma/_config.py | 6 ++--- src/prisma/cli/_node.py | 46 ++++++++++++++++++++------------- tests/test_node/test_node.py | 6 ++--- 10 files changed, 45 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index 5b1c85571..a644796b7 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Chat on Discord - Supported Prisma version is 5.19.0 + Supported Prisma version is 6.0.0 Code style: ruff diff --git a/docs/index.md b/docs/index.md index 194448694..b3bd99806 100644 --- a/docs/index.md +++ b/docs/index.md @@ -8,7 +8,7 @@ Chat on Discord - Supported Prisma version is 5.19.0 + Supported Prisma version is 6.0.0 Code style: ruff diff --git a/docs/reference/binaries.md b/docs/reference/binaries.md index c50311fda..ecc465bf5 100644 --- a/docs/reference/binaries.md +++ b/docs/reference/binaries.md @@ -9,7 +9,7 @@ Prisma Client Python _should_ automatically download the correct binaries for yo - Clone the prisma-engines repository at the current version that the python client supports: ``` -git clone https://github.com/prisma/prisma-engines --branch=5.19.0 +git clone https://github.com/prisma/prisma-engines --branch=6.0.0 ``` - Build the binaries following the steps found [here](https://github.com/prisma/prisma-engines#building-prisma-engines) diff --git a/docs/reference/config.md b/docs/reference/config.md index 5bf079224..5b6df4186 100644 --- a/docs/reference/config.md +++ b/docs/reference/config.md @@ -220,7 +220,7 @@ This option controls the version of Prisma to use. It should be noted that this | Option | Environment Variable | Default | | ---------------- | --------------------- | -------- | -| `prisma_version` | `PRISMA_VERSION` | `5.19.0` | +| `prisma_version` | `PRISMA_VERSION` | `6.0.0` | ### Expected Engine Version @@ -228,7 +228,7 @@ This is an internal option that is here as a safeguard for the `prisma_version` | Option | Environment Variable | Default | | ------------------------- | -------------------------------- | ------------------------------------------ | -| `expected_engine_version` | `PRISMA_EXPECTED_ENGINE_VERSION` | `5fe21811a6ba0b952a3bc71400666511fe3b902f` | +| `expected_engine_version` | `PRISMA_EXPECTED_ENGINE_VERSION` | `5dbef10bdbfb579e07d35cc85fb1518d357cb99e` | ### Binary Platform diff --git a/pipelines/requirements/node.txt b/pipelines/requirements/node.txt index 03d4501d3..4b3669fb2 100644 --- a/pipelines/requirements/node.txt +++ b/pipelines/requirements/node.txt @@ -1 +1 @@ -nodejs-bin==16.15.1a4 +nodejs-wheel-binaries==20.14.0 diff --git a/requirements/node.txt b/requirements/node.txt index 2339a304f..b6d2688c5 100644 --- a/requirements/node.txt +++ b/requirements/node.txt @@ -1 +1 @@ -nodejs-bin +nodejs-wheel-binaries>=20.14.0 diff --git a/src/prisma/_compat.py b/src/prisma/_compat.py index 3d812f614..435587492 100644 --- a/src/prisma/_compat.py +++ b/src/prisma/_compat.py @@ -332,14 +332,14 @@ def Field(*, env: str | None = None, **extra: Any) -> Any: if TYPE_CHECKING: - import nodejs as _nodejs + import nodejs_wheel as _nodejs_wheel - nodejs = make_optional(_nodejs) + nodejs_wheel = make_optional(_nodejs_wheel) else: try: - import nodejs + import nodejs_wheel except ImportError: - nodejs = None + nodejs_wheel = None # Note: this shim is due to an inconsistency with string enums diff --git a/src/prisma/_config.py b/src/prisma/_config.py index d3ca51458..f4a9b7bd2 100644 --- a/src/prisma/_config.py +++ b/src/prisma/_config.py @@ -27,13 +27,13 @@ class DefaultConfig(BaseSettings): # doesn't change then the CLI is incorrectly cached prisma_version: str = Field( env='PRISMA_VERSION', - default='5.19.0', + default='6.0.0', ) # Engine binary versions can be found under https://github.com/prisma/prisma-engine/commits/main expected_engine_version: str = Field( env='PRISMA_EXPECTED_ENGINE_VERSION', - default='5fe21811a6ba0b952a3bc71400666511fe3b902f', + default='5dbef10bdbfb579e07d35cc85fb1518d357cb99e', ) # Home directory, used to build the `binary_cache_dir` option by default, useful in multi-user @@ -56,7 +56,7 @@ class DefaultConfig(BaseSettings): # Whether or not to use the global node installation (if available) use_global_node: bool = Field(env='PRISMA_USE_GLOBAL_NODE', default=True) - # Whether or not to use the `nodejs-bin` package (if installed) + # Whether or not to use the `nodejs-wheel-binaries` package (if installed) use_nodejs_bin: bool = Field(env='PRISMA_USE_NODEJS_BIN', default=True) # Extra arguments to pass to nodeenv, arguments are passed after the path, e.g. python -m nodeenv diff --git a/src/prisma/cli/_node.py b/src/prisma/cli/_node.py index 394a3bb12..7ce50d694 100644 --- a/src/prisma/cli/_node.py +++ b/src/prisma/cli/_node.py @@ -6,6 +6,7 @@ import shutil import logging import subprocess +import importlib.metadata from abc import ABC, abstractmethod from typing import IO, Any, Union, Mapping, cast from pathlib import Path @@ -14,7 +15,7 @@ from .. import config from .._proxy import LazyProxy from ..errors import PrismaError -from .._compat import nodejs, get_args +from .._compat import get_args, nodejs_wheel from ..binaries import platform log: logging.Logger = logging.getLogger(__name__) @@ -22,10 +23,10 @@ Target = Literal['node', 'npm'] # taken from https://github.com/prisma/prisma/blob/main/package.json -MIN_NODE_VERSION = (16, 13) +MIN_NODE_VERSION = (18, 18) # mapped the node version above from https://nodejs.org/en/download/releases/ -MIN_NPM_VERSION = (6, 14) +MIN_NPM_VERSION = (10, 0) # we only care about the first two entries in the version number VERSION_RE = re.compile(r'v?(\d+)(?:\.?(\d+))') @@ -43,7 +44,7 @@ def __init__(self, *, target: str) -> None: class MissingNodejsBinError(PrismaError): def __init__(self) -> None: super().__init__( - 'Attempted to access a function that requires the `nodejs-bin` package to be installed but it is not.' + 'Attempted to access a function that requires the `nodejs-wheel-binaries` package to be installed but it is not.' ) @@ -182,7 +183,7 @@ def from_nodeenv(cls, target: Target) -> NodeBinaryStrategy: ) except Exception as exc: print( # noqa: T201 - 'nodeenv installation failed; You may want to try installing `nodejs-bin` as it is more reliable.', + 'nodeenv installation failed; You may want to try installing `nodejs-wheel-binaries` as it is more reliable.', file=sys.stderr, ) raise exc @@ -212,11 +213,11 @@ def from_nodeenv(cls, target: Target) -> NodeBinaryStrategy: class NodeJSPythonStrategy(Strategy): target: Target - resolver: Literal['nodejs-bin'] + resolver: Literal['nodejs-wheel-binaries'] def __init__(self, *, target: Target) -> None: self.target = target - self.resolver = 'nodejs-bin' + self.resolver = 'nodejs-wheel-binaries' @override def __run__( @@ -228,36 +229,43 @@ def __run__( stderr: File | None = None, env: Mapping[str, str] | None = None, ) -> subprocess.CompletedProcess[bytes]: - if nodejs is None: + if nodejs_wheel is None: raise MissingNodejsBinError() func = None if self.target == 'node': - func = nodejs.node.run + func = nodejs_wheel.node elif self.target == 'npm': - func = nodejs.npm.run + func = nodejs_wheel.npm else: raise UnknownTargetError(target=self.target) - return cast( + proc = cast( 'subprocess.CompletedProcess[bytes]', func( args, - check=check, cwd=cwd, env=env, stdout=stdout, stderr=stderr, + return_completed_process=True, ), ) + if check: + proc.check_returncode() + + return proc @property def node_path(self) -> Path: """Returns the path to the `node` binary""" - if nodejs is None: + if nodejs_wheel is None: raise MissingNodejsBinError() - return Path(nodejs.node.path) + if os.name == 'nt': + return Path(nodejs_wheel.executable.ROOT_DIR).joinpath('node.exe') + + return Path(nodejs_wheel.executable.ROOT_DIR).joinpath('bin/node') @property @override @@ -273,9 +281,11 @@ def resolve(target: Target) -> Node: raise UnknownTargetError(target=target) if config.use_nodejs_bin: - log.debug('Checking if nodejs-bin is installed') - if nodejs is not None: - log.debug('Using nodejs-bin with version: %s', nodejs.node_version) + log.debug('Checking if nodejs-wheel-binaries is installed') + if nodejs_wheel is not None: + log.debug( + 'Using nodejs-wheel-binaries with version: %s', importlib.metadata.version('nodejs-wheel-binaries') + ) return NodeJSPythonStrategy(target=target) return NodeBinaryStrategy.resolve(target) @@ -342,7 +352,7 @@ def _should_use_binary(target: Target, path: Path) -> bool: This only applies to the global node installation as: - - the minimum version of `nodejs-bin` is higher than our requirement + - the minimum version of `nodejs-wheel-binaries` is higher than our requirement - `nodeenv` defaults to the latest stable version of node """ if target == 'node': diff --git a/tests/test_node/test_node.py b/tests/test_node/test_node.py index 556622f08..497d69539 100644 --- a/tests/test_node/test_node.py +++ b/tests/test_node/test_node.py @@ -9,7 +9,7 @@ from pytest_subprocess import FakeProcess from prisma.cli import _node as node -from prisma._compat import nodejs +from prisma._compat import nodejs_wheel from prisma._config import Config from prisma.cli._node import Target @@ -57,7 +57,7 @@ def test_resolve_bad_target() -> None: @parametrize_target -@pytest.mark.skipif(nodejs is None, reason='nodejs-bin is not installed') +@pytest.mark.skipif(nodejs_wheel is None, reason='nodejs-bin is not installed') def test_nodejs_bin(target: Target) -> None: """When `nodejs-bin` is installed, it is resolved to and can be successfully used""" with set_config( @@ -67,7 +67,7 @@ def test_nodejs_bin(target: Target) -> None: ) ): strategy = node.resolve(target) - assert strategy.resolver == 'nodejs-bin' + assert strategy.resolver == 'nodejs-wheel-binaries' assert_strategy(strategy)