Skip to content

Commit

Permalink
link and add pre-commit hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
auredentan committed Aug 29, 2020
1 parent 5be8b01 commit 5fdfaa1
Show file tree
Hide file tree
Showing 7 changed files with 182 additions and 10 deletions.
25 changes: 25 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

repos:
- repo: local
hooks:
- id: format
name: format
entry: make format
pass_filenames: false
language: system
- id: check
name: check
entry: make check
pass_filenames: false
language: system


- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.1.0 # Use the ref you want to point at
stages:
- commit
- push
hooks:
- id: check-added-large-files
- id: detect-private-key
- id: check-merge-conflict
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ setup: ## Setup the development environment (install dependencies).
fi; \
fi; \
poetry install -v
pre-commit install

.PHONY: format
format: ## Run formatting tools on the code.
Expand All @@ -107,7 +108,7 @@ ifndef v
endif
@poetry run failprint -t "Bumping version" -- poetry version $(v)
@poetry run failprint -t "Staging files" -- git add pyproject.toml CHANGELOG.md
@poetry run failprint -t "Committing changes" -- git commit -m "chore: :package: Prepare release $(v) :package:"
@poetry run failprint -t "Committing changes" -- git commit -m ":package: Prepare release $(v) :package:"
@poetry run failprint -t "Tagging commit" -- git tag v$(v)
@poetry run failprint -t "Building dist/wheel" -- poetry build
-@if ! $(CI) && ! $(TESTING); then \
Expand Down
146 changes: 144 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ classifiers = [


[tool.poetry.dependencies]
python = "^3.6"
python = "^3.6.1"
starlette = "^0.13.8"
itsdangerous = "^1.1.0"
redis = {version = "^3.5.3", optional = true}
Expand All @@ -40,6 +40,7 @@ pytest-asyncio = "^0.14.0"
pymemcache = "^3.3.0"
mypy = "^0.782"
flake8 = "^3.8.3"
pre-commit = "^2.7.1"

[tool.black]
line-length = 88
Expand Down
10 changes: 7 additions & 3 deletions starlette_session/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import itsdangerous
from itsdangerous.exc import BadTimeSignature, SignatureExpired

from starlette.datastructures import MutableHeaders
from starlette.requests import HTTPConnection
from starlette.types import ASGIApp, Message, Receive, Scope, Send
Expand Down Expand Up @@ -107,7 +106,10 @@ async def send_wrapper(message: Message, **kwargs) -> None:

if scope["session"]:

if self.backend_type == BackendType.cookie or not self.session_backend:
if (
self.backend_type == BackendType.cookie
or not self.session_backend
):
cookie_data = scope["session"]
else:
await self.session_backend.set(
Expand Down Expand Up @@ -135,7 +137,9 @@ async def send_wrapper(message: Message, **kwargs) -> None:

await self.app(scope, receive, send_wrapper)

def _get_predefined_session_backend(self, backend_db_client) -> Optional[ISessionBackend]:
def _get_predefined_session_backend(
self, backend_db_client
) -> Optional[ISessionBackend]:
if self.backend_type == BackendType.redis:
return RedisSessionBackend(backend_db_client)
elif self.backend_type == BackendType.cookie:
Expand Down
2 changes: 1 addition & 1 deletion starlette_session/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ async def delete(self, key: str) -> Any:
return self.redis.delete(key)


class AioRedisSessionBackend(ISessionBackend):
class AioRedisSessionBackend(ISessionBackend):
def __init__(self, redis: AioRedis): # pragma: no cover
self.redis = redis

Expand Down
3 changes: 1 addition & 2 deletions tests/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import fakeredis
import pytest

from pymemcache.test.utils import MockMemcacheClient

from starlette.applications import Starlette
from starlette.requests import Request
from starlette.responses import JSONResponse
Expand Down Expand Up @@ -47,6 +45,7 @@ def redis() -> fakeredis.FakeStrictRedis:
def memcache():
return MockMemcacheClient()


def test_MemcacheJSONSerde():
serde = MemcacheJSONSerde()

Expand Down

0 comments on commit 5fdfaa1

Please sign in to comment.