diff --git a/.hooks/pre-push b/.hooks/pre-push index eae030a72d..86551f8610 100755 --- a/.hooks/pre-push +++ b/.hooks/pre-push @@ -93,8 +93,43 @@ echo "Running pre push hook!" verify_tag_if_needed run_shellcheck_suite +run_bootstrap_checks() { + echo "Running bootstrap checks..." + local bootstrap_dir="$ROOT_DIR/bootstrap" + local bootstrap_files=() + mapfile -t bootstrap_files < <(find "$bootstrap_dir" -name "*.py" -type f) + + if [ "${#bootstrap_files[@]}" -eq 0 ]; then + echo "No bootstrap Python files found, skipping." + return + fi + + echo "Running isort (bootstrap).." + isort "${isort_args[@]}" "${bootstrap_files[@]}" + + echo "Running black (bootstrap).." + black "${black_args[@]}" "${bootstrap_files[@]}" + + if [ "$fixing" = true ]; then + return + fi + + echo "Running ruff (bootstrap).." + ruff check --config "$CORE_DIR/pyproject.toml" "${bootstrap_files[@]}" + + echo "Running pylint (bootstrap).." + pylint --rcfile "$CORE_DIR/pyproject.toml" "${bootstrap_files[@]}" + + echo "Running mypy (bootstrap).." + mypy --config-file "$CORE_DIR/pyproject.toml" "$bootstrap_dir" +} + if [ "$should_run_primary" = true ]; then run_environment_phase "primary" "$PRIMARY_PROJECT_DIR" "primary" SECONDARY_SCOPE_PATHS EMPTY_PATHS true + # Bootstrap checks reuse the primary venv (run_environment_phase runs in a subshell so we re-activate) + # shellcheck disable=SC1091 + source "$PRIMARY_PROJECT_DIR/.venv/bin/activate" + run_bootstrap_checks fi if [ "$should_run_secondary" = true ]; then if [ "${#SECONDARY_SCOPE_PATHS[@]}" -eq 0 ]; then diff --git a/bootstrap/bootstrap/bootstrap.py b/bootstrap/bootstrap/bootstrap.py index db1e7094fd..df87a563cf 100755 --- a/bootstrap/bootstrap/bootstrap.py +++ b/bootstrap/bootstrap/bootstrap.py @@ -5,7 +5,7 @@ import shutil import sys import time -from typing import Any, Dict +from typing import Any, Dict, Optional from warnings import warn import docker @@ -24,7 +24,7 @@ class Bootstrapper: SETTINGS_NAME_CORE = "core" core_last_response_time = time.monotonic() - def __init__(self, client: docker.DockerClient, low_level_api: docker.APIClient = None) -> None: + def __init__(self, client: docker.DockerClient, low_level_api: Optional[docker.APIClient] = None) -> None: self.version_chooser_is_online = False self.client: docker.DockerClient = client self.core_last_response_time = time.monotonic() @@ -48,8 +48,7 @@ def overwrite_config_file_with_defaults() -> None: Bootstrapper.DOCKER_CONFIG_FILE_PATH, Bootstrapper.DOCKER_CONFIG_FILE_PATH.with_suffix(".json.bak") ) except FileNotFoundError: - # we don't mind if the file is already there - pass + logger.warning(f"File {Bootstrapper.DOCKER_CONFIG_FILE_PATH} not found, creating backup...") shutil.copy(Bootstrapper.DEFAULT_FILE_PATH, Bootstrapper.DOCKER_CONFIG_FILE_PATH) @staticmethod @@ -298,7 +297,7 @@ def run(self) -> None: if time.monotonic() - self.core_last_response_time < 300: continue - # Version choose failed, time to restarted core + # Version chooser failed, time to restart core self.core_last_response_time = time.monotonic() logger.warning("Core has not responded in 5 minutes, resetting to factory...") self.overwrite_config_file_with_defaults() diff --git a/bootstrap/main.py b/bootstrap/main.py index 5701532c99..2b89facfd5 100755 --- a/bootstrap/main.py +++ b/bootstrap/main.py @@ -5,8 +5,8 @@ import docker from loguru import logger -from bootstrap.bootstrap import Bootstrapper +from bootstrap.bootstrap import Bootstrapper if __name__ == "__main__": version = os.environ.get("GIT_DESCRIBE_TAGS", None) diff --git a/bootstrap/test_bootstrap.py b/bootstrap/test_bootstrap.py index 8107fc0b63..8a712ad5c8 100644 --- a/bootstrap/test_bootstrap.py +++ b/bootstrap/test_bootstrap.py @@ -1,9 +1,10 @@ import json +import time from dataclasses import dataclass from pathlib import Path from typing import Any, Dict, Generator, List from unittest.mock import MagicMock, patch -import time + import pytest from docker.errors import NotFound from pyfakefs.fake_filesystem_unittest import TestCase diff --git a/core/pyproject.toml b/core/pyproject.toml index 46c2b6f8f7..2aa3335ba1 100644 --- a/core/pyproject.toml +++ b/core/pyproject.toml @@ -89,6 +89,7 @@ line-length = 120 [tool.isort] profile = "black" +known_first_party = ["bootstrap"] [tool.mypy] allow_untyped_decorators = true