Skip to content

Commit

Permalink
Merge pull request #2 from getsentry/iw/move-config
Browse files Browse the repository at this point in the history
ref(config): Renaming service config and moving it to a config dir
  • Loading branch information
hubertdeng123 authored Sep 4, 2024
2 parents bbf5fa8 + f364441 commit a9547a6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ extend-ignore =
python_version = 3.12
strict = True
ignore_missing_imports = True

[mypy-yaml.*]
ignore_missing_imports = True
10 changes: 5 additions & 5 deletions src/commands/list_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from argparse import ArgumentParser
from argparse import Namespace

from utils.config import load_devservices_config
from configs.service_config import load_service_config


def add_parser(subparsers: _SubParsersAction[ArgumentParser]) -> None:
Expand All @@ -22,14 +22,14 @@ def add_parser(subparsers: _SubParsersAction[ArgumentParser]) -> None:

def list_dependencies(args: Namespace) -> None:
"""List the dependencies of a service."""
config = load_devservices_config(args.service_name)
config = load_service_config(args.service_name)

dependencies = config.devservices_config.dependencies
dependencies = config.service_config.dependencies

if not dependencies:
print(f"No dependencies found for {config.devservices_config.service_name}")
print(f"No dependencies found for {config.service_config.service_name}")
return

print(f"Dependencies of {config.devservices_config.service_name}:")
print(f"Dependencies of {config.service_config.service_name}:")
for dependency_key, dependency_info in dependencies.items():
print("-", dependency_key, ":", dependency_info.description)
12 changes: 6 additions & 6 deletions src/utils/config.py → src/configs/service_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
from pydantic import BaseModel
from pydantic import Field
from pydantic import validator
from utils.devenv import get_code_root
from utils.devenv import get_coderoot


class Dependency(BaseModel):
description: str
link: Optional[str] = None


class DevservicesConfig(BaseModel):
class ServiceConfig(BaseModel):
version: float
service_name: str
dependencies: Dict[str, Dependency]
Expand Down Expand Up @@ -51,10 +51,10 @@ def check_modes(


class Config(BaseModel):
devservices_config: DevservicesConfig = Field(alias="x-sentry-devservices-config")
service_config: ServiceConfig = Field(alias="x-sentry-service-config")


def load_devservices_config(service_name: Optional[str]) -> Config:
def load_service_config(service_name: Optional[str]) -> Config:
"""Load the devservices config for a service."""
if not service_name:
current_dir = os.getcwd()
Expand All @@ -66,8 +66,8 @@ def load_devservices_config(service_name: Optional[str]) -> Config:
f"Config file not found in current directory: {config_path}"
)
else:
code_root = get_code_root()
service_path = os.path.join(code_root, service_name)
coderoot = get_coderoot()
service_path = os.path.join(coderoot, service_name)
config_path = os.path.join(
service_path, DEVSERVICES_DIR_NAME, DOCKER_COMPOSE_FILE_NAME
)
Expand Down
2 changes: 1 addition & 1 deletion src/utils/devenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from devenv.lib.config import read_config


def get_code_root() -> str:
def get_coderoot() -> str:
config_path = os.path.join(home, ".config", "sentry-devenv", "config.ini")
try:
devenv_config: ConfigParser = read_config(config_path)
Expand Down

0 comments on commit a9547a6

Please sign in to comment.