Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanhiebert committed Nov 29, 2017
0 parents commit 0547e8e
Show file tree
Hide file tree
Showing 10 changed files with 244 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*.py[co]
__pycache__/
*.egg-info/
.tox/
.cache/
.coverage*
35 changes: 35 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
dist: trusty
sudo: false
language: python
python:
- 2.7
- 3.4
- 3.5
- 3.6
install:
- pip install tox-travis wheel codecov coverage
- python setup.py bdist_wheel
script: tox --installpkg ./dist/*.whl
after_success: coverage combine && codecov
stages:
- test
- name: deploy
if: tag IS present
jobs:
fast_finish: true
include:
- python: 3.6
env: TOXENV=desc
- stage: deploy
python: 3.6
install: true
script: true
after_success: true
deploy:
provider: pypi
user: ryanhiebert-auto
password:
secure: d5Z3xlI2kdy+GzR0Zj805NSM3YHc0j3D2+zClQ/zLfvAoWzHiOIXkWL0xVfSKVcbzI0Jx05FiHQt3FoWjnYmYqZVFcyXM3ehiyOsw/k2VIw0wu7+qyJIHeGrkr0GmXd8oqHdHNmBPXubI/I9kDgcEdALDboxxQcK1phrOtjUgNiBlIeKgEoJw4qo8CHL9lbyfVkXzoBV7wxWwp4nE+SkZcvex7i+i1zAVp5Akrr3oEYu2zrFpiYN2+fccNQLTgoSS1YRiWGWPbYd2+d2dZOf+pNnlovQWLZF+Urw47YdrE3RN4qsm4i8O/BzVriVvvShLONDLHBkeFcFYfB+El9n1uc0UwvwslJeyVEdu1QB5sv/Uq0Ge2vVZEyZoW2qzfvGCFj8yNT+tpchagtuiyklwHOi+TuKjCYUDVLgGB6vJmaSTKnpGKlCOUTUnbKD/zEAUkk7XMPa9MtrF0AYY+VJ0oBQDftSH89jNtC0Bv9mh9HBx6oDRV+icvjK4dn3BxCTFwLsrHR7dyZ+SteK5EM25cFsX+3voZoMePIL78+8XsAKNhG0GWWQGaV6lij+XI9Xtx8cy2e/uNZwn5R9UoNprfZ61cPbc5Gk9VnZSrlqEY9PiHWHrhZuiC30isPW4pQciB4kksRb+Kbx2KnoZfwQbgAIbBARe510U47RN8zJdNM=
on:
tags: true
distributions: bdist_wheel
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
The MIT License (MIT)

Copyright (c) 2015 Ryan Hiebert

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include *.rst LICENSE
43 changes: 43 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
================================
django-cmd: Get a django command
================================

.. image:: https://img.shields.io/pypi/v/django-cmd.svg
:target: https://pypi.python.org/pypi/django-cmd
:alt: Latest Version

.. image:: https://travis-ci.org/ryanhiebert/django-cmd.svg?branch=master
:target: https://travis-ci.org/ryanhiebert/django-cmd

.. image:: https://codecov.io/gh/ryanhiebert/django-cmd/branch/master/graph/badge.svg
:target: https://codecov.io/gh/ryanhiebert/django-cmd


Django only includes the ``django-admin``.
They prefer to not include multiple ways to do the same thing,
but I really want to spell it ``django``.
I also wanted to be able to configure a
default settings file in a ``setup.cfg`` configuration file.


Usage
=====

.. code-block:: sh
pip install django-cmd
django startproject
Once installed, you can use the ``django`` command
the same as you would normally use the ``django-admin`` command.
Additionally, you can add a section like this to a ``setup.cfg`` file
to configure the ``DJANGO_SETTINGS_MODULE``
that you would like to use when no other is specified.

.. code-block:: ini
[django]
settings_module = myproject.settings
That's it! Have fun!
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[bdist_wheel]
universal = 1
37 changes: 37 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import io
from setuptools import setup

setup(
name='django-cmd',
description='Get a django command',
long_description=io.open('README.rst', encoding='utf-8').read(),
author='Ryan Hiebert',
author_email='ryan@ryanhiebert.com',
url='https://github.com/ryanhiebert/django-cmd',
license='MIT',
version='1.0',
package_dir={'': 'src'},
py_modules=['django_cmd'],
install_requires=['Django'],
classifiers=[
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Framework :: Django :: 1.8',
'Framework :: Django :: 1.10',
'Framework :: Django :: 1.11',
'Framework :: Django :: 2.0',
],
entry_points={
'console_scripts': [
'django = django_cmd:main',
],
},
)
19 changes: 19 additions & 0 deletions src/django_cmd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import os
import sys

try:
import configparser
except ImportError: # Python 2
import ConfigParser as configparser
from django.core.management import execute_from_command_line


def main():
"""Run Django, getting the default from a file if needed."""
if 'DJANGO_SETTINGS_MODULE' not in os.environ:
parser = configparser.RawConfigParser()
parser.read('setup.cfg')
if parser.has_option('django', 'settings_module'):
settings_module = parser.get('django', 'settings_module')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', settings_module)
execute_from_command_line(sys.argv)
42 changes: 42 additions & 0 deletions tests/django_cmd_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import os
import subprocess
from django_cmd import main


def test_main_passthru(monkeypatch, mocker, tmpdir):
"""It shouldn't change a given DJANGO_SETTINGS_MODULE."""
cmd = mocker.patch('django_cmd.execute_from_command_line')
monkeypatch.setenv('DJANGO_SETTINGS_MODULE', 'spam.eggs')
content = u'[django]\nsettings_module = ball.yarn\n'
tmpdir.chdir()
tmpdir.join('setup.cfg').write(content.encode('utf-8'))
main()
assert os.environ.get('DJANGO_SETTINGS_MODULE') == 'spam.eggs'
assert cmd.called


def test_main_from_configfile(monkeypatch, mocker, tmpdir):
"""Read settings module path from config file."""
cmd = mocker.patch('django_cmd.execute_from_command_line')
content = u'[django]\nsettings_module = ball.yarn\n'
tmpdir.chdir()
tmpdir.join('setup.cfg').write(content.encode('utf-8'))
main()
assert os.environ.get('DJANGO_SETTINGS_MODULE') == 'ball.yarn'
assert cmd.called
del os.environ['DJANGO_SETTINGS_MODULE']


def test_main_no_configfile(monkeypatch, mocker, tmpdir):
"""Try to read settings module, but fail and still run command."""
cmd = mocker.patch('django_cmd.execute_from_command_line')
print(tmpdir)
tmpdir.chdir()
main()
assert 'DJANGO_SETTINGS_MODULE' not in os.environ
assert cmd.called


def test_call_command():
"""Should have installed a "django" command."""
subprocess.call(['django'])
37 changes: 37 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[tox]
envlist =
py{27,34,35}-dj18
py{27,34,35}-dj110
py{27,34,35,36}-dj111
py{34,35,36}-dj20
desc

[testenv]
deps =
pytest
pytest-mock
coverage_pth
dj18: Django>=1.8,<1.9
dj110: Django>=1.10,<1.11
dj111: Django>=1.11,<1.12
dj20: Django>=2.0rc1,<2.1
setenv =
COVERAGE_PROCESS_START=.coveragerc
commands = {posargs:pytest}

[testenv:desc]
deps =
docutils
Pygments
commands =
python setup.py check --restructuredtext --strict

[coverage:run]
branch = True
source = django_cmd
parallel = True

[coverage:paths]
source =
src
*/site-packages

0 comments on commit 0547e8e

Please sign in to comment.