Skip to content

Commit fe2abd4

Browse files
committed
Improve work with deps
- reduced the number of optional libraries installed by default - moved aiohttp to extras - added an example of integrating the library into a fastapi project - updated README.md - updated Dockerfile used to run tests - updated ci/cd configs
1 parent 50663e8 commit fe2abd4

11 files changed

Lines changed: 558 additions & 289 deletions

File tree

.github/workflows/release.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
- "*"
77

88
env:
9-
POETRY_VERSION: "1.1.13"
9+
POETRY_VERSION: "1.2.2"
1010

1111
jobs:
1212
deploy:
@@ -19,11 +19,11 @@ jobs:
1919
python-version: "3.8"
2020
- name: Install poetry
2121
run: |
22-
wget https://raw.githubusercontent.com/sdispater/poetry/master/get-poetry.py
22+
wget -O get-poetry.py https://install.python-poetry.org
2323
python ./get-poetry.py --version $POETRY_VERSION
2424
echo "$HOME/.poetry/bin" >> $GITHUB_PATH
2525
- name: Install dependencies
26-
run: poetry install
26+
run: poetry install --all-extras
2727
env:
2828
POETRY_VIRTUALENVS_CREATE: false
2929
- name: Release package

.github/workflows/test.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ on:
99
- 'master'
1010

1111
env:
12-
POETRY_VERSION: "1.1.13"
13-
MIN_COVERAGE: "97"
12+
POETRY_VERSION: "1.2.2"
13+
MIN_COVERAGE: "99"
1414

1515
jobs:
1616
lint:
@@ -23,11 +23,11 @@ jobs:
2323
python-version: "3.8"
2424
- name: Install poetry
2525
run: |
26-
wget https://raw.githubusercontent.com/sdispater/poetry/master/get-poetry.py
26+
wget -O get-poetry.py https://install.python-poetry.org
2727
python ./get-poetry.py --version $POETRY_VERSION
2828
echo "$HOME/.poetry/bin" >> $GITHUB_PATH
2929
- name: Install dependencies
30-
run: poetry install
30+
run: poetry install --all-extras
3131
env:
3232
POETRY_VIRTUALENVS_CREATE: false
3333
- name: Run lint
@@ -51,11 +51,11 @@ jobs:
5151
python-version: "${{ matrix.py_version }}"
5252
- name: Install poetry
5353
run: |
54-
wget https://raw.githubusercontent.com/sdispater/poetry/master/get-poetry.py
54+
wget -O get-poetry.py https://install.python-poetry.org
5555
python ./get-poetry.py --version $POETRY_VERSION
5656
echo "$HOME/.poetry/bin" >> $GITHUB_PATH
5757
- name: Install dependencies
58-
run: poetry install
58+
run: poetry install --all-extras
5959
env:
6060
POETRY_VIRTUALENVS_CREATE: false
6161
- name: Run tests

Dockerfile

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ ARG PYTHON_VERSION
22

33
FROM python:${PYTHON_VERSION}-buster
44

5-
ENV POETRY_VERSION=1.1.13
5+
ENV POETRY_VERSION=1.2.2
66

77
WORKDIR /opt/app/
88

99
RUN apt update \
1010
&& apt-get install -y wget \
11-
&& ln -s /root/.poetry/bin/poetry /usr/bin/poetry \
12-
&& wget https://raw.githubusercontent.com/sdispater/poetry/master/get-poetry.py \
11+
&& ln -s /root/.local/bin/poetry /usr/bin/poetry \
12+
&& wget -O get-poetry.py https://install.python-poetry.org \
1313
&& python ./get-poetry.py --version $POETRY_VERSION \
1414
&& poetry config virtualenvs.create false \
1515
&& rm ./get-poetry.py \
@@ -20,7 +20,9 @@ RUN apt update \
2020
&& touch README.md
2121

2222
COPY pyproject.toml poetry.lock /opt/app/
23-
RUN /bin/bash -c 'mkdir -p src/runtime_config && touch src/runtime_config/__init__.py && poetry install --no-interaction --no-ansi'
23+
RUN /bin/bash -c "mkdir -p src/runtime_config \
24+
&& touch src/runtime_config/__init__.py \
25+
&& poetry install --all-extras --no-interaction --no-ansi"
2426

2527
COPY src/ /opt/app/src
2628
COPY tests/ /opt/app/tests

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
test:
2+
pytest --cov="runtime_config" .
3+
4+
test-multi-versions:
25
bash scripts/tests.sh
36

47
lint:

README.md

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,39 @@ Table of contents:
3030

3131
# Installation
3232

33-
This project can be installed using pip:
33+
You can install the library like this:
3434

35-
```
36-
pip install runtime-config-py
37-
```
35+
- from pypi
36+
37+
```
38+
pip install runtime-config-py[aiohttp]
39+
```
40+
41+
or
3842

39-
Or it can be installed directly from git:
43+
```
44+
poetry add runtime-config-py -E aiohttp
45+
```
46+
47+
- from git:
48+
49+
```
50+
pip install git+https://github.com/runtime-config/runtime-config-py.git#egg="runtime-config-py[aiohttp]"
51+
```
52+
53+
54+
Source dependencies have been moved to extras to give you more control over which libraries are installed. If you
55+
have a project dependency on a certain version of aiohttp you can install the library without specifying extras.
4056

4157
```
42-
pip install git+https://github.com/runtime-config/runtime-config-py.git
58+
pip install runtime-config-py
4359
```
4460

4561
# Usage
4662

47-
Let's see a simple example of using this library together with aiohttp.
63+
Examples of using the library can be found [here](./example).
64+
65+
Let's see a simple example of using this library together with aiohttp application.
4866

4967
```python
5068
from aiohttp import web
@@ -115,14 +133,27 @@ config = await RuntimeConfig.create(..., source=your_source)
115133

116134
# Development
117135

136+
## Install deps
137+
138+
```
139+
poetry install --all-extras
140+
```
141+
118142
## Tests
119143

120144
Check the work of the library on several versions of Python at once using the command below:
121145

146+
```
147+
make test-multi-versions
148+
```
149+
150+
The simple test run is available through the command below:
151+
122152
```
123153
make test
124154
```
125155

156+
126157
## Style code
127158

128159
For automatic code formatting and code verification, you need to use the command below:
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
aiohttp==3.8.1
2-
git+https://github.com/runtime-config/runtime-config-py.git
1+
git+https://github.com/runtime-config/runtime-config-py.git#egg=runtime-config-py[aiohttp]
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import uvicorn
2+
from fastapi import APIRouter, FastAPI
3+
4+
from runtime_config import RuntimeConfig
5+
from runtime_config import get_instance as get_config_inst
6+
from runtime_config.sources import ConfigServerSrc
7+
8+
router = APIRouter()
9+
10+
11+
@router.get("/")
12+
async def hello():
13+
config = get_config_inst()
14+
return f'Hello world {config.name}!'
15+
16+
17+
async def init() -> None:
18+
source = ConfigServerSrc(host='http://127.0.0.1:8080', service_name='hello_world')
19+
await RuntimeConfig.create(init_settings={'name': 'Alex'}, source=source)
20+
21+
22+
async def shutdown() -> None:
23+
await get_config_inst().close()
24+
25+
26+
app = FastAPI()
27+
app.on_event("startup")(init)
28+
app.on_event("shutdown")(shutdown)
29+
app.include_router(router)
30+
uvicorn.run(app, port=5000)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fastapi==0.85.1
2+
uvicorn==0.19.0
3+
git+https://github.com/runtime-config/runtime-config-py.git#egg=runtime-config-py[aiohttp]

0 commit comments

Comments
 (0)