From 30607baa154f3858336f954e8853976a8a8a7328 Mon Sep 17 00:00:00 2001 From: Florent Clarret Date: Thu, 16 May 2024 14:17:59 +0200 Subject: [PATCH 1/2] Run 'inv install-tools' and 'inv dowload-tools' as part of 'inv setup' --- tasks/setup.py | 50 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 42 insertions(+), 8 deletions(-) diff --git a/tasks/setup.py b/tasks/setup.py index 2b9b149421865..2c67e5e751d06 100644 --- a/tasks/setup.py +++ b/tasks/setup.py @@ -8,6 +8,7 @@ import sys from collections.abc import Iterable from dataclasses import dataclass +from typing import TYPE_CHECKING from invoke import task from invoke.exceptions import Exit @@ -15,6 +16,11 @@ from tasks.libs.common.color import color_message from tasks.libs.common.status import Status +if TYPE_CHECKING: + from collections.abc import Generator + +PYTHON_REQUIREMENTS = ["requirements.txt", "tasks/requirements.txt"] + @dataclass class SetupResult: @@ -32,7 +38,9 @@ def setup(ctx): check_python_version, check_go_version, check_git_repo, - update_dependencies, + update_python_dependencies, + download_go_tools, + install_go_tools, enable_pre_commit, ] @@ -131,16 +139,14 @@ def check_python_version(_ctx) -> SetupResult: return SetupResult("Check Python version", status, message) -def update_dependencies(ctx) -> Iterable[SetupResult]: - print(color_message("Updating dependencies...", "blue")) - - requirement_files = ["requirements.txt", "tasks/requirements.txt"] +def update_python_dependencies(ctx) -> Generator[SetupResult]: + print(color_message("Updating Python dependencies...", "blue")) - for requirement_file in requirement_files: - print(color_message(f"Updating {requirement_file}...", "blue")) + for requirement_file in PYTHON_REQUIREMENTS: + print(color_message(f"Updating Python dependencies from {requirement_file}...", "blue")) ctx.run(f"pip install -r {requirement_file}", hide=True) - yield SetupResult(f"Update dependencies from {requirement_file}", Status.OK) + yield SetupResult(f"Update Python dependencies from {requirement_file}", Status.OK) def enable_pre_commit(ctx) -> SetupResult: @@ -164,3 +170,31 @@ def enable_pre_commit(ctx) -> SetupResult: ctx.run(f"git config --global core.hooksPath {hooks_path}", hide=True) return SetupResult("Enable pre-commit", Status.OK) + + +def install_go_tools(ctx) -> SetupResult: + print(color_message("Installing go tools...", "blue")) + status = Status.OK + + try: + from tasks import install_tools + + install_tools(ctx) + except Exception: + status = Status.FAIL + + return SetupResult("Install Go tools", status) + + +def download_go_tools(ctx) -> SetupResult: + print(color_message("Downloading go tools...", "blue")) + status = Status.OK + + try: + from tasks import download_tools + + download_tools(ctx) + except Exception: + status = Status.FAIL + + return SetupResult("Download Go tools", status) From 1b58e8aaeb1287f35e1834b9c545350099eebb09 Mon Sep 17 00:00:00 2001 From: Florent Clarret Date: Thu, 16 May 2024 14:28:25 +0200 Subject: [PATCH 2/2] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: CĂ©lian Raimbault <161456554+CelianR@users.noreply.github.com> --- tasks/setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tasks/setup.py b/tasks/setup.py index 2c67e5e751d06..21467efc2b294 100644 --- a/tasks/setup.py +++ b/tasks/setup.py @@ -180,7 +180,7 @@ def install_go_tools(ctx) -> SetupResult: from tasks import install_tools install_tools(ctx) - except Exception: + except: status = Status.FAIL return SetupResult("Install Go tools", status) @@ -194,7 +194,7 @@ def download_go_tools(ctx) -> SetupResult: from tasks import download_tools download_tools(ctx) - except Exception: + except: status = Status.FAIL return SetupResult("Download Go tools", status)