Skip to content
This repository was archived by the owner on Aug 19, 2025. It is now read-only.

Commit 0598d92

Browse files
collerekPrettyWood
andauthored
Add contributing docs (#453)
* add support for local tests in docker * update docs * move win support to separate PR * remove docker file, update contributing docs * clean scripts * Update docs/contributing.md Co-authored-by: Eric Jolibois <[email protected]> * Update docs/contributing.md Co-authored-by: Eric Jolibois <[email protected]> * remove python version from venv, clarify that docs serve the live docs Co-authored-by: Eric Jolibois <[email protected]>
1 parent c8171e2 commit 0598d92

File tree

5 files changed

+125
-6
lines changed

5 files changed

+125
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.vscode/
2+
.idea/
23
*.pyc
34
test.db
45
.coverage

docs/contributing.md

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# Contibuting
2+
3+
All contributions to *databases* are welcome!
4+
5+
## Issues
6+
7+
To make it as simple as possible for us to help you, please include the following:
8+
9+
* OS
10+
* python version
11+
* databases version
12+
* database backend (mysql, sqlite or postgresql)
13+
* database driver (aiopg, aiomysql etc.)
14+
15+
Please try to always include the above unless you're unable to install *databases* or **know** it's not relevant
16+
to your question or feature request.
17+
18+
## Pull Requests
19+
20+
It should be quite straight forward to get started and create a Pull Request.
21+
22+
!!! note
23+
Unless your change is trivial (typo, docs tweak etc.), please create an issue to discuss the change before
24+
creating a pull request.
25+
26+
To make contributing as easy and fast as possible, you'll want to run tests and linting locally.
27+
28+
You'll need to have **python >= 3.6 (recommended 3.7+)** and **git** installed.
29+
30+
## Getting started
31+
32+
1. Clone your fork and cd into the repo directory
33+
```bash
34+
git clone [email protected]:<your username>/databases.git
35+
cd databases
36+
```
37+
38+
2. Create and activate virtual env
39+
```bash
40+
virtualenv env
41+
source env/bin/activate
42+
```
43+
44+
3. Install databases, dependencies and test dependencies
45+
```bash
46+
pip install -r requirements.txt
47+
```
48+
49+
4. Checkout a new branch and make your changes
50+
```bash
51+
git checkout -b my-new-feature-branch
52+
```
53+
54+
## Make your changes...
55+
56+
## Contribute
57+
58+
1. Formatting and linting - databases uses black for formatting, autoflake for linting and mypy for type hints check
59+
run all of those with lint script
60+
```bash
61+
./scripts/lint
62+
```
63+
64+
2. Prepare tests (basic)
65+
1. Set-up `TEST_DATABASE_URLS` env variable where you can comma separate urls for several backends
66+
2. The simples one is for sqlite alone: `sqlite:///test.db`
67+
68+
3. Prepare tests (all backends)
69+
1. In order to run all backends you need either a docker installation on your system or all supported backends servers installed on your local machine.
70+
2. A sample docker configuration that reflects the CI/CD workflow of databases might be:
71+
72+
```dockerfile
73+
version: '2.1'
74+
services:
75+
postgres:
76+
image: postgres:10.8
77+
environment:
78+
POSTGRES_USER: username
79+
POSTGRES_PASSWORD: password
80+
POSTGRES_DB: testsuite
81+
ports:
82+
- 5432:5432
83+
84+
mysql:
85+
image: mysql:5.7
86+
environment:
87+
MYSQL_USER: username
88+
MYSQL_PASSWORD: password
89+
MYSQL_ROOT_PASSWORD: password
90+
MYSQL_DATABASE: testsuite
91+
ports:
92+
- 3306:3306
93+
```
94+
3. To test all backends, the test urls need to consist of all possible drivers too, so a sample might look like following:
95+
```text
96+
sqlite:///test.db,
97+
sqlite+aiosqlite:///test.db,
98+
mysql+aiomysql://username:password@localhost:3306/testsuite,
99+
mysql+asyncmy://username:password@localhost:3306/testsuite,
100+
postgresql+aiopg://username:[email protected]:5432/testsuite,
101+
postgresql+asyncpg://username:password@localhost:5432/testsuite
102+
```
103+
104+
4. Run tests
105+
```bash
106+
./scripts/test
107+
```
108+
109+
5. Build documentation
110+
1. If you have changed the documentation make sure it runs successfully.
111+
You can preview the live documentation by running the following command:
112+
```bash
113+
./scripts/docs
114+
```
115+
116+
6. Commit, push, and create your pull request

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ nav:
1313
- Database Queries: 'database_queries.md'
1414
- Connections & Transactions: 'connections_and_transactions.md'
1515
- Tests & Migrations: 'tests_and_migrations.md'
16+
- Contributing: 'contributing.md'
1617

1718
markdown_extensions:
1819
- mkautodoc

scripts/test

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,20 @@ if [ -d 'venv' ] ; then
55
export PREFIX="venv/bin/"
66
fi
77

8-
if [ -z "$TEST_DATABASE_URLS" ] ; then
9-
echo "Variable TEST_DATABASE_URLS must be set."
10-
exit 1
8+
if [ -z "$TEST_DATABASE_URLS" ]; then
9+
echo "Variable TEST_DATABASE_URLS must be set."
10+
exit 1
1111
fi
1212

1313
set -ex
1414

1515
if [ -z $GITHUB_ACTIONS ]; then
16-
scripts/check
16+
scripts/check
1717
fi
1818

1919
${PREFIX}coverage run -m pytest $@
2020

2121
if [ -z $GITHUB_ACTIONS ]; then
22-
scripts/coverage
22+
scripts/coverage
2323
fi
24+

tests/test_databases.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def mysql_versions(wrapped_func):
2323
"""
2424

2525
@functools.wraps(wrapped_func)
26-
def check(*args, **kwargs):
26+
def check(*args, **kwargs): # pragma: no cover
2727
url = DatabaseURL(kwargs["database_url"])
2828
if url.scheme in ["mysql", "mysql+aiomysql"] and sys.version_info >= (3, 10):
2929
pytest.skip("aiomysql supports python 3.9 and lower")

0 commit comments

Comments
 (0)