Skip to content
Open
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
35 changes: 35 additions & 0 deletions .hooks/pre-push
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions bootstrap/bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion bootstrap/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion bootstrap/test_bootstrap.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions core/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ line-length = 120

[tool.isort]
profile = "black"
known_first_party = ["bootstrap"]

[tool.mypy]
allow_untyped_decorators = true
Expand Down