diff --git a/.github/workflows/upload-pypi-source.yml b/.github/workflows/upload-pypi-source.yml index 85a04f7e76f9..26f04c34da33 100644 --- a/.github/workflows/upload-pypi-source.yml +++ b/.github/workflows/upload-pypi-source.yml @@ -136,6 +136,9 @@ jobs: command: | python3 -m chia._tests.util.build_network_protocol_files git diff --exit-code + - name: poetry + command: | + .penv/bin/poetry check steps: - uses: chia-network/actions/clean-workspace@main diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0a89e633313a..efceeee634f3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -28,6 +28,13 @@ repos: language: system require_serial: true types_or: [python, pyi] + - repo: local + hooks: + - id: poetry + name: poetry + entry: ./activated.py --poetry poetry check + language: system + pass_filenames: false - repo: https://github.com/pre-commit/mirrors-prettier rev: v3.1.0 hooks: diff --git a/activated.ps1 b/activated.ps1 index 71aad646eb54..b6f5c8f859a6 100644 --- a/activated.ps1 +++ b/activated.ps1 @@ -2,11 +2,13 @@ $ErrorActionPreference = "Stop" $script_directory = Split-Path $MyInvocation.MyCommand.Path -Parent -$command = $args[0] +$env_directory = $args[0] +$command = $args[1] $parameters = [System.Collections.ArrayList]$args $parameters.RemoveAt(0) +$parameters.RemoveAt(0) -& $script_directory/.venv/Scripts/Activate.ps1 +& $script_directory/$env_directory/Scripts/Activate.ps1 & $command @parameters exit $LASTEXITCODE diff --git a/activated.py b/activated.py index 7df915836c3d..f065cc6d46df 100755 --- a/activated.py +++ b/activated.py @@ -2,6 +2,7 @@ from __future__ import annotations +import enum import os import pathlib import subprocess @@ -10,17 +11,27 @@ here = pathlib.Path(__file__).parent.absolute() +class Env(enum.Enum): + chia = ".venv" + poetry = ".penv" + + def main(*args: str) -> int: if len(args) == 0: print("Parameters required") return 1 + env = Env.chia + if args[0].startswith("--"): + env = Env[args[0][2:]] + args = args[1:] + if sys.platform == "win32": script = "activated.ps1" - command = ["powershell", os.fspath(here.joinpath(script)), *args] + command = ["powershell", os.fspath(here.joinpath(script)), env.value, *args] else: script = "activated.sh" - command = ["sh", os.fspath(here.joinpath(script)), *args] + command = ["sh", os.fspath(here.joinpath(script)), env.value, *args] completed_process = subprocess.run(command) diff --git a/activated.sh b/activated.sh index 719edf662e50..d44208f37845 100755 --- a/activated.sh +++ b/activated.sh @@ -6,7 +6,11 @@ SCRIPT_DIRECTORY=$( cd -- "$(dirname -- "$0")" pwd ) -# shellcheck disable=SC1091 -. "${SCRIPT_DIRECTORY}/.venv/bin/activate" + +ENV_DIRECTORY="$1" +shift + +# shellcheck disable=SC1090,SC1091 +. "${SCRIPT_DIRECTORY}/${ENV_DIRECTORY}/bin/activate" "$@"