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

Run inv install-tools and inv dowload-tools as part of inv setup #25656

Merged
merged 2 commits into from
May 17, 2024
Merged
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
50 changes: 42 additions & 8 deletions tasks/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@
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

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:
Expand All @@ -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,
]

Expand Down Expand Up @@ -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:
Expand All @@ -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:
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:
status = Status.FAIL

return SetupResult("Download Go tools", status)
Loading