-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from cr0hn/feature/setup-gitlab-pipeline-and-p…
…oetry Feature/setup gitlab pipeline and poetry
- Loading branch information
Showing
39 changed files
with
923 additions
and
1,213 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[flake8] | ||
application-import-names = platform_mcs | ||
import-order-style = smarkets | ||
inline-quotes = double | ||
max-complexity = 15 | ||
multiline-quotes = double | ||
ignore=I101, P101 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -128,4 +128,5 @@ ENV/ | |
.spyderproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
.ropeproject | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
image: tmaier/docker-compose:18.09 | ||
services: | ||
- docker:18.09-dind | ||
|
||
before_script: | ||
- docker version | ||
- docker-compose version | ||
|
||
after_script: | ||
- docker images | ||
|
||
stages: | ||
- lint | ||
- test | ||
- deploy | ||
|
||
lint: | ||
stage: lint | ||
image: python:3.7 | ||
before_script: | ||
- pip install pre-commit | ||
script: | ||
- pre-commit run -av | ||
|
||
test: | ||
stage: test | ||
script: | ||
- docker-compose run tests | ||
|
||
deploy:pypi: | ||
stage: deploy | ||
image: python:3.7 | ||
before_script: | ||
- pip install poetry | ||
script: | ||
- poetry publish -u $PYPI_U -p $PYPI_P --build | ||
only: | ||
- master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
exclude: > | ||
(?x)^( | ||
tests/data/.*| | ||
.*\.svg | ||
)$ | ||
minimum_pre_commit_version: 1.13.0 | ||
repos: | ||
- repo: https://github.com/ambv/black | ||
rev: 19.10b0 | ||
hooks: | ||
- id: black | ||
args: [--line-length=79] | ||
exclude: ^tests/.*$ | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v2.4.0 | ||
hooks: | ||
- id: end-of-file-fixer | ||
- id: trailing-whitespace | ||
- repo: https://gitlab.com/pycqa/flake8 | ||
rev: 3.7.9 | ||
hooks: | ||
- id: flake8 | ||
name: Lint code (flake8) | ||
additional_dependencies: | ||
- flake8==3.7.9 | ||
- flake8-broken-line==0.1.1 | ||
- flake8-bugbear==19.8.0 | ||
- flake8-builtins==1.4.1 | ||
- flake8-comprehensions==3.0.1 | ||
- flake8-import-order==0.18.1 | ||
- flake8-mutable==1.2.0 | ||
- flake8-quotes==2.1.0 | ||
- flake8-string-format==0.2.3 | ||
- flake8-tidy-imports==3.0.0 | ||
- pep8-naming==0.8.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,4 @@ Improvements and fixes | |
New features | ||
------------ | ||
|
||
- First Version | ||
- First Version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
FROM python:3.7 as base | ||
|
||
FROM base as install-deps | ||
WORKDIR /aiohttp-cache | ||
|
||
COPY ./requirements.txt . | ||
COPY ./requirements-test.txt . | ||
FROM base as install-poetry | ||
RUN pip install poetry | ||
|
||
RUN pip install -r requirements.txt | ||
RUN pip install -r requirements-test.txt | ||
FROM install-poetry as install-deps | ||
WORKDIR /aiohttp-cache | ||
COPY ./pyproject.toml . | ||
COPY ./poetry.lock . | ||
RUN poetry install | ||
|
||
FROM install-deps as copy-src | ||
COPY . . | ||
|
||
ENTRYPOINT ["poetry", "run"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
# Aiohttp-cache | ||
title: 'aiohttp-cache' | ||
--- | ||
|
||
![aiohttp-cache logo](https://raw.githubusercontent.com/cr0hn/aiohttp-cache/master/doc/source/_static/aiohttp-cache-128x128.png) | ||
|
||
|
||
# What's aiohttp-cache | ||
|
||
`aiohttp-cache` is a plugin for aiohttp.web server that allow to use a | ||
cache system to improve the performance of your site. | ||
|
||
# How to use it | ||
|
||
## With in-memory backend | ||
|
||
```python | ||
import asyncio | ||
|
||
from aiohttp import web | ||
|
||
from aiohttp_cache import ( # noqa | ||
setup_cache, | ||
cache, | ||
) | ||
|
||
PAYLOAD = {"hello": "aiohttp_cache"} | ||
WAIT_TIME = 2 | ||
|
||
|
||
@cache() | ||
async def some_long_running_view(request: web.Request) -> web.Response: | ||
await asyncio.sleep(WAIT_TIME) | ||
payload = await request.json() | ||
return web.json_response(payload) | ||
|
||
|
||
app = web.Application() | ||
setup_cache(app) | ||
app.router.add_post("/", some_long_running_view) | ||
|
||
web.run_app(app) | ||
``` | ||
|
||
## With redis backend | ||
|
||
**Note**: redis should be available at | ||
`$CACHE_URL` env variable or`redis://localhost:6379/0` | ||
|
||
```python | ||
import asyncio | ||
|
||
import yarl | ||
from aiohttp import web | ||
from envparse import env | ||
|
||
from aiohttp_cache import ( # noqa | ||
setup_cache, | ||
cache, | ||
RedisConfig, | ||
) | ||
|
||
PAYLOAD = {"hello": "aiohttp_cache"} | ||
WAIT_TIME = 2 | ||
|
||
|
||
@cache() | ||
async def some_long_running_view(request: web.Request) -> web.Response: | ||
await asyncio.sleep(WAIT_TIME) | ||
payload = await request.json() | ||
return web.json_response(payload) | ||
|
||
|
||
app = web.Application() | ||
url = yarl.URL(env.str("CACHE_URL", default="redis://localhost:6379/0")) | ||
setup_cache( | ||
app, | ||
cache_type="redis", | ||
backend_config=RedisConfig( | ||
db=int(url.path[1:]), host=url.host, port=url.port | ||
), | ||
) | ||
|
||
app.router.add_post("/", some_long_running_view) | ||
|
||
web.run_app(app) | ||
``` | ||
|
||
## Example with a custom cache key | ||
|
||
Let's say you would like to cache the requests just by the method and | ||
json payload, then you can setup this as per the follwing example. | ||
|
||
**Note** default key_pattern is: | ||
|
||
```python | ||
DEFAULT_KEY_PATTERN = ( | ||
AvailableKeys.method, | ||
AvailableKeys.host, | ||
AvailableKeys.path, | ||
AvailableKeys.postdata, | ||
AvailableKeys.ctype, | ||
) | ||
``` | ||
|
||
```python | ||
import asyncio | ||
|
||
from aiohttp import web | ||
|
||
from aiohttp_cache import setup_cache, cache, AvailableKeys # noqa | ||
|
||
PAYLOAD = {"hello": "aiohttp_cache"} | ||
WAIT_TIME = 2 | ||
|
||
|
||
@cache() | ||
async def some_long_running_view(request: web.Request) -> web.Response: | ||
await asyncio.sleep(WAIT_TIME) | ||
payload = await request.json() | ||
return web.json_response(payload) | ||
|
||
|
||
custom_cache_key = (AvailableKeys.method, AvailableKeys.json) | ||
|
||
app = web.Application() | ||
setup_cache(app, key_pattern=custom_cache_key) | ||
app.router.add_post("/", some_long_running_view) | ||
|
||
web.run_app(app) | ||
``` | ||
|
||
# License | ||
|
||
This project is released under BSD license. Feel free | ||
|
||
# Source Code | ||
|
||
The latest developer version is available in a github repository: | ||
<https://github.com/cr0hn/aiohttp-cache> | ||
|
||
# Development environment | ||
|
||
1. docker-compose run tests |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,15 @@ | ||
from .setup import * | ||
from .backends import * | ||
from .decorators import * | ||
from .middleware import * | ||
from .exceptions import * | ||
from .backends import AvailableKeys, MemoryCache, RedisCache, RedisConfig | ||
from .decorators import cache | ||
from .middleware import cache_middleware | ||
from .setup import setup_cache | ||
|
||
__version__ = "1.0.3" | ||
|
||
__all__ = ( | ||
"AvailableKeys", | ||
"MemoryCache", | ||
"RedisCache", | ||
"RedisConfig", | ||
"cache", | ||
"cache_middleware", | ||
"setup_cache", | ||
) |
Oops, something went wrong.