Skip to content

Commit 34362e4

Browse files
authored
Merge pull request #309 from python-ellar/code_documentation
chores: Adding more code documentation Part 1
2 parents 45e9816 + 327ad52 commit 34362e4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+964
-271
lines changed

ellar/app/context.py

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@
1616
@ensure_build_context(app_ready=True)
1717
def ensure_available_in_providers(*items: t.Any) -> None:
1818
"""
19-
Ensures that Providers at least belows to a particular module
20-
:param items:
21-
:return:
19+
Ensures that Providers belong to a particular module.
20+
21+
If a provider is not found in any existing module, it is added to the
22+
application module and exported.
23+
24+
:param items: List of providers to check.
2225
"""
2326
app_module = current_injector.tree_manager.get_app_module()
2427

@@ -43,9 +46,9 @@ def _(data: TreeData) -> bool:
4346
@ensure_build_context(app_ready=True)
4447
def use_authentication_schemes(*authentication: AuthenticationHandlerType) -> None:
4548
"""
46-
Registered Authentication Handlers to the application
47-
:param authentication:
48-
:return:
49+
Registers Authentication Handlers to the application.
50+
51+
:param authentication: List of authentication handlers or schemes.
4952
"""
5053
__identity_scheme = current_injector.get(IIdentitySchemes)
5154
for auth in authentication:
@@ -58,9 +61,9 @@ def use_exception_handler(
5861
*exception_handlers: IExceptionHandler,
5962
) -> None:
6063
"""
61-
Adds Application Exception Handlers
62-
:param exception_handlers: IExceptionHandler
63-
:return:
64+
Adds Application Exception Handlers.
65+
66+
:param exception_handlers: List of exception handlers to register.
6467
"""
6568
for exception_handler in exception_handlers:
6669
if exception_handler not in current_config.EXCEPTION_HANDLERS:
@@ -78,12 +81,12 @@ def enable_versioning(
7881
**init_kwargs: t.Any,
7982
) -> None:
8083
"""
81-
Enables an Application Versioning scheme
82-
:param schema: VersioningSchemes
83-
:param version_parameter: versioning parameter lookup key. Default: 'version'
84-
:param default_version: versioning default value. Default: None
85-
:param init_kwargs: Other schema initialization keyword args.
86-
:return:
84+
Enables an Application Versioning scheme.
85+
86+
:param schema: The versioning scheme to use (e.g., URL, Header, Query).
87+
:param version_parameter: The parameter name for version lookup. Default: 'version'.
88+
:param default_version: The default version to use if none is specified. Default: None.
89+
:param init_kwargs: Additional initialization arguments for the versioning scheme.
8790
"""
8891
current_config.VERSIONING_SCHEME = schema.value(
8992
version_parameter=version_parameter,
@@ -97,9 +100,9 @@ def use_global_guards(
97100
*guards: t.Union[GuardCanActivate, t.Type[GuardCanActivate]],
98101
) -> None:
99102
"""
100-
Registers Application Global Guards that affects all routes registered in ApplicationRouter
101-
:param guards:
102-
:return: None
103+
Registers Application Global Guards that affect all routes registered in the ApplicationRouter.
104+
105+
:param guards: List of guards to register globally.
103106
"""
104107
current_config.GLOBAL_GUARDS = list(current_config.GLOBAL_GUARDS) + list(guards)
105108
ensure_available_in_providers(*guards)
@@ -110,9 +113,9 @@ def use_global_interceptors(
110113
*interceptors: t.Union[EllarInterceptor, t.Type[EllarInterceptor]],
111114
) -> None:
112115
"""
113-
Registers Application Global Interceptor that affects all routes registered in ApplicationRouter
114-
:param interceptors:
115-
:return: None
116+
Registers Application Global Interceptors that affect all routes registered in the ApplicationRouter.
117+
118+
:param interceptors: List of interceptors to register globally.
116119
"""
117120
current_config.GLOBAL_INTERCEPTORS = list(
118121
current_config.GLOBAL_INTERCEPTORS

ellar/app/factory.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@
3434

3535
class AppFactory:
3636
"""
37-
Factory for creating Ellar Application
37+
Factory for creating Ellar Application instances.
38+
39+
Provides methods to create an application from a module, controller, or existing app module.
3840
"""
3941

4042
@classmethod
@@ -189,6 +191,22 @@ def create_app(
189191
config_module: t.Union[str, t.Dict, None] = None,
190192
injector: t.Optional[EllarInjector] = None,
191193
) -> App:
194+
"""
195+
Creates an Ellar Application instance.
196+
197+
:param controllers: List of controllers to register.
198+
:param routers: List of routers to register.
199+
:param providers: List of providers to register.
200+
:param modules: List of modules to register.
201+
:param template_folder: Path to the template folder.
202+
:param base_directory: Path to the base directory.
203+
:param static_folder: Name of the static folder. Default: "static".
204+
:param global_guards: List of global guards to register.
205+
:param commands: List of commands to register.
206+
:param config_module: Configuration module or dictionary.
207+
:param injector: Optional existing injector instance.
208+
:return: Configured App instance.
209+
"""
192210
module = Module(
193211
controllers=controllers,
194212
routers=routers,
@@ -219,6 +237,15 @@ def create_from_app_module(
219237
injector: t.Optional[EllarInjector] = None,
220238
config_module: t.Union[str, t.Dict, None] = None,
221239
) -> App:
240+
"""
241+
Creates an Ellar Application from an existing Application Module.
242+
243+
:param module: The application module class.
244+
:param global_guards: List of global guards to register.
245+
:param injector: Optional existing injector instance.
246+
:param config_module: Configuration module or dictionary.
247+
:return: Configured App instance.
248+
"""
222249
app = cls._create_app(
223250
module,
224251
config_module=config_module,

ellar/app/main.py

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@
4444

4545

4646
class App:
47+
"""
48+
The main Ellar Application class.
49+
"""
50+
4751
def __init__(
4852
self,
4953
config: "Config",
@@ -117,6 +121,11 @@ def get_interceptors(
117121
async def use_global_guards(
118122
self, *guards: t.Union["GuardCanActivate", t.Type["GuardCanActivate"]]
119123
) -> None:
124+
"""
125+
Registers global guards for the application.
126+
127+
:param guards: Guards to register.
128+
"""
120129
async with self.with_injector_context():
121130
use_global_guards(*guards)
122131

@@ -125,6 +134,11 @@ async def use_global_guards(
125134
async def use_global_interceptors(
126135
self, *interceptors: t.Union[EllarInterceptor, t.Type[EllarInterceptor]]
127136
) -> None:
137+
"""
138+
Registers global interceptors for the application.
139+
140+
:param interceptors: Interceptors to register.
141+
"""
128142
async with self.with_injector_context():
129143
use_global_interceptors(*interceptors)
130144

@@ -173,11 +187,13 @@ def request_context(
173187
send: TSend = constants.empty_send,
174188
) -> HttpRequestConnectionContext:
175189
"""
176-
Create an RequestContext during request and provides instance for `current_connection`.
177-
e.g
190+
Creates a RequestContext during a request and provides an instance for `current_connection`.
178191
192+
Example:
193+
```python
179194
request = current_connection.switch_http_connection().get_request()
180195
websocket = current_connection.switch_to_websocket().get_client()
196+
```
181197
"""
182198
context_factory = self.injector.get(IHostContextFactory)
183199
return HttpRequestConnectionContext(
@@ -226,6 +242,14 @@ async def enable_versioning(
226242
default_version: t.Optional[str] = None,
227243
**init_kwargs: t.Any,
228244
) -> None:
245+
"""
246+
Enables API versioning for the application.
247+
248+
:param schema: Versioning scheme to use.
249+
:param version_parameter: Parameter name for versioning.
250+
:param default_version: Default version if none specified.
251+
:param init_kwargs: Additional arguments for the versioning scheme.
252+
"""
229253
async with self.with_injector_context():
230254
enable_versioning(
231255
schema,
@@ -262,6 +286,11 @@ async def add_exception_handler(
262286
self,
263287
*exception_handlers: IExceptionHandler,
264288
) -> None:
289+
"""
290+
Registers global exception handlers.
291+
292+
:param exception_handlers: Exception handlers to register.
293+
"""
265294
async with self.with_injector_context():
266295
use_exception_handler(*exception_handlers)
267296

@@ -274,6 +303,11 @@ def reflector(self) -> Reflector:
274303
async def add_authentication_schemes(
275304
self, *authentication: AuthenticationHandlerType
276305
) -> None:
306+
"""
307+
Registers authentication schemes for the application.
308+
309+
:param authentication: Authentication schemes to register.
310+
"""
277311
async with self.with_injector_context():
278312
use_authentication_schemes(*authentication)
279313

@@ -319,7 +353,11 @@ def url_for(context: t.Dict, name: str, **path_params: t.Any) -> URL:
319353
return jinja_env
320354

321355
def setup_jinja_environment(self) -> Environment:
322-
"""Sets up Jinja2 Environment and adds it to DI"""
356+
"""
357+
Sets up the Jinja2 Environment and adds it to the dependency injection container.
358+
359+
:return: Configured Jinja2 Environment.
360+
"""
323361
jinja_environment = self._create_jinja_environment()
324362

325363
self.injector.tree_manager.get_app_module().add_provider(

0 commit comments

Comments
 (0)