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

move imports into functions to allow invoke execution #5160

Merged
merged 4 commits into from
Dec 5, 2024
Merged
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
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ jobs:
# with:
# submodules: true
# - name: "Install Invoke"
# run: "pip install invoke ruamel-yaml semver toml"
# run: "pip install invoke toml"

# - name: "Set environment variables"
# run: echo INFRAHUB_BUILD_NAME=infrahub-${{ runner.name }} >> $GITHUB_ENV
Expand Down Expand Up @@ -403,7 +403,7 @@ jobs:
run: |
pipx install poetry
poetry config virtualenvs.prefer-active-python true
pip install invoke ruamel-yaml semver toml
pip install invoke toml
- name: "Install Package"
run: "poetry install"
- name: "Run validator"
Expand Down Expand Up @@ -486,7 +486,7 @@ jobs:
- name: "Install dependencies"
run: npm install
- name: "Setup Python environment"
run: "pip install invoke ruamel-yaml semver toml"
run: "pip install invoke toml"
- name: "Build website"
run: "invoke docs.build"

Expand All @@ -509,7 +509,7 @@ jobs:
with:
python-version: "3.12"
- name: "Setup environment"
run: "pip install invoke ruamel-yaml semver toml"
run: "pip install invoke toml"
- name: "Build Test Image"
run: "invoke dev.build"
- name: "Validate generated documentation"
Expand Down Expand Up @@ -613,7 +613,7 @@ jobs:
cache-dependency-path: frontend/app/package-lock.json

- name: Install Invoke
run: pip install invoke ruamel-yaml semver toml
run: pip install invoke toml

- name: Set job name
run: echo JOB_NAME="$GITHUB_JOB" >> $GITHUB_ENV
Expand Down Expand Up @@ -784,7 +784,7 @@ jobs:

- name: Install Invoke
run: |
pip install invoke ruamel-yaml semver toml
pip install invoke toml

- name: Set job name
run: echo JOB_NAME="$GITHUB_JOB" >> $GITHUB_ENV
Expand Down
5 changes: 4 additions & 1 deletion tasks/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from typing import TYPE_CHECKING, Any

from invoke import Context, task
from semver import Version

from tasks.shared import init_yaml_obj
from tasks.utils import (
Expand Down Expand Up @@ -104,6 +103,8 @@ def ship(context: Context) -> None:
def update_helm_chart(context: Context, chart_file: str | None = "helm/Chart.yaml") -> None:
"""Update helm/Chart.yaml with the current version from pyproject.toml."""
print(" - [release] Update Helm chart")
from semver import Version

app_version: Version = Version.parse(get_version_from_pyproject(), optional_minor_and_patch=True)

yaml: YAML = init_yaml_obj()
Expand Down Expand Up @@ -143,6 +144,8 @@ def update_helm_chart(context: Context, chart_file: str | None = "helm/Chart.yam
def update_docker_compose(context: Context, docker_file: str | None = "docker-compose.yml") -> None:
"""Update docker-compose.yml with the current version from pyproject.toml."""
print(" - [release] Update docker-compose.yml")
from semver import Version

version: Version = Version.parse(get_version_from_pyproject(), optional_minor_and_patch=True)

yaml: YAML = init_yaml_obj(line_length=4096)
Expand Down
16 changes: 11 additions & 5 deletions tasks/shared.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
from __future__ import annotations

import os
import platform
import re
import sys
from enum import Enum
from pathlib import Path
from typing import Optional, Union
from typing import TYPE_CHECKING

from invoke import Context, UnexpectedExit
from invoke.runners import Result
from ruamel.yaml import YAML

from .utils import get_yamllint_rules, str_to_bool

if TYPE_CHECKING:
from invoke.runners import Result
from ruamel.yaml.main import YAML


class DatabaseType(str, Enum):
NEO4J = "neo4j"
Expand Down Expand Up @@ -226,7 +230,7 @@ def get_compose_cmd(namespace: Namespace) -> str:
return "docker compose"


def execute_command(context: Context, command: str, print_cmd: bool = False) -> Optional[Result]:
def execute_command(context: Context, command: str, print_cmd: bool = False) -> Result | None:
params = check_environment(context=context)

if params["sudo"]:
Expand Down Expand Up @@ -305,7 +309,7 @@ def build_dev_compose_files_cmd(database: str) -> str:


def build_test_compose_files_cmd(
database: Union[bool, str] = DatabaseType.MEMGRAPH.value,
database: bool | str = DatabaseType.MEMGRAPH.value,
) -> str:
if database is False:
return f"-f {TEST_COMPOSE_FILE}"
Expand Down Expand Up @@ -362,6 +366,8 @@ def init_yaml_obj(line_length: int | None = None) -> YAML:
Returns:
YAML: Instantiated ruamel.yaml.YAML object..
"""
from ruamel.yaml import YAML

yamllint_rules: dict = get_yamllint_rules()

yaml = YAML(typ="rt")
Expand Down
3 changes: 2 additions & 1 deletion tasks/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from typing import Tuple

from invoke import Context, UnexpectedExit
from ruamel.yaml import YAML

try:
import toml
Expand Down Expand Up @@ -110,6 +109,8 @@ def get_version_from_pyproject() -> str:


def get_yamllint_rules() -> dict:
from ruamel.yaml import YAML

yaml = YAML(typ="rt")
yamllint_rules = yaml.load(Path(".yamllint.yml"))
return yamllint_rules
Loading