Merge lp:~ricardokirkner/django-configglue/setup-housekeeping into lp:django-configglue

Proposed by Ricardo Kirkner
Status: Merged
Approved by: Ricardo Kirkner
Approved revision: 58
Merged at revision: 54
Proposed branch: lp:~ricardokirkner/django-configglue/setup-housekeeping
Merge into: lp:django-configglue
Diff against target: 285 lines (+136/-84)
8 files modified
.bzrignore (+1/-0)
MANIFEST.in (+1/-1)
django_configglue/__init__.py (+7/-73)
django_configglue/management/__init__.py (+75/-3)
django_configglue/tests/test_configglue.py (+1/-1)
setup.py (+6/-3)
setup_helpers.py (+41/-0)
tox (+4/-3)
To merge this branch: bzr merge lp:~ricardokirkner/django-configglue/setup-housekeeping
Reviewer Review Type Date Requested Status
Canonical ISD hackers Pending
Review via email: mp+67459@code.launchpad.net

Commit message

added __version__ string

Description of the change

Some improvement to the setup.py script

move the management utility monkeypatch out of the way
add __version__ string
other housekeeping tasks

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '.bzrignore'
2--- .bzrignore 2011-01-10 21:44:26 +0000
3+++ .bzrignore 2011-07-10 15:32:50 +0000
4@@ -1,2 +1,3 @@
5 doc/_build
6 django_configglue.egg-info
7+*.pyc
8
9=== renamed file 'LICENSE' => 'LICENSE.txt'
10=== modified file 'MANIFEST.in'
11--- MANIFEST.in 2010-08-11 17:00:02 +0000
12+++ MANIFEST.in 2011-07-10 15:32:50 +0000
13@@ -1,4 +1,4 @@
14-include LICENSE
15+include *.py *.txt
16 graft testproject
17 graft third-party
18 global-exclude *.pyc
19
20=== renamed file 'README' => 'README.txt'
21=== modified file 'django_configglue/__init__.py'
22--- django_configglue/__init__.py 2011-04-09 22:38:14 +0000
23+++ django_configglue/__init__.py 2011-07-10 15:32:50 +0000
24@@ -1,73 +1,7 @@
25-# Copyright 2010 Canonical Ltd.
26-# Copyright Django Software Foundation and individual contributors
27-# This software is licensed under the
28-# GNU Lesser General Public License version 3 (see the file LICENSE)
29-# except where third-party/django/LICENSE applies.
30-
31-import sys
32-
33-import django
34-import django.core.management
35-from configglue.pyschema.glue import schemaconfigglue
36-from django.core.management import ManagementUtility, LaxOptionParser
37-from django.core.management.base import BaseCommand, handle_default_options
38-from django.conf import settings
39-from django_configglue import utils
40-
41-
42-class GlueManagementUtility(ManagementUtility):
43- # This function was mostly taken from the django project.
44- # Please see the license file in the third-party/django directory.
45- def execute(self):
46- """
47- Given the command-line arguments, this figures out which subcommand is
48- being run, creates a parser appropriate to that command, and runs it.
49- """
50- # Preprocess options to extract --settings and --pythonpath.
51- # These options could affect the commands that are available, so they
52- # must be processed early.
53- parser = LaxOptionParser(usage="%prog subcommand [options] [args]",
54- version=django.get_version(),
55- option_list=BaseCommand.option_list)
56- try:
57- configglue_parser = settings.__CONFIGGLUE_PARSER__
58- parser, options, args = schemaconfigglue(configglue_parser,
59- op=parser, argv=self.argv)
60- # remove schema-related options from the argv list
61- self.argv = args
62- utils.update_settings(configglue_parser, settings)
63- except AttributeError:
64- # no __CONFIGGLUE_PARSER__ found, fall back to standard django
65- # options parsing
66- options, args = parser.parse_args(self.argv)
67- handle_default_options(options)
68- except:
69- # Ignore any option errors at this point.
70- args = self.argv
71-
72- try:
73- subcommand = self.argv[1]
74- except IndexError:
75- sys.stderr.write("Type '%s help' for usage.\n" % self.prog_name)
76- sys.exit(1)
77-
78- if subcommand == 'help':
79- if len(args) > 2:
80- self.fetch_command(args[2]).print_help(self.prog_name, args[2])
81- else:
82- parser.print_lax_help()
83- sys.stderr.write(self.main_help_text() + '\n')
84- sys.exit(1)
85- # Special-cases: We want 'django-admin.py --version' and
86- # 'django-admin.py --help' to work, for backwards compatibility.
87- elif self.argv[1:] == ['--version']:
88- # LaxOptionParser already takes care of printing the version.
89- pass
90- elif self.argv[1:] == ['--help']:
91- parser.print_lax_help()
92- sys.stderr.write(self.main_help_text() + '\n')
93- else:
94- self.fetch_command(subcommand).run_from_argv(self.argv)
95-
96-# We're going to go ahead and use our own ManagementUtility here, thank you.
97-django.core.management.ManagementUtility = GlueManagementUtility
98+# Copyright 2010 Canonical Ltd. This software is licensed under the
99+# GNU Lesser General Public License version 3 (see the file LICENSE).
100+
101+__version__ = '0.5'
102+
103+# monkey-patch django's management utility
104+from . import management
105
106=== modified file 'django_configglue/management/__init__.py'
107--- django_configglue/management/__init__.py 2010-07-23 19:27:51 +0000
108+++ django_configglue/management/__init__.py 2011-07-10 15:32:50 +0000
109@@ -1,3 +1,75 @@
110-# Copyright 2010 Canonical Ltd. This software is licensed under the
111-# GNU Lesser General Public License version 3 (see the file LICENSE).
112-
113+# Copyright 2010 Canonical Ltd.
114+# Copyright Django Software Foundation and individual contributors
115+# This software is licensed under the
116+# GNU Lesser General Public License version 3 (see the file LICENSE)
117+# except where third-party/django/LICENSE applies.
118+
119+
120+import sys
121+
122+import django
123+import django.core.management
124+from configglue.pyschema.glue import schemaconfigglue
125+from django.core.management import ManagementUtility, LaxOptionParser
126+from django.core.management.base import BaseCommand, handle_default_options
127+from django.conf import settings
128+from django_configglue import utils
129+
130+
131+class GlueManagementUtility(ManagementUtility):
132+ # This function was mostly taken from the django project.
133+ # Please see the license file in the third-party/django directory.
134+ def execute(self):
135+ """
136+ Given the command-line arguments, this figures out which subcommand is
137+ being run, creates a parser appropriate to that command, and runs it.
138+ """
139+ # Preprocess options to extract --settings and --pythonpath.
140+ # These options could affect the commands that are available, so they
141+ # must be processed early.
142+ parser = LaxOptionParser(usage="%prog subcommand [options] [args]",
143+ version=django.get_version(),
144+ option_list=BaseCommand.option_list)
145+ try:
146+ configglue_parser = settings.__CONFIGGLUE_PARSER__
147+ parser, options, args = schemaconfigglue(configglue_parser,
148+ op=parser, argv=self.argv)
149+ # remove schema-related options from the argv list
150+ self.argv = args
151+ utils.update_settings(configglue_parser, settings)
152+ except AttributeError:
153+ # no __CONFIGGLUE_PARSER__ found, fall back to standard django
154+ # options parsing
155+ options, args = parser.parse_args(self.argv)
156+ handle_default_options(options)
157+ except:
158+ # Ignore any option errors at this point.
159+ args = self.argv
160+
161+ try:
162+ subcommand = self.argv[1]
163+ except IndexError:
164+ sys.stderr.write("Type '%s help' for usage.\n" % self.prog_name)
165+ sys.exit(1)
166+
167+ if subcommand == 'help':
168+ if len(args) > 2:
169+ self.fetch_command(args[2]).print_help(self.prog_name, args[2])
170+ else:
171+ parser.print_lax_help()
172+ sys.stderr.write(self.main_help_text() + '\n')
173+ sys.exit(1)
174+ # Special-cases: We want 'django-admin.py --version' and
175+ # 'django-admin.py --help' to work, for backwards compatibility.
176+ elif self.argv[1:] == ['--version']:
177+ # LaxOptionParser already takes care of printing the version.
178+ pass
179+ elif self.argv[1:] == ['--help']:
180+ parser.print_lax_help()
181+ sys.stderr.write(self.main_help_text() + '\n')
182+ else:
183+ self.fetch_command(subcommand).run_from_argv(self.argv)
184+
185+
186+# We're going to go ahead and use our own ManagementUtility here, thank you.
187+django.core.management.ManagementUtility = GlueManagementUtility
188
189=== modified file 'django_configglue/tests/test_configglue.py'
190--- django_configglue/tests/test_configglue.py 2011-06-22 23:06:50 +0000
191+++ django_configglue/tests/test_configglue.py 2011-07-10 15:32:50 +0000
192@@ -20,7 +20,7 @@
193 from django.conf import settings
194 from mock import patch
195
196-from django_configglue import GlueManagementUtility
197+from django_configglue.management import GlueManagementUtility
198 from django_configglue.utils import (
199 SETTINGS_ENCODING,
200 configglue,
201
202=== modified file 'setup.py'
203--- setup.py 2011-06-24 18:18:25 +0000
204+++ setup.py 2011-07-10 15:32:50 +0000
205@@ -3,12 +3,15 @@
206
207 from setuptools import setup, find_packages
208
209+from setup_helpers import get_version
210+
211+
212 setup(
213 # metadata
214 name='django-configglue',
215- version='0.5',
216- author='Canonical ISD Hackers',
217- author_email='canonical-isd@lists.launchpad.net',
218+ version=get_version('django_configglue/__init__.py'),
219+ author='Ricardo Kirkner',
220+ author_email='ricardo.kirkner@canonical.com',
221 description='Django commands for managing configglue generated settings',
222 long_description='Django commands for managing configglue generated '
223 'settings from the command line.\n'
224
225=== added file 'setup_helpers.py'
226--- setup_helpers.py 1970-01-01 00:00:00 +0000
227+++ setup_helpers.py 2011-07-10 15:32:50 +0000
228@@ -0,0 +1,41 @@
229+# Copyright 2010-2011 Canonical Ltd. This software is licensed under the
230+# GNU Lesser General Public License version 3 (see the file LICENSE).
231+# Copyright 2009-2011 by Barry A. Warsaw
232+
233+import re
234+
235+
236+DEFAULT_VERSION_RE = re.compile(r'(?P<version>\d+\.\d(?:\.\d+)?)')
237+
238+
239+def get_version(filename, pattern=None):
240+ """Extract the __version__ from a file without importing it.
241+
242+ While you could get the __version__ by importing the module, the very act
243+ of importing can cause unintended consequences. For example, Distribute's
244+ automatic 2to3 support will break. Instead, this searches the file for a
245+ line that starts with __version__, and extract the version number by
246+ regular expression matching.
247+
248+ By default, two or three dot-separated digits are recognized, but by
249+ passing a pattern parameter, you can recognize just about anything. Use
250+ the `version` group name to specify the match group.
251+
252+ :param filename: The name of the file to search.
253+ :type filename: string
254+ :param pattern: Optional alternative regular expression pattern to use.
255+ :type pattern: string
256+ :return: The version that was extracted.
257+ :rtype: string
258+ """
259+ if pattern is None:
260+ cre = DEFAULT_VERSION_RE
261+ else:
262+ cre = re.compile(pattern)
263+ with open(filename) as fp:
264+ for line in fp:
265+ if line.startswith('__version__'):
266+ mo = cre.search(line)
267+ assert mo, 'No valid __version__ string found'
268+ return mo.group('version')
269+ raise AssertionError('No __version__ assignment found')
270
271=== modified file 'tox'
272--- tox 2011-04-09 21:52:09 +0000
273+++ tox 2011-07-10 15:32:50 +0000
274@@ -1,6 +1,7 @@
275 #!/usr/bin/env python
276-import urllib
277-url = "https://pytox.googlecode.com/hg/toxbootstrap.py"
278+import urllib, os
279+url = "https://bitbucket.org/hpk42/tox/raw/default/toxbootstrap.py"
280+#os.environ['USETOXDEV']="1" # use tox dev version
281 d = dict(__file__='toxbootstrap.py')
282 exec urllib.urlopen(url).read() in d
283-d['cmdline'](['--recreate'])
284\ No newline at end of file
285+d['cmdline'](['--recreate'])

Subscribers

People subscribed via source and target branches

to all changes: