From d8cdf6c14051eece3469408e2f5ef9ccdfb43729 Mon Sep 17 00:00:00 2001 From: Andrey Golovizin Date: Sat, 8 Feb 2020 14:09:28 +0100 Subject: [PATCH] Add runserver-uvicorn command --- default.nix | 2 + requirements.nix | 108 ++++++++++++++++++ requirements.txt | 3 + requirements_frozen.txt | 6 + .../management/commands/runserver-uvicorn.py | 22 ++++ src/strojnadzor/settings.py | 4 +- 6 files changed, 144 insertions(+), 1 deletion(-) create mode 100644 src/strojnadzor/management/commands/runserver-uvicorn.py diff --git a/default.nix b/default.nix index d301a64..1d8c579 100644 --- a/default.nix +++ b/default.nix @@ -30,5 +30,7 @@ python.mkDerivation { djangocms-video easy-thumbnails setuptools + uvicorn + uvloop ]; } diff --git a/requirements.nix b/requirements.nix index 35a8fa0..98bb787 100644 --- a/requirements.nix +++ b/requirements.nix @@ -179,6 +179,23 @@ let }; }; + "click" = python.mkDerivation { + name = "click-7.0"; + src = pkgs.fetchurl { + url = "https://files.pythonhosted.org/packages/f8/5c/f60e9d8a1e77005f664b76ff8aeaee5bc05d0a91798afd7f53fc998dbc47/Click-7.0.tar.gz"; + sha256 = "5b94b49521f6456670fdb30cd82a4eca9412788a93fa6dd6df72c94d5a8ff2d7"; +}; + doCheck = commonDoCheck; + format = "setuptools"; + buildInputs = commonBuildInputs ++ [ ]; + propagatedBuildInputs = [ ]; + meta = with pkgs.stdenv.lib; { + homepage = "https://palletsprojects.com/p/click/"; + license = licenses.bsdOriginal; + description = "Composable command line interface toolkit"; + }; + }; + "cssselect" = python.mkDerivation { name = "cssselect-1.1.0"; src = pkgs.fetchurl { @@ -837,6 +854,23 @@ let }; }; + "h11" = python.mkDerivation { + name = "h11-0.9.0"; + src = pkgs.fetchurl { + url = "https://files.pythonhosted.org/packages/34/5a/abaa557d20b210117d8c3e6b0b817ce9b329b2e81f87612e60102a924323/h11-0.9.0.tar.gz"; + sha256 = "33d4bca7be0fa039f4e84d50ab00531047e53d6ee8ffbc83501ea602c169cae1"; +}; + doCheck = commonDoCheck; + format = "setuptools"; + buildInputs = commonBuildInputs ++ [ ]; + propagatedBuildInputs = [ ]; + meta = with pkgs.stdenv.lib; { + homepage = "https://github.com/python-hyper/h11"; + license = licenses.mit; + description = "A pure-Python, bring-your-own-I/O implementation of HTTP/1.1"; + }; + }; + "html5lib" = python.mkDerivation { name = "html5lib-1.0.1"; src = pkgs.fetchurl { @@ -857,6 +891,23 @@ let }; }; + "httptools" = python.mkDerivation { + name = "httptools-0.0.13"; + src = pkgs.fetchurl { + url = "https://files.pythonhosted.org/packages/1b/03/215969db11abe8741e9c266a4cbe803a372bd86dd35fa0084c4df6d4bd00/httptools-0.0.13.tar.gz"; + sha256 = "e00cbd7ba01ff748e494248183abc6e153f49181169d8a3d41bb49132ca01dfc"; +}; + doCheck = commonDoCheck; + format = "setuptools"; + buildInputs = commonBuildInputs ++ [ ]; + propagatedBuildInputs = [ ]; + meta = with pkgs.stdenv.lib; { + homepage = "https://github.com/MagicStack/httptools"; + license = licenses.mit; + description = "A collection of framework independent HTTP protocol utils."; + }; + }; + "idna" = python.mkDerivation { name = "idna-2.8"; src = pkgs.fetchurl { @@ -1112,6 +1163,46 @@ let }; }; + "uvicorn" = python.mkDerivation { + name = "uvicorn-0.11.2"; + src = pkgs.fetchurl { + url = "https://files.pythonhosted.org/packages/5c/ed/37f168f52814d09feaf0b4f6894704a17209f84219773def5b8b14a060dc/uvicorn-0.11.2.tar.gz"; + sha256 = "11f397855c7f35dc034a3d288883382a4c16afdfe6675b70896f55bd6051da64"; +}; + doCheck = commonDoCheck; + format = "setuptools"; + buildInputs = commonBuildInputs ++ [ ]; + propagatedBuildInputs = [ + self."click" + self."h11" + self."httptools" + self."uvloop" + self."websockets" + ]; + meta = with pkgs.stdenv.lib; { + homepage = "https://github.com/encode/uvicorn"; + license = licenses.bsdOriginal; + description = "The lightning-fast ASGI server."; + }; + }; + + "uvloop" = python.mkDerivation { + name = "uvloop-0.14.0"; + src = pkgs.fetchurl { + url = "https://files.pythonhosted.org/packages/84/2e/462e7a25b787d2b40cf6c9864a9e702f358349fc9cfb77e83c38acb73048/uvloop-0.14.0.tar.gz"; + sha256 = "123ac9c0c7dd71464f58f1b4ee0bbd81285d96cdda8bc3519281b8973e3a461e"; +}; + doCheck = commonDoCheck; + format = "setuptools"; + buildInputs = commonBuildInputs ++ [ ]; + propagatedBuildInputs = [ ]; + meta = with pkgs.stdenv.lib; { + homepage = "http://github.com/MagicStack/uvloop"; + license = licenses.asl20; + description = "Fast implementation of asyncio event loop on top of libuv"; + }; + }; + "webencodings" = python.mkDerivation { name = "webencodings-0.5.1"; src = pkgs.fetchurl { @@ -1129,6 +1220,23 @@ let }; }; + "websockets" = python.mkDerivation { + name = "websockets-8.1"; + src = pkgs.fetchurl { + url = "https://files.pythonhosted.org/packages/e9/2b/cf738670bb96eb25cb2caf5294e38a9dc3891a6bcd8e3a51770dbc517c65/websockets-8.1.tar.gz"; + sha256 = "5c65d2da8c6bce0fca2528f69f44b2f977e06954c8512a952222cea50dad430f"; +}; + doCheck = commonDoCheck; + format = "setuptools"; + buildInputs = commonBuildInputs ++ [ ]; + propagatedBuildInputs = [ ]; + meta = with pkgs.stdenv.lib; { + homepage = "https://github.com/aaugustin/websockets"; + license = licenses.bsdOriginal; + description = "An implementation of the WebSocket Protocol (RFC 6455 & 7692)"; + }; + }; + "wheel" = python.mkDerivation { name = "wheel-0.34.2"; src = pkgs.fetchurl { diff --git a/requirements.txt b/requirements.txt index 1b7ceda..04f6f69 100644 --- a/requirements.txt +++ b/requirements.txt @@ -19,3 +19,6 @@ Django<2.2 django-classy-tags>=0.9 django-sekizai>=1.0 django-mptt>0.9 + +uvicorn +uvloop diff --git a/requirements_frozen.txt b/requirements_frozen.txt index 780085c..aa9f851 100644 --- a/requirements_frozen.txt +++ b/requirements_frozen.txt @@ -3,6 +3,7 @@ aldryn-forms==4.0.1 cachetools==4.0.0 certifi==2019.11.28 chardet==3.0.4 +Click==7.0 cssselect==1.1.0 cssutils==1.0.2 Django==2.1.15 @@ -36,7 +37,9 @@ djangocms-text-ckeditor==3.8.0 djangocms-video==2.2.0 easy-thumbnails==2.7 et-xmlfile==1.0.1 +h11==0.9.0 html5lib==1.0.1 +httptools==0.0.13 idna==2.8 jdcal==1.4.1 lxml==4.5.0 @@ -50,5 +53,8 @@ six==1.14.0 tablib==1.0.0 Unidecode==1.0.23 urllib3==1.25.8 +uvicorn==0.11.2 +uvloop==0.14.0 webencodings==0.5.1 +websockets==8.1 YURL==1.0.0 diff --git a/src/strojnadzor/management/commands/runserver-uvicorn.py b/src/strojnadzor/management/commands/runserver-uvicorn.py new file mode 100644 index 0000000..50de26c --- /dev/null +++ b/src/strojnadzor/management/commands/runserver-uvicorn.py @@ -0,0 +1,22 @@ +import uvicorn +from django.core.management.base import BaseCommand, CommandError + + +class Command(BaseCommand): + help = "Run Uvicorn HTTP server" + + def add_arguments(self, parser): + parser.add_argument("host", type=str) + parser.add_argument("port", type=int) + parser.add_argument("-w", "--workers", type=int, default=2) + + def handle(self, host, port, workers, **kwargs): + uvicorn.run( + "strojnadzor.wsgi:application", + interface="wsgi", + loop="uvloop", + workers=workers, + host=host, + port=port, + ) + diff --git a/src/strojnadzor/settings.py b/src/strojnadzor/settings.py index 1e01a6e..3319d1b 100644 --- a/src/strojnadzor/settings.py +++ b/src/strojnadzor/settings.py @@ -1,7 +1,7 @@ import os # isort:skip gettext = lambda s: s -DATA_DIR = os.path.dirname(os.path.dirname(__file__)) +DATA_DIR = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) """ Django settings for strojnadzor project. @@ -216,3 +216,5 @@ DJANGOCMS_PICTURE_RESPONSIVE_IMAGES = True DJANGOCMS_PICTURE_RESPONSIVE_IMAGES_VIEWPORT_BREAKPOINTS = [300, 400, 576, 768] DEFAULT_FROM_EMAIL = "noreply@sologoc.com" +FILER_DEBUG = True +THUMBNAIL_DEBUG = True