From cc51045f681782f4a9a349ea2f09b81c8db48045 Mon Sep 17 00:00:00 2001 From: Hironsan Date: Tue, 8 Dec 2020 11:56:22 +0900 Subject: [PATCH] Update setup.py and settings.py to fix #1095 --- app/app/settings.py | 19 +++++++++++++------ app/doccano/doccano.py | 8 ++++---- setup.py | 11 ++++++++--- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/app/app/settings.py b/app/app/settings.py index 1163ddbb..84577b02 100644 --- a/app/app/settings.py +++ b/app/app/settings.py @@ -10,9 +10,10 @@ https://docs.djangoproject.com/en/2.0/ref/settings/ Any setting that is configured via an environment variable may also be set in a `.env` file in the project base directory. """ +import importlib.util +import sys from os import path -import django_heroku import dj_database_url from environs import Env from furl import furl @@ -53,13 +54,13 @@ INSTALLED_APPS = [ 'django.contrib.staticfiles', 'server.apps.ServerConfig', 'api.apps.ApiConfig', - 'widget_tweaks', + # 'widget_tweaks', 'rest_framework', 'rest_framework.authtoken', 'django_filters', 'social_django', 'polymorphic', - 'webpack_loader', + # 'webpack_loader', 'corsheaders', 'drf_yasg' ] @@ -83,7 +84,7 @@ MIDDLEWARE = [ 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', 'social_django.middleware.SocialAuthExceptionMiddleware', - 'applicationinsights.django.ApplicationInsightsMiddleware', + # 'applicationinsights.django.ApplicationInsightsMiddleware', 'corsheaders.middleware.CorsMiddleware', ] @@ -277,7 +278,13 @@ LOGIN_URL = '/login/' LOGIN_REDIRECT_URL = '/projects/' LOGOUT_REDIRECT_URL = '/' -django_heroku.settings(locals(), test_runner=False) +# dynamic import to avoid installing psycopg2 on pip installation. +name = 'django_heroku' +if (spec := importlib.util.find_spec(name)) is not None: + module = importlib.util.module_from_spec(spec) + sys.modules[name] = module + spec.loader.exec_module(module) + django_heroku.settings(locals(), test_runner=False) # Change 'default' database configuration with $DATABASE_URL. DATABASES['default'].update(dj_database_url.config( @@ -309,7 +316,7 @@ CSRF_COOKIE_SECURE = env.bool('CSRF_COOKIE_SECURE', False) CSRF_TRUSTED_ORIGINS = env.list('CSRF_TRUSTED_ORIGINS', []) # Allow all host headers -# ALLOWED_HOSTS = ['*'] +ALLOWED_HOSTS = ['*'] # Size of the batch for creating documents # on the import phase diff --git a/app/doccano/doccano.py b/app/doccano/doccano.py index 4186cf9c..c6f0a610 100644 --- a/app/doccano/doccano.py +++ b/app/doccano/doccano.py @@ -4,13 +4,13 @@ import subprocess def main(): - parser = argparse.ArgumentParser(description='doccano.') + parser = argparse.ArgumentParser(description='doccano, text annotation for machine learning practitioners.') parser.add_argument('--username', type=str, default='admin', help='admin username') parser.add_argument('--password', type=str, default='password', help='admin password') parser.add_argument('--email', type=str, default='example@example.com', help='admin email') - parser.add_argument('--port', type=int, default=8000, help='port') - parser.add_argument('--workers', type=int, default=1, help='workers') - parser.add_argument('--database_url', type=str, default='sqlite:///doccano.db', help='data store') + parser.add_argument('--port', type=int, default=8000, help='port number') + # parser.add_argument('--workers', type=int, default=1, help='the number of workers') + parser.add_argument('--database_url', type=str, default='sqlite:///doccano.db', help='the database URL') args = parser.parse_args() os.environ.setdefault('DEBUG', 'False') diff --git a/setup.py b/setup.py index 57538e8b..2a584c7a 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ import os from setuptools import find_packages, setup NAME = 'doccano' -DESCRIPTION = 'doccano' +DESCRIPTION = 'doccano, text annotation tool for machine learning practitioners' URL = 'https://github.com/doccano/doccano' EMAIL = 'hiroki.nakayama.py@gmail.com' AUTHOR = 'Hironsan' @@ -16,8 +16,9 @@ here = os.path.abspath(os.path.dirname(__file__)) with io.open(os.path.join(here, 'README.md'), encoding='utf-8') as f: long_description = '\n' + f.read() -# required = ['requests', 'boto3', 'pydantic', 'jinja2'] -required = [line.rstrip() for line in io.open(os.path.join(here, 'app/requirements.txt')) if not line.startswith('psy')] +# Todo: make a cleaned requirements.txt +required = [line.rstrip() for line in io.open(os.path.join(here, 'app/requirements.txt')) + if not line.startswith(('psycopg2', 'django-heroku', 'django-mssql-backend'))] setup( name=NAME, @@ -36,6 +37,10 @@ setup( ] }, install_requires=required, + extras_require={ + 'postgresql': ['psycopg2-binary>=2.8.6'], + 'mssql': ['django-mssql-backend>=2.8.1'], + }, include_package_data=True, license=LICENSE, classifiers=[