Merge lp:~johnpaulett/djangorecipe/relative-paths into lp:~roland-micite/djangorecipe/dev

Proposed by John Paulett
Status: Needs review
Proposed branch: lp:~johnpaulett/djangorecipe/relative-paths
Merge into: lp:~roland-micite/djangorecipe/dev
Diff against target: 95 lines (+54/-0)
2 files modified
src/djangorecipe/recipe.py (+13/-0)
src/djangorecipe/tests.py (+41/-0)
To merge this branch: bzr merge lp:~johnpaulett/djangorecipe/relative-paths
Reviewer Review Type Date Requested Status
roland Pending
Review via email: mp+65888@code.launchpad.net

Description of the change

Thanks for creating djangorecipe--it has been very useful!

I have a need (related to packaging) to make use of buildout's relative-paths option, so that the manage and test file do not have absolute paths in them.

I made the appropriate changes and tested it in my project.

Please let me know if you see any issues. I would love to get this in the next release of djangorecipe.

To post a comment you must log in.
Revision history for this message
roland (roland-micite) wrote :

Thank you for this patch.
Could you write unittests to go with it?

113. By John Paulett

Add tests for relative-paths support.

Revision history for this message
John Paulett (johnpaulett) wrote :

Definitely! Here is a first past with 2 additional tests:
http://bazaar.launchpad.net/~johnpaulett/djangorecipe/relative-paths/revision/113

This is my first time digging into buildout code, so the tests may not
be optimal. I wanted to assert that the sys.path entries are
modified, but I was having a hard time getting and buildout.develop or
buildout.eggs to show up (probably because I am not doing a full
recipe.install()). Therefore, I am merely testing for the definition
of the `base` variable that buildout will create when
relative-paths=True.

On Sun, Jun 26, 2011 at 8:31 AM, roland <email address hidden> wrote:
> Thank you for this patch.
> Could you write unittests to go with it?
>
>
> --
> https://code.launchpad.net/~johnpaulett/djangorecipe/relative-paths/+merge/65888
> You are the owner of lp:~johnpaulett/djangorecipe/relative-paths.
>

Unmerged revisions

113. By John Paulett

Add tests for relative-paths support.

112. By John Paulett

Add support for relative-paths (modeled on zc.recipe.egg).

relative-paths = True allows the buildout directory to be safely moved,
since the manage and test scripts have relative paths, not absolute paths.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/djangorecipe/recipe.py'
2--- src/djangorecipe/recipe.py 2011-06-07 14:09:53 +0000
3+++ src/djangorecipe/recipe.py 2011-06-26 15:55:54 +0000
4@@ -45,6 +45,16 @@
5 options.setdefault('wsgilog', '')
6 options.setdefault('logfile', '')
7
8+ # respect relative-paths (from zc.recipe.egg)
9+ relative_paths = options.get(
10+ 'relative-paths', buildout['buildout'].get('relative-paths', 'false'))
11+ if relative_paths == 'true':
12+ options['buildout-directory'] = buildout['buildout']['directory']
13+ self._relative_paths = options['buildout-directory']
14+ else:
15+ self._relative_paths = ''
16+ assert relative_paths == 'false'
17+
18 def install(self):
19 location = self.options['location']
20 base_dir = self.buildout['buildout']['directory']
21@@ -84,6 +94,7 @@
22 'djangorecipe.manage', 'main')],
23 ws, self.options['executable'], self.options['bin-directory'],
24 extra_paths=extra_paths,
25+ relative_paths=self._relative_paths,
26 arguments="'%s.%s'" % (project,
27 self.options['settings']))
28
29@@ -97,6 +108,7 @@
30 working_set, self.options['executable'],
31 self.options['bin-directory'],
32 extra_paths=extra_paths,
33+ relative_paths=self._relative_paths,
34 arguments="'%s.%s', %s" % (
35 self.options['project'],
36 self.options['settings'],
37@@ -169,6 +181,7 @@
38 self.options['executable'],
39 self.options['bin-directory'],
40 extra_paths=extra_paths,
41+ relative_paths=self._relative_paths,
42 arguments="'%s.%s', logfile='%s'" % (
43 project, self.options['settings'],
44 self.options.get('logfile'))))
45
46=== modified file 'src/djangorecipe/tests.py'
47--- src/djangorecipe/tests.py 2011-06-07 14:09:53 +0000
48+++ src/djangorecipe/tests.py 2011-06-26 15:55:54 +0000
49@@ -451,6 +451,47 @@
50 'python': 'py5k', 'wsgi': 'true'}
51 self.assertRaises(UserError, Recipe, *('buildout', 'test', options))
52
53+ def test_relative_paths_default(self):
54+ self.recipe.options['wsgi'] = 'true'
55+
56+ self.recipe.make_scripts([], [])
57+ self.recipe.create_manage_script([], [])
58+
59+ manage = os.path.join(self.bin_dir, 'django')
60+ wsgi_script = os.path.join(self.bin_dir, 'django.wsgi')
61+
62+ expected = base = 'base = os.path.dirname(os.path.abspath(os.path.realpath(__file__)))'
63+ self.assertFalse(expected in open(manage).read())
64+ self.assertFalse(expected in open(wsgi_script).read())
65+
66+ def test_relative_paths_true(self):
67+ recipe = Recipe({
68+ 'buildout': {
69+ 'eggs-directory': self.eggs_dir,
70+ 'develop-eggs-directory': self.develop_eggs_dir,
71+ 'python': 'python-version',
72+ 'bin-directory': self.bin_dir,
73+ 'parts-directory': self.parts_dir,
74+ 'directory': self.buildout_dir,
75+ 'find-links': '',
76+ 'allow-hosts': '',
77+ 'develop': '.',
78+ 'relative-paths': 'true'
79+ },
80+ 'python-version': {'executable': sys.executable}},
81+ 'django',
82+ {'recipe': 'djangorecipe',
83+ 'wsgi': 'true'})
84+ recipe.make_scripts([], [])
85+ recipe.create_manage_script([], [])
86+
87+ manage = os.path.join(self.bin_dir, 'django')
88+ wsgi_script = os.path.join(self.bin_dir, 'django.wsgi')
89+
90+ expected = base = 'base = os.path.dirname(os.path.abspath(os.path.realpath(__file__)))'
91+ self.assertTrue(expected in open(manage).read())
92+ self.assertTrue(expected in open(wsgi_script).read())
93+
94
95 class ScriptTestCase(unittest.TestCase):
96

Subscribers

People subscribed via source and target branches

to all changes: