From bf65fd495d3da90fc525e285cd1eef6511a7f486 Mon Sep 17 00:00:00 2001 From: Ondrej Samohel Date: Fri, 6 Jan 2023 17:19:02 +0100 Subject: [PATCH] :art: add pre-commit installation to create_env scripts --- .pre-commit-config.yaml | 16 ++++++++++++++++ tools/create_env.ps1 | 8 ++++++++ tools/create_env.sh | 4 +++- 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000000..40159f4344 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,16 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v3.2.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + - id: check-added-large-files + - id: no-commit-to-branch + args: [ '--pattern', '^(?!((enhancement|feature|bugfix|documentation|tests)\/[a-zA-Z0-9\-]+)$).*' ] +- repo: https://github.com/psf/black + rev: 22.12.0 + hooks: + - id: black diff --git a/tools/create_env.ps1 b/tools/create_env.ps1 index 75cba3f65e..5e088df075 100644 --- a/tools/create_env.ps1 +++ b/tools/create_env.ps1 @@ -179,6 +179,14 @@ if ($LASTEXITCODE -ne 0) { Set-Location -Path $current_dir Exit-WithCode 1 } +Write-Color -Text ">>> ", "Installing pre-commit hooks ..." -Color Green, White +& "$env:POETRY_HOME\bin\poetry" run pre-commit install +if ($LASTEXITCODE -ne 0) { + Write-Color -Text "!!! ", "Installation of pre-commit hooks failed." -Color Red, Yellow + Set-Location -Path $current_dir + Exit-WithCode 1 +} + $endTime = [int][double]::Parse((Get-Date -UFormat %s)) Set-Location -Path $current_dir try diff --git a/tools/create_env.sh b/tools/create_env.sh index 1ecd960fe1..f2a33fdd3c 100755 --- a/tools/create_env.sh +++ b/tools/create_env.sh @@ -191,10 +191,12 @@ main () { # reinstalling them solves the problem. echo -e "${BIGreen}>>>${RST} Post-venv creation fixes ..." local openpype_index=$("$POETRY_HOME/bin/poetry" run python "$openpype_root/tools/parse_pyproject.py" tool.poetry.source.0.url) - echo -e "${BIGreen}- ${RST} Using index: ${BIWhite}$openpype_index${RST}" + echo -e "${BIGreen}- ${RST} Using index: ${BIWhite}$openpype_index${RST}" "$POETRY_HOME/bin/poetry" run pip install setuptools==49.6.0 "$POETRY_HOME/bin/poetry" run pip install --disable-pip-version-check --force-reinstall wheel "$POETRY_HOME/bin/poetry" run python -m pip install --disable-pip-version-check --force-reinstall pip + echo -e "${BIGreen}>>>${RST} Installing pre-commit hooks ..." + "$POETRY_HOME/bin/poetry" run pre-commit install } return_code=0