Skip to content
Draft
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
32 changes: 30 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ setup: check_uv
fi
@echo "$(YELLOW)🔄Updating python dependencies...$(RESET)"
@uv sync
@echo "$(YELLOW)📦Installing project in editable mode...$(RESET)"
@uv pip install -e .
@echo "$(GREEN)✅Project installed.$(RESET)"

view_python_venv_size:
@echo "$(YELLOW)🔍Checking python venv size...$(RESET)"
Expand All @@ -82,9 +85,9 @@ view_python_venv_size_by_libraries:
# Run Main Application
########################################################

all: setup setup_githooks
run: setup setup_githooks
@echo "$(GREEN)🏁Running main application...$(RESET)"
@$(PYTHON) main.py
@$(PYTHON) -m miyamura80_demo
@echo "$(GREEN)✅ Main application run completed.$(RESET)"


Expand Down Expand Up @@ -115,6 +118,7 @@ install_tools: check_uv
@uv tool install ruff --force
@uv tool install ty --force
@uv tool install vulture --force
@uv tool install twine --force
@echo "$(GREEN)✅Tools installed.$(RESET)"

fmt: install_tools check_jq
Expand Down Expand Up @@ -151,6 +155,30 @@ ty:
ci: ruff vulture ty ## Run all CI checks (ruff, vulture, ty)
@echo "$(GREEN)✅CI checks completed.$(RESET)"

########################################################
# Deployment
########################################################

build:
@echo "$(YELLOW)🔨Building package...$(RESET)"
@uv pip build
@echo "$(GREEN)✅Package built.$(RESET)"

publish: build
@echo "$(YELLOW)🚀Publishing package...$(RESET)"
@uv tool run twine upload dist/*
@echo "$(GREEN)✅Package published.$(RESET)"

push:
@echo "$(YELLOW)Pushing to Git...$(RESET)"
@git push
@git push --tags
@echo "$(GREEN)✅Pushed to Git.$(RESET)"

all: build publish push ## Build, publish, and push the package
@echo "$(GREEN)✅All tasks completed.$(RESET)"


########################################################
# Dependencies
########################################################
Expand Down
7 changes: 5 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[project]
name = "python-template"
name = "miyamura80-demo"
version = "0.1.0"
description = "Add your description here"
authors = [
Expand Down Expand Up @@ -31,11 +31,14 @@ requires-python = ">= 3.12"
requires = ["hatchling"]
build-backend = "hatchling.build"

[project.scripts]
miyamura80-demo = "miyamura80_demo.__main__:main"

[tool.hatch.metadata]
allow-direct-references = true

[tool.hatch.build.targets.wheel]
packages = ["src/python_template"]
packages = ["src/miyamura80_demo"]

[tool.vulture]
exclude = [
Expand Down
Empty file.
2 changes: 1 addition & 1 deletion main.py → src/miyamura80_demo/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from common import global_config
from .common import global_config


def main():
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
LoggingConfig,
)

# Get the path to the root directory (one level up from common)
root_dir = Path(__file__).parent.parent
# Get the path to the root directory (four levels up from this file)
root_dir = Path(__file__).parent.parent.parent.parent

OPENAI_O_SERIES_PATTERN = r"o(\d+)(-mini)?"

Expand Down Expand Up @@ -54,7 +54,7 @@ def recursive_update(default: dict, override: dict) -> dict:
return default

# Load base config
config_path = root_dir / "common" / "global_config.yaml"
config_path = Path(__file__).parent / "global_config.yaml"
try:
with open(config_path, "r") as file:
config_data = yaml.safe_load(file) or {}
Expand All @@ -65,7 +65,7 @@ def recursive_update(default: dict, override: dict) -> dict:

# Load production config if in prod environment
if os.getenv("DEV_ENV") == "prod":
prod_config_path = root_dir / "common" / "production_config.yaml"
prod_config_path = Path(__file__).parent / "production_config.yaml"
if prod_config_path.exists():
try:
with open(prod_config_path, "r") as file:
Expand Down Expand Up @@ -121,9 +121,6 @@ class Config(BaseSettings):
"""

model_config = SettingsConfigDict(
# Load from .env file (will be handled separately for .prod.env)
env_file=str(root_dir / ".env"),
env_file_encoding="utf-8",
# Allow nested env vars with double underscore
env_nested_delimiter="__",
# Case sensitive for field names
Expand All @@ -132,6 +129,13 @@ class Config(BaseSettings):
extra="allow",
)

def __init__(self, **values: Any):
# Load .env files before initializing the settings
load_dotenv(dotenv_path=root_dir / ".env", override=True)
if os.getenv("DEV_ENV") == "prod":
load_dotenv(dotenv_path=root_dir / ".prod.env", override=True)
super().__init__(**values)

# Top-level fields
model_name: str
dot_global_config_health_check: bool
Expand Down Expand Up @@ -234,14 +238,6 @@ def api_base(self, model_name: str) -> str:
raise ValueError(f"No API base configured for model: {model_name}")


# Load .env files before creating the config instance
# Load .env file first, to get DEV_ENV if it's defined there
load_dotenv(dotenv_path=root_dir / ".env", override=True)

# Now, check DEV_ENV and load .prod.env if it's 'prod', overriding .env
if os.getenv("DEV_ENV") == "prod":
load_dotenv(dotenv_path=root_dir / ".prod.env", override=True)

# Check if .env file has been properly loaded
is_local = os.getenv("GITHUB_ACTIONS") != "true"
if is_local:
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/healthcheck/test_common.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from tests.test_template import TestTemplate
from common import global_config
from miyamura80_demo.common import global_config


class TestCommonHealthCheck(TestTemplate):
Expand Down
2 changes: 1 addition & 1 deletion tests/healthcheck/test_env_var_loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_env_var_loading_precedence(monkeypatch):
with open(dot_env_path, "r") as f:
original_dot_env_content = f.read()

common_module = sys.modules["common.global_config"]
common_module = sys.modules["miyamura80_demo.common.global_config"]

try:
# 1. Set mock system environment variables
Expand Down
2 changes: 1 addition & 1 deletion tests/healthcheck/test_pydantic_type_coercion.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def test_pydantic_type_coercion(monkeypatch):
Test that pydantic-settings automatically coerces environment variable strings
to the correct types (int, float, bool) as defined in the Pydantic models.
"""
common_module = sys.modules["common.global_config"]
common_module = sys.modules["miyamura80_demo.common.global_config"]

# Set environment variables with intentionally "wrong" types (but coercible)
# These should all be automatically converted to the correct types by pydantic-settings
Expand Down
2 changes: 1 addition & 1 deletion tests/test_template.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
from copy import deepcopy
from human_id import generate_id
from common import global_config
from miyamura80_demo.common import global_config

# Markers for slow, and nondeterministic tests
slow_test = pytest.mark.slow
Expand Down
90 changes: 45 additions & 45 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading