From 740282a63661b38df25d381aad5a021ddb7dba35 Mon Sep 17 00:00:00 2001 From: Kyle Altendorf Date: Mon, 29 Jul 2024 12:30:05 -0700 Subject: [PATCH] add `poetry check` ... well, check (#18357) * add poetry check ... well, check * add poetry check to pre-commit * touchup * Update activated.sh * Update activated.ps1 --- .github/workflows/upload-pypi-source.yml | 3 +++ .pre-commit-config.yaml | 7 +++++++ activated.ps1 | 6 ++++-- activated.py | 15 +++++++++++++-- activated.sh | 8 ++++++-- 5 files changed, 33 insertions(+), 6 deletions(-) diff --git a/.github/workflows/upload-pypi-source.yml b/.github/workflows/upload-pypi-source.yml index 85a04f7e76..26f04c34da 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 0a89e63331..efceeee634 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 71aad646eb..b6f5c8f859 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 7df915836c..f065cc6d46 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 @@ import sys 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 719edf662e..d44208f378 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" "$@"