Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add poetry check ... well, check #18357

Merged
merged 5 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/upload-pypi-source.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 4 additions & 2 deletions activated.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 13 additions & 2 deletions activated.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations

import enum
import os
import pathlib
import subprocess
Expand All @@ -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)

Expand Down
8 changes: 6 additions & 2 deletions activated.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

"$@"
Loading