Skip to content

Commit 7091d1f

Browse files
authored
Merge pull request #179 from python-ellar/refactoring
Final Overall Refactor
2 parents 4cbb4a7 + 3525020 commit 7091d1f

File tree

219 files changed

+3294
-1461
lines changed

Some content is hidden

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

219 files changed

+3294
-1461
lines changed

CODE_OF_CONDUCT.md

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
We as members, contributors, and leaders pledge to make participation in our
6+
community a harassment-free experience for everyone, regardless of age, body
7+
size, visible or invisible disability, ethnicity, sex characteristics, gender
8+
identity and expression, level of experience, education, socio-economic status,
9+
nationality, personal appearance, race, caste, color, religion, or sexual
10+
identity and orientation.
11+
12+
We pledge to act and interact in ways that contribute to an open, welcoming,
13+
diverse, inclusive, and healthy community.
14+
15+
## Our Standards
16+
17+
Examples of behavior that contributes to a positive environment for our
18+
community include:
19+
20+
- Demonstrating empathy and kindness toward other people
21+
- Being respectful of differing opinions, viewpoints, and experiences
22+
- Giving and gracefully accepting constructive feedback
23+
- Accepting responsibility and apologizing to those affected by our mistakes,
24+
and learning from the experience
25+
- Focusing on what is best not just for us as individuals, but for the overall
26+
community
27+
28+
Examples of unacceptable behavior include:
29+
30+
- The use of sexualized language or imagery, and sexual attention or advances of
31+
any kind
32+
- Trolling, insulting or derogatory comments, and personal or political attacks
33+
- Public or private harassment
34+
- Publishing others' private information, such as a physical or email address,
35+
without their explicit permission
36+
- Other conduct which could reasonably be considered inappropriate in a
37+
professional setting
38+
39+
## Enforcement Responsibilities
40+
41+
Community leaders are responsible for clarifying and enforcing our standards of
42+
acceptable behavior and will take appropriate and fair corrective action in
43+
response to any behavior that they deem inappropriate, threatening, offensive,
44+
or harmful.
45+
46+
Community leaders have the right and responsibility to remove, edit, or reject
47+
comments, commits, code, wiki edits, issues, and other contributions that are
48+
not aligned to this Code of Conduct, and will communicate reasons for moderation
49+
decisions when appropriate.
50+
51+
## Scope
52+
53+
This Code of Conduct applies within all community spaces, and also applies when
54+
an individual is officially representing the community in public spaces.
55+
Examples of representing our community include using an official e-mail address,
56+
posting via an official social media account, or acting as an appointed
57+
representative at an online or offline event.
58+
59+
## Enforcement
60+
61+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
62+
reported to the community leaders responsible for enforcement at
63+
64+
All complaints will be reviewed and investigated promptly and fairly.
65+
66+
All community leaders are obligated to respect the privacy and security of the
67+
reporter of any incident.
68+
69+
## Enforcement Guidelines
70+
71+
Community leaders will follow these Community Impact Guidelines in determining
72+
the consequences for any action they deem in violation of this Code of Conduct:
73+
74+
### 1. Correction
75+
76+
**Community Impact**: Use of inappropriate language or other behavior deemed
77+
unprofessional or unwelcome in the community.
78+
79+
**Consequence**: A private, written warning from community leaders, providing
80+
clarity around the nature of the violation and an explanation of why the
81+
behavior was inappropriate. A public apology may be requested.
82+
83+
### 2. Warning
84+
85+
**Community Impact**: A violation through a single incident or series of
86+
actions.
87+
88+
**Consequence**: A warning with consequences for continued behavior. No
89+
interaction with the people involved, including unsolicited interaction with
90+
those enforcing the Code of Conduct, for a specified period of time. This
91+
includes avoiding interactions in community spaces as well as external channels
92+
like social media. Violating these terms may lead to a temporary or permanent
93+
ban.
94+
95+
### 3. Temporary Ban
96+
97+
**Community Impact**: A serious violation of community standards, including
98+
sustained inappropriate behavior.
99+
100+
**Consequence**: A temporary ban from any sort of interaction or public
101+
communication with the community for a specified period of time. No public or
102+
private interaction with the people involved, including unsolicited interaction
103+
with those enforcing the Code of Conduct, is allowed during this period.
104+
Violating these terms may lead to a permanent ban.
105+
106+
### 4. Permanent Ban
107+
108+
**Community Impact**: Demonstrating a pattern of violation of community
109+
standards, including sustained inappropriate behavior, harassment of an
110+
individual, or aggression toward or disparagement of classes of individuals.
111+
112+
**Consequence**: A permanent ban from any sort of public interaction within the
113+
community.
114+
115+
## Attribution
116+
117+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118+
version 2.1, available at
119+
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120+
121+
Community Impact Guidelines were inspired by
122+
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123+
124+
For answers to common questions about this code of conduct, see the FAQ at
125+
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
126+
[https://www.contributor-covenant.org/translations][translations].
127+
128+
[homepage]: https://www.contributor-covenant.org
129+
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130+
[Mozilla CoC]: https://github.com/mozilla/diversity
131+
[FAQ]: https://www.contributor-covenant.org/faq
132+
[translations]: https://www.contributor-covenant.org/translations

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,11 @@ document_builder.set_title('Ellar API') \
113113

114114
document = document_builder.build_document(app)
115115
module = OpenAPIDocumentModule.setup(
116+
app=app,
116117
docs_ui=SwaggerUI(),
117118
document=document,
118119
guards=[]
119120
)
120-
app.install_module(module)
121121

122122

123123
if __name__ == "__main__":

docs/basics/application-context.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# **Application Context**
2+
3+
In the complex web of dependencies within Ellar,
4+
accessing the application instance without triggering circular import errors can be a daunting task.
5+
6+
To address this challenge, Ellar introduces the concept of an application context,
7+
a powerful mechanism that facilitates smooth access to the application instance throughout various parts of the codebase.
8+
9+
## **Understanding the Application Context**
10+
11+
The application context serves as a bridge between different components of the application, making the application object
12+
readily available through the application Dependency Injection (DI) container. This ensures that you can access the
13+
application instance without encountering import issues, whether it's during request handling, execution of CLI commands,
14+
or manual invocation of the context.
15+
16+
Two key elements of the application context are:
17+
18+
- **current_injector**: This proxy variable refers to the current application **injector**, providing access to any service or the application instance itself.
19+
- **config**: A lazy loader for application configuration, which is based on the `ELLAR_CONFIG_MODULE` reference or accessed through `application.config` when the application context is active.
20+
21+
## **Integration with Click Commands**
22+
23+
By decorating Click commands with `click.with_app_context`, you can effortlessly incorporate the application context
24+
into their CLI workflows. This allows them to leverage the full power of the application context when executing commands.
25+
26+
For instance, consider the following example:
27+
28+
```python
29+
import ellar_cli.click as click
30+
from ellar.app import current_injector
31+
from ellar.di import injectable
32+
33+
@injectable
34+
class MyService:
35+
def do_something(self) -> None:
36+
pass
37+
38+
@click.command()
39+
@click.argument('name')
40+
@click.with_app_context
41+
def my_command(name: str):
42+
my_service = current_injector.get(MyService)
43+
my_service.do_something()
44+
```
45+
46+
Here, the `click.with_app_context` decorator ensures that the application context is available within the `my_command` function,
47+
allowing seamless access to application resources.
48+
49+
## **Lifecycle of the Application Context**
50+
51+
The application context operates as an asynchronous context manager, automatically created at
52+
the beginning of request handling and gracefully torn down upon completion of the request.
53+
54+
## **Handling Application Context Events**
55+
56+
Additionally, the application context offers event hooks that you can leverage to perform custom actions at
57+
specific points in the context's lifecycle.
58+
59+
Two such events are `app_context_started` and `app_context_teardown`,
60+
which are triggered at the beginning and end of the context, respectively.
61+
62+
For example, consider the following event handling setup:
63+
64+
```python
65+
from ellar.events import app_context_teardown, app_context_started
66+
from ellar.app import App, AppFactory, current_injector
67+
from ellar.threading import run_as_async
68+
69+
@app_context_started.connect
70+
async def on_context_started():
71+
print('=======> Context Started <=======')
72+
73+
@app_context_teardown.connect
74+
def on_context_ended():
75+
print('=======> Context ended <=========')
76+
77+
app = AppFactory.create_app()
78+
79+
@run_as_async
80+
async def run_app_context():
81+
async with app.application_context() as ctx:
82+
print("-----> Context is now available <------")
83+
84+
app_instance = ctx.injector.get(App)
85+
app_instance_2 = current_injector.get(App)
86+
87+
assert app_instance == app == app_instance_2
88+
print("-----> Context is now destroyed <------")
89+
90+
if __name__ == '__main__':
91+
run_app_context()
92+
```
93+
94+
In this example, event handlers are registered to execute custom logic when the application context starts and ends.
95+
This allows you to perform initialization or cleanup tasks as needed.

examples/02-socketio-app/socketio_app/apps/events/tests/test_controllers.py renamed to docs/basics/storage.md

File renamed without changes.

docs/cli/custom-commands.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ ARGUMENTS:
4141
## **With App Context Decorator**
4242
The `ellar_cli.click` module includes a command decorator function called `with_app_context`.
4343
This decorator ensures that a click command is executed within the application context,
44-
allowing `current_app`, `current_injector`, and `current_config` to have values.
44+
allowing `current_injector`, and `config` to have values.
4545

4646
For instance:
4747

docs/contribution.md

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,81 @@
1-
# Coming Soon
1+
# **Contribution Guidelines**
2+
3+
Thank you for considering contributing to Ellar! Your contributions help make the project better for everyone.
4+
Please take a moment to review the following guidelines before getting started.
5+
6+
## Setting up the Development Environment
7+
8+
1. **Fork the repository:** Fork the Ellar repository on GitHub and clone it locally.
9+
10+
2. **Virtual Environment:** Create and activate a virtual environment for the project.
11+
12+
```bash
13+
python -m venv venv
14+
source venv/bin/activate # Linux/macOS
15+
```
16+
17+
```bash
18+
python -m venv venv
19+
.\venv\Scripts\activate # Windows
20+
```
21+
22+
3. **Install `flit`:** Ensure you have `flit` installed globally.
23+
24+
```bash
25+
pip install flit
26+
```
27+
28+
4. **Install Dependencies:** Install development libraries and pre-commit hooks.
29+
30+
```bash
31+
make install
32+
```
33+
34+
### **Code Style and Formatting**
35+
36+
- **Formatting:** To format your code and ensure consistency, run:
37+
38+
```bash
39+
make fmt
40+
```
41+
42+
- **Linting:** Ellar uses `mypy` and `ruff` for linting. Run the following command to check code linting:
43+
44+
```bash
45+
make lint
46+
```
47+
48+
### **Testing**
49+
50+
- **Unit Tests:** We use `pytest` for unit testing. Run the test suite:
51+
52+
```bash
53+
make test
54+
```
55+
56+
- **Test Coverage:** To check test coverage:
57+
58+
```bash
59+
make test-cov
60+
```
61+
62+
### **Submitting a Pull Request**
63+
64+
1. **Branch:** Create a new branch for your feature or bug fix.
65+
66+
```bash
67+
git checkout -b feature-branch
68+
```
69+
70+
2. **Commit Messages:** Follow the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) specification for your commit messages.
71+
72+
3. **Push Changes:** Push your branch to your forked repository.
73+
74+
```bash
75+
git push origin feature-branch
76+
```
77+
78+
4. **Pull Request:** Open a pull request against the `master` branch of the Ellar repository. Provide a clear and descriptive title and description for your changes.
79+
80+
81+
Thank you for contributing to Ellar! 🚀

docs/img/api_tags.png

141 KB
Loading

docs/img/guard_basic_openapi.png

132 KB
Loading

docs/img/guard_bearer_openapi.png

119 KB
Loading

docs/img/guard_cookie_openapi.png

169 KB
Loading

0 commit comments

Comments
 (0)