Skip to content

Commit

Permalink
windows compatiblity changes for setup scripts, movement of bootstrap…
Browse files Browse the repository at this point in the history
…per to its own file
  • Loading branch information
Chris7 committed Jun 23, 2015
1 parent 3a4e1de commit 5830db8
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ python:
install:
- pip install -q $DJANGO_VERSION
- pip install -q -r requirements.txt
- pip install -q -e .
- pip install -e .
# command to run tests
script: make test
after_success:
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ testenv:
pip install -e .

test:
nosetests tests
coverage run --branch --source=djangui --omit=djangui/conf*,djangui/migrations*,djangui/tests*,djangui/backend/ast* `which django-admin.py` test --settings=djangui.test_settings djangui.tests
nosetests --with-coverage --cover-erase --cover-package=djangui tests
coverage run --append --branch --source=djangui --omit=djangui/conf*,djangui/migrations*,djangui/tests*,djangui/backend/ast* `which django-admin.py` test --settings=djangui.test_settings djangui.tests
coverage report
25 changes: 10 additions & 15 deletions scripts/djanguify.py → djangui/backend/command_line.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
#!/usr/bin/env python
__author__ = 'chris'
description = """
Create a Django app with Djangui setup.
"""
import sys
import os
import subprocess
import shutil
from argparse import ArgumentParser
from django.template import Context
import djangui
from djangui import django_compat
env = os.environ
from .. import django_compat

def which(pgm):
# from http://stackoverflow.com/questions/9877462/is-there-a-python-equivalent-to-the-which-command
Expand All @@ -31,21 +25,26 @@ def walk_dir(templates, dest, filter=None):
l.append((os.path.join(root, filename), os.path.join(dest, relative_dir)))
return l

def main():
parser = ArgumentParser(description=description)
def bootstrap(env=None, cwd=None):
if env is None:
env = os.environ
parser = ArgumentParser(description="Create a Django app with Djangui setup.")
parser.add_argument('-p', '--project', help='The name of the django project to create.', type=str, required=True)
args = parser.parse_args()

project_name = args.project
new_project = not os.path.exists(project_name)
if not new_project:
sys.stderr.write('Project {0} already exists.\n'.format(project_name))
return 1
sys.exit(1)
env['DJANGO_SETTINGS_MODULE'] = ''
admin_command = [sys.executable] if sys.executable else []
admin_path = which('django-admin.py')
admin_command.extend([admin_path, 'startproject', project_name])
subprocess.call(admin_command, env=env)
admin_kwargs = {'env': env}
if cwd is not None:
admin_kwargs.update({'cwd': cwd})
subprocess.call(admin_command, **admin_kwargs)
project_root = project_name
project_base_dir = os.path.join(os.path.realpath(os.path.curdir), project_root, project_name)

Expand Down Expand Up @@ -91,7 +90,3 @@ def main():
sys.stdout.write("Please enter the project directory {0}, and run python manage.py createsuperuser and"
" python manage.py runserver to start. The admin can be found at localhost:8000/admin. You may also want to set your "
"DJANGO_SETTINGS_MODULE environment variable to {0}.settings \n".format(project_name))
return 0

if __name__ == "__main__":
sys.exit(main())
4 changes: 2 additions & 2 deletions djangui/conf/project_template/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class ProcessExceptionMiddleware(object):
def process_response(self, request, response):
if response.status_code != 200:
try:
sys.stderr.write('{}'.format('\n'.join(traceback.format_exc())))
sys.stderr.write('{}'.format(''.join(traceback.format_exc())))
except AttributeError:
pass
return response
return response
6 changes: 6 additions & 0 deletions scripts/djanguify
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env python
__author__ = 'chris'
from djangui.backend import command_line

if __name__ == "__main__":
command_line.bootstrap()
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
name='django-djangui',
version='0.2.6',
packages=find_packages(),
scripts=['scripts/djanguify.py'],
scripts=['scripts/djanguify'],
entry_points={'console_scripts': ['djanguify = djangui.backend.command_line:bootstrap',]},
install_requires = ['Django>=1.6', 'django-autoslug', 'django-celery', 'six'],
include_package_data=True,
license='GPLv3',
Expand Down
1 change: 0 additions & 1 deletion tests/__init__.py

This file was deleted.

22 changes: 15 additions & 7 deletions tests/test_project.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,40 @@
__author__ = 'chris'
from unittest import TestCase
import subprocess
import os
import subprocess
import shutil
import sys

BASE_DIR = os.path.split(__file__)[0]
DJANGUI_SCRIPT_PATH = os.path.join(BASE_DIR, '..', 'scripts', 'djanguify.py')
DJANGUI_SCRIPT_PATH = os.path.join(BASE_DIR, '..', 'scripts', 'djanguify')
DJANGUI_TEST_PROJECT_NAME = 'djangui_project'
DJANGUI_TEST_PROJECT_PATH = os.path.join(BASE_DIR, DJANGUI_TEST_PROJECT_NAME)
DJANGUI_TEST_PROJECT_MANAGE = os.path.join(DJANGUI_TEST_PROJECT_PATH, 'manage.py')
PYTHON_INTERPRETTER = 'python'
PYTHON_INTERPRETTER = sys.executable

env = os.environ
env['DJANGO_SETTINGS_MODULE'] = '{}.settings'.format(DJANGUI_TEST_PROJECT_NAME)
env['TESTING'] = 'True'

class TestProject(TestCase):
def setUp(self):
os.chdir(BASE_DIR)
# if old stuff exists, remove it
if os.path.exists(DJANGUI_TEST_PROJECT_PATH):
shutil.rmtree(DJANGUI_TEST_PROJECT_PATH)

def tearDown(self):
os.chdir(BASE_DIR)
if os.path.exists(DJANGUI_TEST_PROJECT_PATH):
shutil.rmtree(DJANGUI_TEST_PROJECT_PATH)

def test_bootstrap(self):
proc = subprocess.Popen([PYTHON_INTERPRETTER, DJANGUI_SCRIPT_PATH, '-p', DJANGUI_TEST_PROJECT_NAME],
cwd=BASE_DIR, env=env, stderr=subprocess.PIPE)
stdout, stderr = proc.communicate()
self.assertEqual(proc.returncode, 0, msg=stderr)
from djangui.backend import command_line
sys.argv = [DJANGUI_SCRIPT_PATH, '-p', DJANGUI_TEST_PROJECT_NAME]
ret = command_line.bootstrap(env=env, cwd=BASE_DIR)
self.assertIsNone(ret)
# test our script is executable from the command line, it will fail with return code of 1 since
# the project already exists
proc = subprocess.Popen([PYTHON_INTERPRETTER, DJANGUI_SCRIPT_PATH, '-p', DJANGUI_TEST_PROJECT_NAME])
stdout, stderr = proc.communicate()
self.assertEqual(proc.returncode, 1, stderr)

0 comments on commit 5830db8

Please sign in to comment.