Skip to content

Commit 89fb7bf

Browse files
reorganize and cleanup
1 parent d11107c commit 89fb7bf

File tree

13 files changed

+327
-347
lines changed

13 files changed

+327
-347
lines changed

.devcontainer/devcontainer.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
"python.defaultInterpreterPath": "/workspace/.venv/bin/python",
1616
"python.terminal.activateEnvironment": true,
1717
"python.formatting.provider": "ruff",
18+
"python.analysis.extraPaths": ["./src"],
19+
"python.autoComplete.extraPaths": ["./src"],
1820
"[python]": {
1921
"editor.codeActionsOnSave": {
2022
"source.fixAll": "explicit",

examples/flight.py

Lines changed: 0 additions & 91 deletions
This file was deleted.

pyproject.toml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,18 @@ readme = "README.md"
88
license = { file = "LICENSE" }
99

1010
dependencies = [
11-
"pydantic>=2.10.6,<3.0.0",
12-
"pytz>=2024.2,<2025.0"
11+
"pydantic[email]>=2.10.6,<3.0.0",
12+
"pytz>=2024.2,<2025.0",
1313
]
1414

1515
[tool.pytest.ini_options]
16-
pythonpath = "src"
16+
pythonpath = ["src"]
1717
testpaths = ["tests"]
1818
filterwarnings = ["error"]
1919

20+
[tool.setuptools]
21+
package-dir = { "" = "src" }
22+
2023
[tool.uv]
2124
dev-dependencies = [
2225
"pyright>=1.1.389,<2.0.0",

src/examples/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Example modules demonstrating various features."""

src/examples/flight.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
"""Example of using Pydantic for flight time handling."""
2+
3+
from datetime import datetime, timedelta
4+
5+
from pydantic import BaseModel, Field
6+
7+
8+
class Flight(BaseModel):
9+
"""Represents a flight with departure time and duration."""
10+
11+
# Departure information
12+
departure_airport: str = Field(..., min_length=3, max_length=3)
13+
departure_time: datetime
14+
departure_utc_offset: int = Field(..., ge=-12, le=14) # Hours from UTC
15+
16+
# Arrival information
17+
arrival_airport: str = Field(..., min_length=3, max_length=3)
18+
arrival_utc_offset: int = Field(..., ge=-12, le=14) # Hours from UTC
19+
20+
# Flight duration
21+
duration_minutes: int = Field(..., gt=0)
22+
23+
def calculate_arrival_time(self) -> datetime:
24+
"""Calculate arrival time based on departure time and duration."""
25+
return self.departure_time + timedelta(minutes=self.duration_minutes)
26+
27+
def to_local_times(self) -> dict[str, datetime]:
28+
"""Convert times to their respective timezones."""
29+
departure_local = self.departure_time + timedelta(
30+
hours=self.departure_utc_offset
31+
)
32+
arrival_local = self.calculate_arrival_time() + timedelta(
33+
hours=self.arrival_utc_offset
34+
)
35+
36+
return {
37+
"departure_local": departure_local,
38+
"arrival_local": arrival_local,
39+
}
40+
41+
42+
def main() -> None:
43+
"""Show how to use the Flight class."""
44+
# Example flight from New York to London
45+
flight = Flight(
46+
# Departure information
47+
departure_airport="JFK",
48+
departure_time=datetime(2024, 3, 25, 20, 0), # 8 PM
49+
departure_utc_offset=-4, # EDT (UTC-4)
50+
# Arrival information
51+
arrival_airport="LHR",
52+
arrival_utc_offset=0, # GMT (UTC+0)
53+
# Flight duration
54+
duration_minutes=420, # 7 hours
55+
)
56+
57+
# Calculate arrival time
58+
arrival_time = flight.calculate_arrival_time()
59+
print(f"Arrival time: {arrival_time}")
60+
61+
# Get local times
62+
local_times = flight.to_local_times()
63+
print(f"Departure (local): {local_times['departure_local']}")
64+
print(f"Arrival (local): {local_times['arrival_local']}")
65+
66+
67+
if __name__ == "__main__":
68+
main()

src/examples/user.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""Example of using Pydantic for user data validation."""
2+
3+
from pydantic import BaseModel, EmailStr, Field
4+
5+
from logging_config import get_logger
6+
7+
logger = get_logger(__name__)
8+
9+
10+
class User(BaseModel):
11+
"""Represents a user with basic profile information."""
12+
13+
id: int
14+
name: str = Field(..., min_length=2) # Added min_length validation to match test
15+
email: EmailStr # Using EmailStr for email validation
16+
17+
def to_json(self) -> str: # noqa: D102
18+
return self.model_dump_json()
19+
20+
@classmethod
21+
def from_json(cls, json_str: str) -> "User": # noqa: D102
22+
return cls.model_validate_json(json_str)
23+
24+
25+
def main() -> None:
26+
"""Show how to use the User class."""
27+
user = User(id=1, name="Alice Smith", email="alice.smith@example.com")
28+
29+
print(f"User: {user.name}") # noqa: T201
30+
print(f"Email: {user.email}") # noqa: T201
31+
print(f"ID: {user.id}") # noqa: T201
32+
33+
34+
if __name__ == "__main__":
35+
main()

src/hello_world.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import sys
2+
3+
4+
def main() -> None:
5+
"""Print 'hello world' to the console."""
6+
if len(sys.argv) >= 2:
7+
print(f"hello {sys.argv[1]}!")
8+
else:
9+
print("hello world!")
10+
11+
12+
if __name__ == "__main__":
13+
main()

src/main.py

Lines changed: 0 additions & 52 deletions
This file was deleted.

src/user.py

Lines changed: 0 additions & 26 deletions
This file was deleted.

tests/libs/pytz/test_flight_type.py

Lines changed: 0 additions & 72 deletions
This file was deleted.

0 commit comments

Comments
 (0)