Skip to content

Commit 3226a1b

Browse files
committed
Update contributing guide
1 parent 94f2f00 commit 3226a1b

File tree

1 file changed

+115
-0
lines changed

1 file changed

+115
-0
lines changed

docs/contributing.md

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,118 @@ Any and all contributions and involvement with the project is welcome. The easie
55
## Documentation
66

77
The documentation is built using [mkdocs](https://www.mkdocs.org/). All documentation is in markdown format, and can be found in `./docs/`
8+
9+
10+
## Contributing Code
11+
12+
### Step 1: prerequisites
13+
14+
`fastapi-pagination` uses [poetry](https://python-poetry.org/) for dependency management.
15+
Please, install poetry before continuing.
16+
17+
Minimum supported python version is `3.8`.
18+
19+
20+
### Step 2: clone the repo
21+
22+
```shell
23+
git clone https://github.com/uriyyo/fastapi-pagination
24+
```
25+
26+
27+
### Step 3: install dependencies
28+
29+
To install all dependencies, run:
30+
```sh
31+
poetry install -E all
32+
```
33+
34+
To install only basic dependencies, run:
35+
```sh
36+
poetry install
37+
```
38+
39+
To install docs requirements, run:
40+
```sh
41+
poetry run pip install -r docs_requirements.txt
42+
```
43+
44+
### Step 4: do your changes
45+
46+
If you want to add new feature, please, create an issue first and describe your idea.
47+
48+
If you want to add new extension for pagination you will need to create a new module in `fastapi_pagination/ext/` directory.
49+
Please, use `fastapi_pagination/ext/sqlalchemy.py` as an example.
50+
Generally, you will need to call function `paginate` and signature should include next arguments:
51+
```py
52+
from typing import Any, Optional
53+
54+
from fastapi_pagination.api import apply_items_transformer, create_page
55+
from fastapi_pagination.bases import AbstractParams
56+
from fastapi_pagination.types import AdditionalData, AsyncItemsTransformer
57+
from fastapi_pagination.utils import verify_params
58+
59+
60+
async def paginate(
61+
query: QuerySet,
62+
params: Optional[AbstractParams] = None, # Optional params for pagination (if None, current params will be used)
63+
*,
64+
transformer: Optional[AsyncItemsTransformer] = None, # Optional transformer for items
65+
additional_data: Optional[AdditionalData] = None, # Optional additional data for page object
66+
) -> Any:
67+
params, raw_params = verify_params(params, "limit-offset") # verify params is of correct type
68+
69+
total = await query.count() # get total count of items
70+
items = await query.limit(raw_params.limit).offset(raw_params.offset).all() # get items for current page
71+
t_items = await apply_items_transformer(items, transformer, async_=True) # apply transformer if needed
72+
73+
return create_page( # create page object
74+
t_items,
75+
total=total,
76+
params=params,
77+
**(additional_data or {}),
78+
)
79+
```
80+
81+
If you want to add/updated docs, then you will need to edit `./docs/` directory.
82+
You can run `mkdocs serve` to see your changes locally.
83+
84+
### Step 5: run pre-commit hooks
85+
86+
Before creating a commit, please, run pre-commit hooks:
87+
```sh
88+
poetry run pre-commit run --all-files
89+
```
90+
91+
You can also install pre-commit hooks to run automatically before each commit:
92+
```sh
93+
poetry run pre-commit install
94+
```
95+
96+
### Step 6: run tests
97+
98+
To run tests, run:
99+
```sh
100+
poetry run pytest tests
101+
```
102+
103+
If you want to run tests with coverage, run:
104+
```sh
105+
poetry run pytest tests --cov=fastapi_pagination
106+
```
107+
108+
If you want to run only unit tests, run:
109+
```sh
110+
poetry run pytest tests --unit-tests
111+
```
112+
113+
If you want to run only integration tests, then you will also will need to have `PostgreSQL`, `MongoDB` and `Casandra` running.
114+
115+
To run integration tests, run:
116+
```sh
117+
poetry run pytest tests/ext
118+
```
119+
120+
### Step 7: create a pull request
121+
122+
After you have done all changes, please, create a pull request.

0 commit comments

Comments
 (0)