Skip to content

Commit 5a57e08

Browse files
committed
Rewrote some docs and added docs on modulesetup and dynamic setup
1 parent b5a6ed6 commit 5a57e08

File tree

4 files changed

+75
-28
lines changed

4 files changed

+75
-28
lines changed

README.md

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,15 @@ If you are familiar with these frameworks, you will find it easy to understand a
4040
## Installation
4141
### Poetry Installation
4242
For [Poetry](https://python-poetry.org/) usages
43+
4344
```shell
44-
poetry add ellar[standard]
45+
poetry add ellar-cli
4546
```
4647

4748
### Pip Installation
4849
For normal pip installation
4950
```shell
50-
pip install ellar[standard]
51-
```
52-
### NB:
53-
Some shells may treat square braces (`[` and `]`) as special characters. If that's the case here, then use a quote around the characters to prevent unexpected shell expansion.
54-
```shell
55-
pip install "ellar[standard]"
51+
pip install ellar-cli
5652
```
5753

5854
## Create a project
@@ -234,7 +230,6 @@ Ellar is not aware of `CarModule` yet, so we need to add it to the `modules` lis
234230
```python
235231
from ellar.common import Module, exception_handler
236232
from ellar.core import IHostContext, ModuleBase
237-
from ellar.core.connection import Request
238233
from ellar.core.response import JSONResponse, Response
239234

240235
from ellar.samples.modules import HomeModule

mkdocs.yml

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,25 @@ site_url: https://github.com/eadwinCode/ellar
44
repo_name: eadwinCode/ellar
55
repo_url: https://github.com/eadwinCode/ellar
66
edit_uri: blob/master/docs
7+
copyright: |
8+
Copyright &copy; 2021 - 2023 <a href="https://github.com/eadwinCode" target="_blank" rel="noopener">Eadwin Ezeudoh</a>
79
810
docs_dir: docs
911
site_dir: site
1012

1113
theme:
1214
name: material
15+
features:
16+
- announce.dismiss
17+
- content.action.edit
18+
- content.action.view
19+
- content.code.annotate
20+
- content.code.copy
21+
- content.tooltips
22+
- search.highlight
23+
- search.share
24+
- search.suggest
25+
- toc.follow
1326
palette:
1427
- media: "(prefers-color-scheme: light)"
1528
scheme: default
@@ -26,15 +39,22 @@ theme:
2639
toggle:
2740
icon: material/lightbulb-outline
2841
name: Switch to light mode
29-
42+
font:
43+
text: Roboto
44+
code: Roboto Mono
3045
language: en
3146
logo: img/Icon.svg
3247
favicon: img/Icon.svg
3348
icon:
3449
repo: fontawesome/brands/git-alt
3550

3651
plugins:
37-
- search
52+
- search:
53+
separator: '[\s\-,:!=\[\]()"`/]+|\.(?!\d)|&[lg]t;|(?!\b)(?=[A-Z][a-z])'
54+
- minify:
55+
minify_html: true
56+
- git-revision-date-localized:
57+
enable_creation_date: false
3858

3959
nav:
4060
- Introduction: index.md
@@ -45,7 +65,7 @@ nav:
4565
- Modules: overview/modules.md
4666
- Middlewares: overview/middleware.md
4767
- Exception Handling: overview/exception_handling.md
48-
# - Guards: overview/guards.md
68+
- Guards: overview/guards.md
4969
- Custom Decorators: overview/custom_decorators.md
5070
- Module Router: overview/module-router.md
5171
- Configuration: configurations.md
@@ -66,11 +86,20 @@ nav:
6686
- Static Files: templating/staticfiles.md
6787

6888
- Caching: caching.md
89+
- Rate Limiting: throttling.md
6990
# - Injection Scopes: basics/injection-scope.md
7091
# - Model View Controller: basics/model-view-controller.md
7192
# - Events: basics/events.md
93+
- Commands:
94+
- Introduction: commands/index.md
95+
- Commands:
96+
- new: commands/new-command.md
97+
- create project: commands/create-project-command.md
98+
- create module: commands/create-module-command.md
99+
- runserver: commands/runserver-command.md
100+
- Custom Commands: commands/custom-commands.md
101+
- Command Grouping: commands/command-grouping.md
72102
- Versioning: basics/versioning.md
73-
- Commands: basics/commands.md
74103
- Testing: basics/testing.md
75104
- OpenAPI: openapi/index.md
76105
- WebSockets: websockets.md
@@ -93,7 +122,6 @@ markdown_extensions:
93122
custom_fences:
94123
- name: mermaid
95124
class: mermaid
96-
format: !!python/name:pymdownx.superfences.fence_code_format ''
97125
- pymdownx.details
98126
- pymdownx.tabbed:
99127
alternate_style: true

tests/test_application/test_application_functions.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ def run_cleanup():
126126
app = App(
127127
config=Config(),
128128
injector=EllarInjector(),
129-
routes=[],
130129
on_startup_event_handlers=[EventHandler(run_startup)],
131130
on_shutdown_event_handlers=[EventHandler(run_cleanup)],
132131
)
@@ -150,9 +149,7 @@ async def lifespan(app):
150149
yield
151150
cleanup_complete = True
152151

153-
app = App(
154-
config=Config(), injector=EllarInjector(), lifespan=lifespan, routes=[]
155-
)
152+
app = App(config=Config(), injector=EllarInjector(), lifespan=lifespan)
156153

157154
assert not startup_complete
158155
assert not cleanup_complete
@@ -217,7 +214,7 @@ def test_app_staticfiles_route(self, tmpdir):
217214
injector = EllarInjector()
218215
CoreServiceRegistration(injector, config=Config()).register_all()
219216
injector.container.register_instance(config)
220-
app = App(injector=injector, config=config, routes=[])
217+
app = App(injector=injector, config=config)
221218
client = TestClient(app)
222219

223220
response = client.get("/static/example.txt")
@@ -239,7 +236,7 @@ def test_app_staticfiles_with_different_static_path(self, tmpdir):
239236
injector = EllarInjector()
240237
CoreServiceRegistration(injector, config=Config()).register_all()
241238
injector.container.register_instance(config)
242-
app = App(injector=injector, config=config, routes=[])
239+
app = App(injector=injector, config=config)
243240
client = TestClient(app)
244241

245242
response = client.get("/static-modified/example.txt")
@@ -258,15 +255,15 @@ def test_app_install_module(self):
258255
assert module_instance is module_instance2
259256

260257
def test_has_static_files(self, tmpdir):
261-
app = App(injector=EllarInjector(), config=Config(), routes=[])
258+
app = App(injector=EllarInjector(), config=Config())
262259
assert app.has_static_files is False
263260

264261
config = Config(STATIC_DIRECTORIES=[tmpdir])
265-
app = App(injector=EllarInjector(), config=config, routes=[])
262+
app = App(injector=EllarInjector(), config=config)
266263
assert app.has_static_files
267264

268265
def test_app_enable_versioning_and_versioning_scheme(self):
269-
app = App(injector=EllarInjector(), config=Config(), routes=[])
266+
app = App(injector=EllarInjector(), config=Config())
270267
assert app.config.VERSIONING_SCHEME
271268
assert isinstance(app.config.VERSIONING_SCHEME, DefaultAPIVersioning)
272269

@@ -290,7 +287,7 @@ def test_app_initialization_completion(self):
290287
CoreServiceRegistration(injector, config=Config()).register_all()
291288
injector.container.register_instance(config)
292289

293-
app = App(config=config, injector=injector, routes=[])
290+
app = App(config=config, injector=injector)
294291
assert injector.get(Reflector)
295292
assert injector.get(Config) is config
296293
assert injector.get(Environment) is app.jinja_environment
@@ -313,7 +310,7 @@ async def catch(
313310
) # will raise an exception is service is not registered
314311
CoreServiceRegistration(injector, config=Config()).register_all()
315312
injector.container.register_instance(config)
316-
app = App(config=config, injector=injector, routes=[])
313+
app = App(config=config, injector=injector)
317314
app.add_exception_handler(CustomExceptionHandler())
318315

319316
@get("/404")
@@ -364,7 +361,7 @@ def test_app_create_static_app(self, tmpdir):
364361
file.write("<file content>")
365362

366363
config = Config(STATIC_DIRECTORIES=[tmpdir])
367-
app = App(injector=EllarInjector(), config=config, routes=[])
364+
app = App(injector=EllarInjector(), config=config)
368365
static_app = app.create_static_app()
369366
assert isinstance(static_app, StaticFiles)
370367
client = TestClient(static_app)
@@ -386,7 +383,7 @@ def test_app_reload_static_app(self, tmpdir):
386383
file.write("<file content>")
387384

388385
config = Config(STATIC_DIRECTORIES=[tmpdir])
389-
app = App(injector=EllarInjector(), config=config, routes=[])
386+
app = App(injector=EllarInjector(), config=config)
390387
static_app_old = app._static_app
391388

392389
app.reload_static_app()
@@ -399,7 +396,7 @@ def test_app_reload_static_app(self, tmpdir):
399396
assert res.text == "<file content>"
400397

401398
def test_app_template_filter(self):
402-
app = App(injector=EllarInjector(), config=Config(), routes=[])
399+
app = App(injector=EllarInjector(), config=Config())
403400

404401
@app.template_filter()
405402
def square(value):
@@ -424,7 +421,7 @@ def triple_function(value):
424421
assert result == "<html>filter square: 4, filter triple_function: 27</html>"
425422

426423
def test_app_template_global(self):
427-
app = App(injector=EllarInjector(), config=Config(), routes=[])
424+
app = App(injector=EllarInjector(), config=Config())
428425

429426
@app.template_global()
430427
def square(value):

tests/test_di/test_provider_scopes.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,33 @@ def test_invalid_use_of_provider_config():
5353
ProviderConfig(IContext, use_class=AnyContext, use_value=AnyContext())
5454

5555

56+
def test_provider_config_use_value():
57+
injector = EllarInjector(auto_bind=False)
58+
ProviderConfig(IContext, use_value=AnyContext()).register(injector.container)
59+
60+
# IContext is now registered as a singleton
61+
assert injector.get(IContext) == injector.get(IContext)
62+
63+
64+
def test_provider_config():
65+
injector = EllarInjector(auto_bind=False)
66+
ProviderConfig(AnyContext).register(injector.container)
67+
68+
assert injector.get(AnyContext) != injector.get(AnyContext) # RequestScope
69+
70+
71+
def test_invalid_use_provider_config():
72+
injector = EllarInjector(auto_bind=False)
73+
any_ctx = AnyContext()
74+
with pytest.raises(DIImproperConfiguration) as ex:
75+
ProviderConfig(any_ctx).register(injector.container)
76+
77+
assert (
78+
str(ex.value)
79+
== f"couldn't determine provider setup for {any_ctx}. Please use `ProviderConfig` or `register_services` function in a Module to configure the provider"
80+
)
81+
82+
5683
def test_has_binding_works():
5784
@inject
5885
def inject_function(a: IContext):

0 commit comments

Comments
 (0)