Skip to content

Commit b48e405

Browse files
authored
chore: Update .gitignore and pyproject.toml for improved dependency management and ignore patterns (#6)
1 parent 8ad576a commit b48e405

File tree

6 files changed

+41
-33
lines changed

6 files changed

+41
-33
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,10 @@ cython_debug/
160160
# and can be added to the global gitignore or merged into this file. For a more nuclear
161161
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
162162
#.idea/
163+
164+
src/
165+
app-config.json
166+
application-properties.json
167+
main.py
168+
pdm.lock
169+
*.db

py_spring_model/core/model.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import contextlib
2-
from typing import ClassVar, Iterator, Optional, Type, Self
2+
from typing_extensions import Self
3+
from typing import ClassVar, Iterator, Optional, Type
34
from loguru import logger
45
from sqlalchemy import Engine, MetaData
56
from sqlalchemy.engine.base import Connection

py_spring_model/py_spring_model_provider.py

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33

44
import py_spring_core.core.utils as core_utils
55
from loguru import logger
6-
from py_spring_core import Component, EntityProvider
7-
from py_spring_core.core.application.context.application_context import (
8-
ApplicationContext,
9-
)
6+
from py_spring_core import Component, EntityProvider, ApplicationContextRequired
107
from sqlalchemy import create_engine
118
from sqlalchemy.exc import InvalidRequestError as SqlAlehemyInvalidRequestError
129
from sqlmodel import SQLModel
@@ -26,7 +23,7 @@
2623
class ApplicationContextNotSetError(Exception): ...
2724

2825

29-
class PySpringModelProvider(EntityProvider, Component):
26+
class PySpringModelProvider(EntityProvider, Component, ApplicationContextRequired):
3027
"""
3128
The `PySpringModelProvider` class is responsible for initializing the PySpring model provider, which includes:
3229
- Grouping file paths into class files and model files
@@ -38,15 +35,22 @@ class PySpringModelProvider(EntityProvider, Component):
3835
This class is a key component in the PySpring model infrastructure, handling the setup and initialization of the model-related functionality.
3936
"""
4037

41-
props: PySpringModelProperties
38+
def _get_props(self) -> PySpringModelProperties:
39+
app_context = self.get_application_context()
40+
assert app_context is not None
41+
props = app_context.get_properties(PySpringModelProperties)
42+
assert props is not None
43+
return props
4244

4345
def _group_file_paths(self, files: Iterable[str]) -> ApplicationFileGroups:
46+
props = self._get_props()
47+
4448
class_files: set[str] = set()
4549
model_files: set[str] = set()
4650

4751
for file in files:
4852
py_file_name = self._get_file_base_name(file)
49-
if py_file_name in self.props.model_file_postfix_patterns:
53+
if py_file_name in props.model_file_postfix_patterns:
5054
model_files.add(file)
5155
if file not in model_files:
5256
class_files.add(file)
@@ -76,6 +80,7 @@ def import_func_wrapper() -> set[type[object]]:
7680
self._model_classes = self._get_pyspring_model_inheritors()
7781

7882
def _is_from_model_file(self, cls: Type[object]) -> bool:
83+
props = self._get_props()
7984
try:
8085
source_file_name = inspect.getsourcefile(cls)
8186
except TypeError as error:
@@ -86,7 +91,7 @@ def _is_from_model_file(self, cls: Type[object]) -> bool:
8691
if source_file_name is None:
8792
return False
8893
py_file_name = self._get_file_base_name(source_file_name) # e.g., models.py
89-
return py_file_name in self.props.model_file_postfix_patterns
94+
return py_file_name in props.model_file_postfix_patterns
9095

9196
def _get_file_base_name(self, file_path: str) -> str:
9297
return file_path.split("/")[-1]
@@ -126,34 +131,30 @@ def _create_all_tables(self) -> None:
126131
RepositoryBase.connection = self.sql_engine.connect()
127132

128133
def provider_init(self) -> None:
129-
self.app_context: ApplicationContext
134+
props = self._get_props()
130135
logger.info(
131136
f"[PYSPRING MODEL PROVIDER INIT] Initialize PySpringModelProvider with app context: {self.app_context}"
132137
)
133-
if self.app_context is None:
134-
raise ApplicationContextNotSetError(
135-
"AppContext is not set by the framework"
136-
)
138+
app_context = self.get_application_context()
137139

138-
self.app_file_groups = self._group_file_paths(self.app_context.all_file_paths)
140+
self.app_file_groups = self._group_file_paths(app_context.all_file_paths)
139141
self.sql_engine = create_engine(
140-
url=self.props.sqlalchemy_database_uri, echo=True
142+
url=props.sqlalchemy_database_uri, echo=True
141143
)
142-
if self.app_context is None:
143-
raise ApplicationContextNotSetError(
144-
"AppContext is not set by the framework"
145-
)
146144
self._import_model_modules()
147145
self._create_all_tables()
148146

149147

150148
def provide_py_spring_model() -> EntityProvider:
151149
return PySpringModelProvider(
152-
rest_controller_classes=[PySpringModelRestController],
150+
rest_controller_classes=[
151+
# PySpringModelRestController
152+
],
153153
component_classes=[
154-
PySpringModelProvider,
155-
PySpringModelRestService,
156-
CrudRepositoryImplementationService,
157-
], # injecting self for getting properties
158-
properties_classes=[PySpringModelProperties],
154+
# PySpringModelRestService,
155+
# CrudRepositoryImplementationService,
156+
],
157+
properties_classes=[
158+
PySpringModelProperties
159+
],
159160
)

py_spring_model/py_spring_model_rest/controller/py_spring_model_rest_controller.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class PySpringModelRestController(RestController):
1717

1818
rest_service: PySpringModelRestService
1919

20-
def register_routes(self) -> None:
20+
def post_construct(self) -> None:
2121
self._register_resource_for_models()
2222

2323
def _register_resource_for_models(self) -> None:

py_spring_model/py_spring_model_rest/service/curd_repository_implementation_service/crud_repository_implementation_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def decorator(func: Callable[P, RT]) -> Callable[P, RT]:
172172
func_full_name = func.__qualname__
173173
CrudRepositoryImplementationService.add_skip_function(func_full_name)
174174
@functools.wraps(func)
175-
def wrapper(*args, **kwargs) -> RT:
175+
def wrapper(*args: P.args, **kwargs: P.kwargs) -> RT:
176176
nonlocal query_template
177177
RETURN = "return"
178178

pyproject.toml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ authors = [
66
{name = "William Chen", email = "william_w_chen@trendmicro.com"},
77
]
88
dependencies = [
9-
"py-spring-core>=0.0.5",
10-
"isort>=5.13.2",
11-
"sqlmodel>=0.0.22",
9+
"py-spring-core>=0.0.13",
10+
"sqlmodel>=0.0.24",
1211
]
13-
requires-python = ">=3.11"
12+
13+
requires-python = ">=3.10, <3.13"
1414
readme = "README.md"
1515
license = {text = "MIT"}
1616

@@ -30,4 +30,3 @@ dev = [
3030
"pytest>=8.3.2",
3131
"pytest-mock>=3.14.0",
3232
]
33-

0 commit comments

Comments
 (0)