From 587c2849b6b8b34f7e8f0080c513a10527a4a536 Mon Sep 17 00:00:00 2001 From: Jens Kleineheismann Date: Tue, 8 Oct 2019 14:50:10 +0200 Subject: [PATCH] Restructured everything. --- .buildbot/test/02-djangoproject | 2 - .buildbot/test/02-setup | 1 + .buildbot/test/03-settings | 1 - .buildbot/test/50-django_testrunner | 2 +- .gitignore | 6 +- MANIFEST.in | 3 - {base => apps}/__init__.py | 0 .../console_scripts => apps/base}/__init__.py | 0 .../base/bootstrap/css/bootstrap-grid.css | 0 .../base/bootstrap/css/bootstrap-grid.css.map | 0 .../base/bootstrap/css/bootstrap-grid.min.css | 0 .../bootstrap/css/bootstrap-grid.min.css.map | 0 .../base/bootstrap/css/bootstrap-reboot.css | 0 .../bootstrap/css/bootstrap-reboot.css.map | 0 .../bootstrap/css/bootstrap-reboot.min.css | 0 .../css/bootstrap-reboot.min.css.map | 0 .../static/base/bootstrap/css/bootstrap.css | 0 .../base/bootstrap/css/bootstrap.css.map | 0 .../base/bootstrap/css/bootstrap.min.css | 0 .../base/bootstrap/css/bootstrap.min.css.map | 0 .../base/bootstrap/js/bootstrap.bundle.js | 0 .../base/bootstrap/js/bootstrap.bundle.js.map | 0 .../base/bootstrap/js/bootstrap.bundle.min.js | 0 .../bootstrap/js/bootstrap.bundle.min.js.map | 0 .../static/base/bootstrap/js/bootstrap.js | 0 .../static/base/bootstrap/js/bootstrap.js.map | 0 .../static/base/bootstrap/js/bootstrap.min.js | 0 .../base/bootstrap/js/bootstrap.min.js.map | 0 {base => apps/base}/static/base/css/local.css | 0 .../base}/static/base/js/jquery.min.js | 0 {base => apps/base}/templates/base/base.html | 0 {base => apps/base}/templates/base/root.html | 0 {base => apps/base}/templates/signum.html | 0 {base => apps/base}/tests/__init__.py | 0 {base => apps/base}/tests/test_templates.py | 0 {base => apps/base}/tests/test_views.py | 0 {base => apps/base}/tests/utils.py | 0 {base => apps/base}/urls.py | 0 {base => apps/base}/views.py | 0 base/console_scripts/admin.py | 95 -------------- base/tests/test_scripts.py | 31 ----- bin/setup.py | 90 ++++++++++++++ .../django}/additional_settings.py | 9 +- setup.py | 117 ------------------ tests/__init__.py | 2 - tests/test_suite.py | 71 ----------- 46 files changed, 102 insertions(+), 328 deletions(-) delete mode 100644 .buildbot/test/02-djangoproject create mode 100644 .buildbot/test/02-setup delete mode 100644 .buildbot/test/03-settings delete mode 100644 MANIFEST.in rename {base => apps}/__init__.py (100%) rename {base/console_scripts => apps/base}/__init__.py (100%) rename {base => apps/base}/static/base/bootstrap/css/bootstrap-grid.css (100%) rename {base => apps/base}/static/base/bootstrap/css/bootstrap-grid.css.map (100%) rename {base => apps/base}/static/base/bootstrap/css/bootstrap-grid.min.css (100%) rename {base => apps/base}/static/base/bootstrap/css/bootstrap-grid.min.css.map (100%) rename {base => apps/base}/static/base/bootstrap/css/bootstrap-reboot.css (100%) rename {base => apps/base}/static/base/bootstrap/css/bootstrap-reboot.css.map (100%) rename {base => apps/base}/static/base/bootstrap/css/bootstrap-reboot.min.css (100%) rename {base => apps/base}/static/base/bootstrap/css/bootstrap-reboot.min.css.map (100%) rename {base => apps/base}/static/base/bootstrap/css/bootstrap.css (100%) rename {base => apps/base}/static/base/bootstrap/css/bootstrap.css.map (100%) rename {base => apps/base}/static/base/bootstrap/css/bootstrap.min.css (100%) rename {base => apps/base}/static/base/bootstrap/css/bootstrap.min.css.map (100%) rename {base => apps/base}/static/base/bootstrap/js/bootstrap.bundle.js (100%) rename {base => apps/base}/static/base/bootstrap/js/bootstrap.bundle.js.map (100%) rename {base => apps/base}/static/base/bootstrap/js/bootstrap.bundle.min.js (100%) rename {base => apps/base}/static/base/bootstrap/js/bootstrap.bundle.min.js.map (100%) rename {base => apps/base}/static/base/bootstrap/js/bootstrap.js (100%) rename {base => apps/base}/static/base/bootstrap/js/bootstrap.js.map (100%) rename {base => apps/base}/static/base/bootstrap/js/bootstrap.min.js (100%) rename {base => apps/base}/static/base/bootstrap/js/bootstrap.min.js.map (100%) rename {base => apps/base}/static/base/css/local.css (100%) rename {base => apps/base}/static/base/js/jquery.min.js (100%) rename {base => apps/base}/templates/base/base.html (100%) rename {base => apps/base}/templates/base/root.html (100%) rename {base => apps/base}/templates/signum.html (100%) rename {base => apps/base}/tests/__init__.py (100%) rename {base => apps/base}/tests/test_templates.py (100%) rename {base => apps/base}/tests/test_views.py (100%) rename {base => apps/base}/tests/utils.py (100%) rename {base => apps/base}/urls.py (100%) rename {base => apps/base}/views.py (100%) delete mode 100644 base/console_scripts/admin.py delete mode 100644 base/tests/test_scripts.py create mode 100755 bin/setup.py rename {base/console_scripts/django_project_config => etc/django}/additional_settings.py (89%) delete mode 100644 setup.py delete mode 100644 tests/__init__.py delete mode 100644 tests/test_suite.py diff --git a/.buildbot/test/02-djangoproject b/.buildbot/test/02-djangoproject deleted file mode 100644 index 8d9c416..0000000 --- a/.buildbot/test/02-djangoproject +++ /dev/null @@ -1,2 +0,0 @@ -mkdir -p env/django -django-admin startproject main env/django diff --git a/.buildbot/test/02-setup b/.buildbot/test/02-setup new file mode 100644 index 0000000..20b2c91 --- /dev/null +++ b/.buildbot/test/02-setup @@ -0,0 +1 @@ +python bin/setup.py diff --git a/.buildbot/test/03-settings b/.buildbot/test/03-settings deleted file mode 100644 index 3bb7b6b..0000000 --- a/.buildbot/test/03-settings +++ /dev/null @@ -1 +0,0 @@ -cat base/console_scripts/django_project_config/additional_settings.py >> env/django/main/settings.py diff --git a/.buildbot/test/50-django_testrunner b/.buildbot/test/50-django_testrunner index b69f5f2..7cd7b17 100644 --- a/.buildbot/test/50-django_testrunner +++ b/.buildbot/test/50-django_testrunner @@ -1 +1 @@ -python env/django/manage.py test +python manage.py test diff --git a/.gitignore b/.gitignore index a2e4b13..89f4aa8 100644 --- a/.gitignore +++ b/.gitignore @@ -3,9 +3,9 @@ geckodriver.log .idea/ -django_test.egg-info/ -build/ -dist/ +manage.py +conf/ env/ tmp/ +var/ diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index 73f9111..0000000 --- a/MANIFEST.in +++ /dev/null @@ -1,3 +0,0 @@ -recursive-include base/console_scripts/django_project_config *.py -recursive-include base/static * -recursive-include base/templates * diff --git a/base/__init__.py b/apps/__init__.py similarity index 100% rename from base/__init__.py rename to apps/__init__.py diff --git a/base/console_scripts/__init__.py b/apps/base/__init__.py similarity index 100% rename from base/console_scripts/__init__.py rename to apps/base/__init__.py diff --git a/base/static/base/bootstrap/css/bootstrap-grid.css b/apps/base/static/base/bootstrap/css/bootstrap-grid.css similarity index 100% rename from base/static/base/bootstrap/css/bootstrap-grid.css rename to apps/base/static/base/bootstrap/css/bootstrap-grid.css diff --git a/base/static/base/bootstrap/css/bootstrap-grid.css.map b/apps/base/static/base/bootstrap/css/bootstrap-grid.css.map similarity index 100% rename from base/static/base/bootstrap/css/bootstrap-grid.css.map rename to apps/base/static/base/bootstrap/css/bootstrap-grid.css.map diff --git a/base/static/base/bootstrap/css/bootstrap-grid.min.css b/apps/base/static/base/bootstrap/css/bootstrap-grid.min.css similarity index 100% rename from base/static/base/bootstrap/css/bootstrap-grid.min.css rename to apps/base/static/base/bootstrap/css/bootstrap-grid.min.css diff --git a/base/static/base/bootstrap/css/bootstrap-grid.min.css.map b/apps/base/static/base/bootstrap/css/bootstrap-grid.min.css.map similarity index 100% rename from base/static/base/bootstrap/css/bootstrap-grid.min.css.map rename to apps/base/static/base/bootstrap/css/bootstrap-grid.min.css.map diff --git a/base/static/base/bootstrap/css/bootstrap-reboot.css b/apps/base/static/base/bootstrap/css/bootstrap-reboot.css similarity index 100% rename from base/static/base/bootstrap/css/bootstrap-reboot.css rename to apps/base/static/base/bootstrap/css/bootstrap-reboot.css diff --git a/base/static/base/bootstrap/css/bootstrap-reboot.css.map b/apps/base/static/base/bootstrap/css/bootstrap-reboot.css.map similarity index 100% rename from base/static/base/bootstrap/css/bootstrap-reboot.css.map rename to apps/base/static/base/bootstrap/css/bootstrap-reboot.css.map diff --git a/base/static/base/bootstrap/css/bootstrap-reboot.min.css b/apps/base/static/base/bootstrap/css/bootstrap-reboot.min.css similarity index 100% rename from base/static/base/bootstrap/css/bootstrap-reboot.min.css rename to apps/base/static/base/bootstrap/css/bootstrap-reboot.min.css diff --git a/base/static/base/bootstrap/css/bootstrap-reboot.min.css.map b/apps/base/static/base/bootstrap/css/bootstrap-reboot.min.css.map similarity index 100% rename from base/static/base/bootstrap/css/bootstrap-reboot.min.css.map rename to apps/base/static/base/bootstrap/css/bootstrap-reboot.min.css.map diff --git a/base/static/base/bootstrap/css/bootstrap.css b/apps/base/static/base/bootstrap/css/bootstrap.css similarity index 100% rename from base/static/base/bootstrap/css/bootstrap.css rename to apps/base/static/base/bootstrap/css/bootstrap.css diff --git a/base/static/base/bootstrap/css/bootstrap.css.map b/apps/base/static/base/bootstrap/css/bootstrap.css.map similarity index 100% rename from base/static/base/bootstrap/css/bootstrap.css.map rename to apps/base/static/base/bootstrap/css/bootstrap.css.map diff --git a/base/static/base/bootstrap/css/bootstrap.min.css b/apps/base/static/base/bootstrap/css/bootstrap.min.css similarity index 100% rename from base/static/base/bootstrap/css/bootstrap.min.css rename to apps/base/static/base/bootstrap/css/bootstrap.min.css diff --git a/base/static/base/bootstrap/css/bootstrap.min.css.map b/apps/base/static/base/bootstrap/css/bootstrap.min.css.map similarity index 100% rename from base/static/base/bootstrap/css/bootstrap.min.css.map rename to apps/base/static/base/bootstrap/css/bootstrap.min.css.map diff --git a/base/static/base/bootstrap/js/bootstrap.bundle.js b/apps/base/static/base/bootstrap/js/bootstrap.bundle.js similarity index 100% rename from base/static/base/bootstrap/js/bootstrap.bundle.js rename to apps/base/static/base/bootstrap/js/bootstrap.bundle.js diff --git a/base/static/base/bootstrap/js/bootstrap.bundle.js.map b/apps/base/static/base/bootstrap/js/bootstrap.bundle.js.map similarity index 100% rename from base/static/base/bootstrap/js/bootstrap.bundle.js.map rename to apps/base/static/base/bootstrap/js/bootstrap.bundle.js.map diff --git a/base/static/base/bootstrap/js/bootstrap.bundle.min.js b/apps/base/static/base/bootstrap/js/bootstrap.bundle.min.js similarity index 100% rename from base/static/base/bootstrap/js/bootstrap.bundle.min.js rename to apps/base/static/base/bootstrap/js/bootstrap.bundle.min.js diff --git a/base/static/base/bootstrap/js/bootstrap.bundle.min.js.map b/apps/base/static/base/bootstrap/js/bootstrap.bundle.min.js.map similarity index 100% rename from base/static/base/bootstrap/js/bootstrap.bundle.min.js.map rename to apps/base/static/base/bootstrap/js/bootstrap.bundle.min.js.map diff --git a/base/static/base/bootstrap/js/bootstrap.js b/apps/base/static/base/bootstrap/js/bootstrap.js similarity index 100% rename from base/static/base/bootstrap/js/bootstrap.js rename to apps/base/static/base/bootstrap/js/bootstrap.js diff --git a/base/static/base/bootstrap/js/bootstrap.js.map b/apps/base/static/base/bootstrap/js/bootstrap.js.map similarity index 100% rename from base/static/base/bootstrap/js/bootstrap.js.map rename to apps/base/static/base/bootstrap/js/bootstrap.js.map diff --git a/base/static/base/bootstrap/js/bootstrap.min.js b/apps/base/static/base/bootstrap/js/bootstrap.min.js similarity index 100% rename from base/static/base/bootstrap/js/bootstrap.min.js rename to apps/base/static/base/bootstrap/js/bootstrap.min.js diff --git a/base/static/base/bootstrap/js/bootstrap.min.js.map b/apps/base/static/base/bootstrap/js/bootstrap.min.js.map similarity index 100% rename from base/static/base/bootstrap/js/bootstrap.min.js.map rename to apps/base/static/base/bootstrap/js/bootstrap.min.js.map diff --git a/base/static/base/css/local.css b/apps/base/static/base/css/local.css similarity index 100% rename from base/static/base/css/local.css rename to apps/base/static/base/css/local.css diff --git a/base/static/base/js/jquery.min.js b/apps/base/static/base/js/jquery.min.js similarity index 100% rename from base/static/base/js/jquery.min.js rename to apps/base/static/base/js/jquery.min.js diff --git a/base/templates/base/base.html b/apps/base/templates/base/base.html similarity index 100% rename from base/templates/base/base.html rename to apps/base/templates/base/base.html diff --git a/base/templates/base/root.html b/apps/base/templates/base/root.html similarity index 100% rename from base/templates/base/root.html rename to apps/base/templates/base/root.html diff --git a/base/templates/signum.html b/apps/base/templates/signum.html similarity index 100% rename from base/templates/signum.html rename to apps/base/templates/signum.html diff --git a/base/tests/__init__.py b/apps/base/tests/__init__.py similarity index 100% rename from base/tests/__init__.py rename to apps/base/tests/__init__.py diff --git a/base/tests/test_templates.py b/apps/base/tests/test_templates.py similarity index 100% rename from base/tests/test_templates.py rename to apps/base/tests/test_templates.py diff --git a/base/tests/test_views.py b/apps/base/tests/test_views.py similarity index 100% rename from base/tests/test_views.py rename to apps/base/tests/test_views.py diff --git a/base/tests/utils.py b/apps/base/tests/utils.py similarity index 100% rename from base/tests/utils.py rename to apps/base/tests/utils.py diff --git a/base/urls.py b/apps/base/urls.py similarity index 100% rename from base/urls.py rename to apps/base/urls.py diff --git a/base/views.py b/apps/base/views.py similarity index 100% rename from base/views.py rename to apps/base/views.py diff --git a/base/console_scripts/admin.py b/base/console_scripts/admin.py deleted file mode 100644 index d8b5559..0000000 --- a/base/console_scripts/admin.py +++ /dev/null @@ -1,95 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals -import argparse -import os -import pkg_resources -import sys - -DJANGO_MAIN_MODULE = 'main' -VERSION = '0.1' - - -class AdminCommand(object): - @staticmethod - def _setup_argparser(): - kwargs = { - 'description': 'Tool to manage your test django installation.', - } - parser = argparse.ArgumentParser(**kwargs) - - parser.add_argument('-V', '--version', action='version', - version='%(prog)s ' + VERSION) - - subparsers = parser.add_subparsers(dest='subcmd', metavar='CMD', - title='subcommands', - description="Use '%(prog)s CMD -h' to show help for a subcommand") - subparser = subparsers.add_parser('setup', help='Setup the installation.') - subparser.add_argument('path', metavar='PATH', - help='A directory, where the project files will be installed.') - - return parser - - def _parse_args(self, argv=None): - if argv is None: - argv = sys.argv[1:] - if not argv: - argv = ['--help'] - - return self._argparser.parse_args(argv) - - @staticmethod - def _subcmd_setup(cmd_args): - django_main_module = DJANGO_MAIN_MODULE - django_base_dir = cmd_args.path - - sys.stdout.write('Setup installation in \'{path}\'...\n'.format(path=django_base_dir)) - - if os.path.exists(django_base_dir): - if not os.path.isdir(django_base_dir): - sys.stderr.write('{path}: Not a directory.\n'.format(path=django_base_dir)) - return os.EX_USAGE - else: - os.makedirs(django_base_dir) - - sys.stdout.write('Creating django project...\n') - django_cmd = 'django-admin startproject {name} "{path}"'.format(name=django_main_module, - path=django_base_dir) - exitval = os.system(django_cmd) - if exitval != os.EX_OK: - return exitval - - sys.stdout.write('Configure django project...\n') - - input_file = os.path.join('django_project_config', 'additional_settings.py') - output_file = os.path.join(django_base_dir, django_main_module, 'settings.py') - with open(output_file, 'ab') as f: - f.write(pkg_resources.resource_string(__package__, input_file)) - - sys.stdout.write('Creating directories...\n') - dirs = [ - os.path.join(django_base_dir, 'var', 'log'), - os.path.join(django_base_dir, 'var', 'www', 'static'), - ] - - for d in dirs: - sys.stdout.write(' - %s\n' % d) - os.makedirs(d) - - return os.EX_OK - - def __init__(self): - self._argparser = self._setup_argparser() - - def __call__(self, argv=None): - cmd_args = self._parse_args(argv) - subcmd = cmd_args.subcmd - method_name = '_subcmd_{}'.format(subcmd) - method = getattr(self, method_name) - exitval = method(cmd_args) - return exitval - - -def main(): - cmd = AdminCommand() - exitval = cmd() - sys.exit(exitval) diff --git a/base/tests/test_scripts.py b/base/tests/test_scripts.py deleted file mode 100644 index 2cefb1e..0000000 --- a/base/tests/test_scripts.py +++ /dev/null @@ -1,31 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals -import os -import shutil -from django.test import SimpleTestCase - -from ..console_scripts.admin import DJANGO_MAIN_MODULE, AdminCommand - -from .utils import mkdtemp - - -class AdminTestCase(SimpleTestCase): - def setUp(self): - super(AdminTestCase, self).setUp() - self.tmp_dir = mkdtemp(prefix='AdminTestCase') - - def tearDown(self): - super(AdminTestCase, self).tearDown() - if os.path.isdir(self.tmp_dir): - shutil.rmtree(self.tmp_dir) - - def test_setup(self): - path = self.tmp_dir - cmd = AdminCommand() - argv = ['setup', path] - exitval = cmd(argv) - self.assertEqual(exitval, os.EX_OK) - self.assertTrue(os.path.isfile(os.path.join(path, 'manage.py'))) - self.assertTrue(os.path.isfile(os.path.join(path, DJANGO_MAIN_MODULE, 'settings.py'))) - self.assertTrue(os.path.isdir(os.path.join(path, 'var', 'log'))) - self.assertTrue(os.path.isdir(os.path.join(path, 'var', 'www', 'static'))) diff --git a/bin/setup.py b/bin/setup.py new file mode 100755 index 0000000..74ca464 --- /dev/null +++ b/bin/setup.py @@ -0,0 +1,90 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +from __future__ import unicode_literals +import argparse +import os +import shutil +import sys + + +class Command(object): + settings_module_name = 'main' + + @staticmethod + def _setup_argparser(): + kwargs = { + 'description': 'Setup and configure the django project.', + } + parser = argparse.ArgumentParser(**kwargs) + + parser.add_argument('--force', + action='store_true', dest='force', + help='Overwrite existing django settings') + return parser + + def _parse_args(self, argv=None): + if argv is None: + argv = sys.argv[1:] + + return self._argparser.parse_args(argv) + + def _run(self, force=False): + settings_module_name = self.settings_module_name + settings_file = os.path.join(settings_module_name, 'settings.py') + + if os.path.exists(settings_file): + if not force: + sys.stderr.write('Django settings file detected. Abort!\n') + return os.EX_NOPERM + + if os.path.exists('manage.py') or \ + os.path.exists(settings_module_name): + sys.stdout.write('Replacing django files...\n') + if os.path.exists('manage.py'): + os.unlink('manage.py') + if os.path.exists(settings_module_name): + shutil.rmtree(settings_module_name) + else: + sys.stdout.write('Installing django files...\n') + + cmd = 'django-admin startproject {name} .'.format(name=settings_module_name) + exitval = os.system(cmd) + if exitval != os.EX_OK: + return exitval + + sys.stdout.write('Configure django...\n') + add_settings_file = os.path.join('etc', 'django', 'additional_settings.py') + with open(settings_file, 'a') as f_out: + with open(add_settings_file) as f_in: + f_out.write(f_in.read()) + + sys.stdout.write('Creating directories...\n') + dirs = [ + os.path.join('var', 'db'), + os.path.join('var', 'log'), + os.path.join('var', 'www', 'static'), + ] + for d in dirs: + sys.stdout.write(' - %s\n' % d) + if not os.path.exists(d): + os.makedirs(d) + + return os.EX_OK + + def __init__(self): + self._argparser = self._setup_argparser() + + def __call__(self, argv=None): + cmd_args = self._parse_args(argv) + exitval = self._run(cmd_args.force) + return exitval + + +def main(): + cmd = Command() + exitval = cmd() + sys.exit(exitval) + + +if __name__ == '__main__': + main() diff --git a/base/console_scripts/django_project_config/additional_settings.py b/etc/django/additional_settings.py similarity index 89% rename from base/console_scripts/django_project_config/additional_settings.py rename to etc/django/additional_settings.py index 6c5bb44..6b68ff0 100644 --- a/base/console_scripts/django_project_config/additional_settings.py +++ b/etc/django/additional_settings.py @@ -9,10 +9,15 @@ LOG_DIR = os.path.join(BASE_VAR_DIR, 'log') INSTALLED_APPS += [ 'django_extensions', # Our main app - 'base', + 'apps.base', ] -ROOT_URLCONF = 'base.urls' +DATABASES['default'] = { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_VAR_DIR, 'db', 'devel.sqlite3'), +} + +ROOT_URLCONF = 'apps.base.urls' STATIC_ROOT = os.path.join(BASE_VAR_DIR, 'www', 'static') LOGGING = { diff --git a/setup.py b/setup.py deleted file mode 100644 index 84d5f10..0000000 --- a/setup.py +++ /dev/null @@ -1,117 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -from __future__ import unicode_literals -import os -import sys -from setuptools import setup, find_packages -from setuptools import Command - - -class MyCommand(Command): - user_options = [] - - def initialize_options(self): - pass - - def finalize_options(self): - pass - - -class SetupPythonEnvironment(MyCommand): - description = 'create a (virtual) python environment' - - @staticmethod - def run(): - python_bin = sys.executable if sys.executable else 'python' - python_ver = sys.version_info.major - if python_ver == 2: - path = os.path.join('env', 'python2') - symlink_path = os.path.join('env', 'python') - venv_module = 'virtualenv' - prompt = '(py2-django) ' - elif python_ver == 3: - path = os.path.join('env', 'python3') - symlink_path = os.path.join('env', 'python') - venv_module = 'venv' - prompt = 'py3-django' - else: - sys.stderr.write('Python {} is not supported.\n'.format(python_ver)) - sys.exit(os.EX_USAGE) - - sys.stdout.write('Creating new python environment in {path}\n'.format(path=path)) - cmd = ('{bin} -m {venv_module}' - ' --prompt="{prompt}"' - ' {path}'.format(bin=python_bin, path=path, - venv_module=venv_module, prompt=prompt)) - os.system(cmd) - - if symlink_path and not os.path.exists(symlink_path): - symlink_dir = os.path.dirname(symlink_path) - relpath = os.path.relpath(path, symlink_dir) - os.symlink(relpath, symlink_path) - - print('') - print('Depending on your operating system or command shell,') - print('you should activate the new environment for this shell session') - print('by running ONE of the following commands:') - print('- Windows: %s' % os.path.join(path, 'Scripts', 'activate')) - print('- C Shell: source %s/bin/activate.csh' % path) - print('- All others: source %s/bin/activate' % path) - - -class SetupDjangoEnvironment(MyCommand): - description = 'create a typical installation for developing' - - @staticmethod - def run(): - # python_bin = sys.executable if sys.executable else 'python' - django_project_path = 'env/django' - # mgmt_script = os.path.join(django_project_path, 'manage.py') - - sys.stdout.write('Install distribution in development mode...\n') - cmd = 'pip install -e .' - os.system(cmd) - - sys.stdout.write('Setup django project in {}...\n'.format(django_project_path)) - cmd = 'django-test-admin setup {}'.format(django_project_path) - os.system(cmd) - - # sys.stdout.write('Make database migrations...\n') - # cmd = '{bin} {mgmt} makemigrations'.format(bin=python_bin, mgmt=mgmt_script) - # os.system(cmd) - - # sys.stdout.write('Create database...\n') - # cmd = '{bin} {mgmt} migrate'.format(bin=python_bin, mgmt=mgmt_script) - # os.system(cmd) - - # sys.stdout.write('Create superuser \'root\'...\n') - # cmd = ('{bin} {mgmt} createsuperuser' - # ' --username root').format(bin=python_bin, mgmt=mgmt_script) - # os.system(cmd) - - -setup( - name='django-test', - version='1.0', - description='An example django based web application.', - url='https://heinzelwelt.de', - maintainer='Jens Kleineheismann', - maintainer_email='heinzel@heinzelwelt.de', - cmdclass={ - 'mkpyenv': SetupPythonEnvironment, - 'mkdjangoenv': SetupDjangoEnvironment, - }, - packages=find_packages(exclude=['tests']), - include_package_data=True, - test_suite='tests.test_suite', - entry_points={ - 'console_scripts': [ - 'django-test-admin = base.console_scripts.admin:main', - ], - }, - install_requires=[ - 'coverage', - 'django', - 'django-extensions', - ], -) diff --git a/tests/__init__.py b/tests/__init__.py deleted file mode 100644 index 014b65d..0000000 --- a/tests/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -from .test_suite import TestSuite -test_suite = TestSuite() diff --git a/tests/test_suite.py b/tests/test_suite.py deleted file mode 100644 index 752ceff..0000000 --- a/tests/test_suite.py +++ /dev/null @@ -1,71 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals -import datetime -import django -import os -import shutil -import sys -from django.test.utils import get_runner - -from base.console_scripts.admin import DJANGO_MAIN_MODULE -from base.tests.utils import mkdtemp - - -class DjangoEnvironment(object): - @staticmethod - def _install_djangoproject(path): - cmd = 'django-test-admin setup "{}"'.format(path) - os.system(cmd) - - def __init__(self, path=None, remove_after=True): - self.path = path - - self._remove_after = remove_after - self._original_sys_path = None - self._modified_sys_path = None - - def __enter__(self): - if self.path is None: - prefix = 'testrun-{datetime}-'.format( - datetime=datetime.datetime.now().strftime('%Y%m%d-%H%M') - ) - self.path = mkdtemp(prefix=prefix) - - self._install_djangoproject(self.path) - - self._original_sys_path = sys.path - sys.path.append(self.path) - self._modified_sys_path = sys.path - - os.environ['DJANGO_SETTINGS_MODULE'] = '{}.settings'.format(DJANGO_MAIN_MODULE) - django.setup() - - from django.conf import settings - self.settings = settings - - return self - - def __exit__(self, *args): - if self._modified_sys_path is not None and self._original_sys_path is not None: - if sys.path == self._modified_sys_path: - sys.path = self._original_sys_path - if self._remove_after: - shutil.rmtree(self.path) - - -class TestSuite(object): - @staticmethod - def run(): - tests = ['base'] - test_tags = None - exclude_test_tags = None - - with DjangoEnvironment() as env: - test_runner_class = get_runner(env.settings) - test_runner = test_runner_class(tags=test_tags, exclude_tags=exclude_test_tags) - failures = test_runner.run_tests(tests) - - return bool(failures) - - def __call__(self): - sys.exit(self.run())