Browse Source

Support doccano init on windows

pull/1529/head
Hironsan 3 years ago
parent
commit
08f8a9215b
4 changed files with 714 additions and 568 deletions
  1. 1
      Pipfile
  2. 1225
      Pipfile.lock
  3. 55
      backend/cli.py
  4. 1
      setup.py

1
Pipfile

@ -51,6 +51,7 @@ django-drf-filepond = "*"
celery = "*"
django-celery-results = "*"
sqlalchemy = "*"
waitress = "*"
[requires]
python_version = "3.8"

1225
Pipfile.lock
File diff suppressed because it is too large
View File

55
backend/cli.py

@ -1,12 +1,10 @@
import argparse
import multiprocessing
import os
import platform
import subprocess
import sys
import gunicorn.app.base
import gunicorn.util
from .app.celery import app
base = os.path.abspath(os.path.dirname(__file__))
@ -18,21 +16,38 @@ def number_of_workers():
return (multiprocessing.cpu_count() * 2) + 1
class StandaloneApplication(gunicorn.app.base.BaseApplication):
def run_on_windows(args):
import gunicorn.app.base
import gunicorn.util
class StandaloneApplication(gunicorn.app.base.BaseApplication):
def __init__(self, options=None):
self.options = options or {}
super().__init__()
def load_config(self):
config = {key: value for key, value in self.options.items()
if key in self.cfg.settings and value is not None}
for key, value in config.items():
self.cfg.set(key.lower(), value)
def load(self):
sys.path.append(base)
return gunicorn.util.import_app('app.wsgi')
def __init__(self, options=None):
self.options = options or {}
super().__init__()
options = {
'bind': '%s:%s' % ('0.0.0.0', args.port),
'workers': number_of_workers(),
'chdir': base
}
StandaloneApplication(options).run()
def load_config(self):
config = {key: value for key, value in self.options.items()
if key in self.cfg.settings and value is not None}
for key, value in config.items():
self.cfg.set(key.lower(), value)
def load(self):
sys.path.append(base)
return gunicorn.util.import_app('app.wsgi')
def run_on_nix(args):
from waitress import serve
from app.wsgi import application
serve(application, port=args.port)
def command_db_init(args):
@ -53,12 +68,10 @@ def command_user_create(args):
def command_run_webserver(args):
print(f'Starting server with port {args.port}.')
options = {
'bind': '%s:%s' % ('0.0.0.0', args.port),
'workers': number_of_workers(),
'chdir': base
}
StandaloneApplication(options).run()
if platform.system() == 'Windows':
run_on_windows(args)
else:
run_on_nix(args)
def command_run_task_queue(args):

1
setup.py

@ -42,6 +42,7 @@ required = [
'django-drf-filepond>=0.3.0',
'sqlalchemy>=1.4.7',
'gunicorn>=20.1.0',
'waitress>=2.0.0',
]
setup(

Loading…
Cancel
Save