Skip to content

Commit

Permalink
add uvloop optional dependency (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
aminalaee authored Aug 2, 2021
1 parent 094301b commit 1127878
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
with:
python-version: 3.7
- name: "Install dependencies"
run: "pip install -r dev-requirements.txt"
run: "pip install -r requirements/dev-requirements.txt"
- name: "Publish to PyPI"
run: "./scripts/release.sh"
env:
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r dev-requirements.txt
pip install -r tests/test-requirements.txt
pip install -r requirements/requirements.txt
pip install -r requirements/dev-requirements.txt
pip install -r requirements/test-requirements.txt
- name: Lint
run: ./scripts/lint.sh

Expand Down Expand Up @@ -62,8 +62,8 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r tests/test-requirements.txt
pip install -r requirements/requirements.txt
pip install -r requirements/test-requirements.txt
- name: Setup postgres
run: |
export PGPASSWORD=postgres
Expand Down Expand Up @@ -97,8 +97,8 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r tests/test-requirements.txt
pip install -r requirements/requirements.txt
pip install -r requirements/test-requirements.txt
- name: Test with pytest, SQLite
run: ./scripts/test-sqlite.sh
- name: Upload coverage
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ _build/
*.sqlite
htmlcov/
prof/
.env/
.venv/
8 changes: 6 additions & 2 deletions docs/src/piccolo/getting_started/installing_piccolo.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ Now install piccolo, ideally inside a `virtualenv <https://docs.python-guide.org
# The important bit:
pip install piccolo
# For optional orjson support, which improves JSON serialisation
# performance:
# Optional: orjson for improved JSON serialisation performance
pip install piccolo[orjson]
# Optional: uvloop as default event loop instead of asyncio
# If using Piccolo with Uvicorn, Uvicorn will set uvloop as
# default event loop if installed
pip install piccolo[uvloop]
7 changes: 7 additions & 0 deletions piccolo/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@

from targ import CLI # type: ignore

try:
import uvloop # type: ignore

uvloop.install()
except ImportError:
pass

from piccolo.apps.app.piccolo_app import APP_CONFIG as app_config
from piccolo.apps.asgi.piccolo_app import APP_CONFIG as asgi_config
from piccolo.apps.meta.piccolo_app import APP_CONFIG as meta_config
Expand Down
6 changes: 6 additions & 0 deletions requirements/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Requirement files

* `extras` - Optional dependencies of `Piccolo`.
* `dev-requirements.txt` - Requirements needed to develop `Piccolo`.
* `requirements.txt` - Default requirements of `Piccolo`.
* `test-requirements.txt` - Requirements needed to run `Piccolo` tests.
File renamed without changes.
1 change: 1 addition & 0 deletions requirements/extras/orjson.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
orjson==3.4.1
1 change: 1 addition & 0 deletions requirements/extras/playground.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ipython
1 change: 1 addition & 0 deletions requirements/extras/uvloop.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uvloop>=0.12.0
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
coveralls==2.2.0
flake8==3.8.4
mypy==0.790
pytest-cov==2.10.1
pytest==6.2.1
python-dateutil==2.8.1
37 changes: 31 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,48 @@
# -*- coding: utf-8 -*-

import os
from typing import List
from setuptools import find_packages, setup

from piccolo import __VERSION__ as VERSION


directory = os.path.abspath(os.path.dirname(__file__))


with open(os.path.join(directory, "requirements.txt")) as f:
contents = f.read()
REQUIREMENTS = [i.strip() for i in contents.strip().split("\n")]
extras = ["orjson", "playground", "uvloop"]


with open(os.path.join(directory, "README.md")) as f:
LONG_DESCRIPTION = f.read()


def parse_requirement(req_path: str) -> List[str]:
"""
Parse requirement file.
Example:
parse_requirement('requirements.txt') # requirements/requirements.txt
parse_requirement('extras/playground.txt') # requirements/extras/playground.txt
Returns:
List[str]: list of requirements specified in the file.
"""
with open(os.path.join(directory, "requirements", req_path)) as f:
contents = f.read()
return [i.strip() for i in contents.strip().split("\n")]


def extras_require():
"""
Parse requirements in requirements/extras directory
"""
extra_requirements = {}
for extra in extras:
extra_requirements[extra] = parse_requirement(
os.path.join("extras", extra + ".txt")
)

return extra_requirements


setup(
name="piccolo",
version=VERSION,
Expand All @@ -41,8 +66,8 @@
],
"piccolo": ["py.typed"],
},
install_requires=REQUIREMENTS,
extras_require={"orjson": ["orjson==3.4.1"], "playground": ["ipython"]},
install_requires=parse_requirement("requirements.txt"),
extras_require=extras_require(),
license="MIT",
classifiers=[
"License :: OSI Approved :: MIT License",
Expand Down

0 comments on commit 1127878

Please sign in to comment.