Skip to content

Commit 90804bd

Browse files
committed
feat: add pydantic-extra-types for enhanced coordinate handling and update weather settings
1 parent f91f818 commit 90804bd

6 files changed

Lines changed: 64 additions & 2 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ dependencies = [
1212
"loguru>=0.7.3",
1313
"pathlib>=1.0.1",
1414
"pydantic>=2.12.5",
15+
"pydantic-extra-types>=2.11.0",
1516
"pydantic-settings>=2.12.0",
1617
"pyfiglet>=1.0.4",
1718
"pylint>=4.0.4",

src/sample_python_app/core/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
Export core modules for use in other modules.
33
"""
44

5-
from sample_python_app.core.config import settings
5+
from sample_python_app.core.config import settings, weather_settings
66
from sample_python_app.core.data_loader import fetch_astronomical_data_from_api
77
from sample_python_app.core.display import display_astronomical_data
88
from sample_python_app.core.logging import setup_logger
99

1010
__all__ = [
1111
"settings",
12+
"weather_settings",
1213
"setup_logger",
1314
"display_astronomical_data",
1415
"fetch_astronomical_data_from_api",

src/sample_python_app/core/config.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,22 @@
44

55
from zoneinfo import ZoneInfo
66

7+
from pydantic_extra_types.coordinate import Coordinate, Latitude, Longitude
78
from pydantic_settings import BaseSettings, SettingsConfigDict
89

910

11+
class WeatherSettings(BaseSettings):
12+
"""Weather-related settings."""
13+
14+
LOCATION: Coordinate = Coordinate(Latitude(29.8469), Longitude(-95.4689))
15+
16+
model_config = SettingsConfigDict(
17+
env_file=".env",
18+
env_file_encoding="utf-8",
19+
case_sensitive=False,
20+
)
21+
22+
1023
class Settings(BaseSettings):
1124
"""Application settings display."""
1225

@@ -26,3 +39,4 @@ def tz(self) -> ZoneInfo:
2639

2740

2841
settings = Settings()
42+
weather_settings = WeatherSettings()

src/sample_python_app/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111
from sample_python_app.core import (
1212
display_astronomical_data,
1313
fetch_astronomical_data_from_api,
14+
weather_settings,
1415
)
1516

1617

1718
def run_app():
18-
lat, lon = 29.8469, -95.4689
19+
lat, lon = weather_settings.LOCATION.latitude, weather_settings.LOCATION.longitude
1920
try:
2021
astro = fetch_astronomical_data_from_api(lat, lon)
2122
except httpx.HTTPStatusError as e:

tests/test_config.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from sample_python_app.core.config import settings, weather_settings
2+
3+
4+
def test_settings_fields():
5+
assert settings.APP_NAME == "python-app-template"
6+
assert settings.DATE_FORMAT
7+
assert settings.TIMEZONE
8+
9+
10+
def test_settings_tz_property():
11+
tz = settings.tz
12+
# ZoneInfo does not have a 'zone' attribute; use 'key' for the timezone name
13+
assert tz.key == settings.TIMEZONE
14+
15+
16+
def test_weather_settings_location():
17+
loc = weather_settings.LOCATION
18+
assert loc.latitude == 29.8469
19+
assert loc.longitude == -95.4689
20+
21+
22+
def test_settings_instantiation_and_model_config():
23+
# Explicitly instantiate settings classes
24+
s = type(settings)()
25+
ws = type(weather_settings)()
26+
# Access model_config (should exist and be a dict-like object)
27+
assert hasattr(s, "model_config")
28+
assert hasattr(ws, "model_config")
29+
# Access tz property again for coverage
30+
assert isinstance(s.tz, type(settings.tz))

uv.lock

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)