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
=== modified file 'src/djangorecipe/recipe.py'
--- src/djangorecipe/recipe.py 2011-06-07 14:09:53 +0000
+++ src/djangorecipe/recipe.py 2011-06-26 15:55:54 +0000
@@ -45,6 +45,16 @@
45 options.setdefault('wsgilog', '')45 options.setdefault('wsgilog', '')
46 options.setdefault('logfile', '')46 options.setdefault('logfile', '')
4747
48 # respect relative-paths (from zc.recipe.egg)
49 relative_paths = options.get(
50 'relative-paths', buildout['buildout'].get('relative-paths', 'false'))
51 if relative_paths == 'true':
52 options['buildout-directory'] = buildout['buildout']['directory']
53 self._relative_paths = options['buildout-directory']
54 else:
55 self._relative_paths = ''
56 assert relative_paths == 'false'
57
48 def install(self):58 def install(self):
49 location = self.options['location']59 location = self.options['location']
50 base_dir = self.buildout['buildout']['directory']60 base_dir = self.buildout['buildout']['directory']
@@ -84,6 +94,7 @@
84 'djangorecipe.manage', 'main')],94 'djangorecipe.manage', 'main')],
85 ws, self.options['executable'], self.options['bin-directory'],95 ws, self.options['executable'], self.options['bin-directory'],
86 extra_paths=extra_paths,96 extra_paths=extra_paths,
97 relative_paths=self._relative_paths,
87 arguments="'%s.%s'" % (project,98 arguments="'%s.%s'" % (project,
88 self.options['settings']))99 self.options['settings']))
89100
@@ -97,6 +108,7 @@
97 working_set, self.options['executable'],108 working_set, self.options['executable'],
98 self.options['bin-directory'],109 self.options['bin-directory'],
99 extra_paths=extra_paths,110 extra_paths=extra_paths,
111 relative_paths=self._relative_paths,
100 arguments="'%s.%s', %s" % (112 arguments="'%s.%s', %s" % (
101 self.options['project'],113 self.options['project'],
102 self.options['settings'],114 self.options['settings'],
@@ -169,6 +181,7 @@
169 self.options['executable'],181 self.options['executable'],
170 self.options['bin-directory'],182 self.options['bin-directory'],
171 extra_paths=extra_paths,183 extra_paths=extra_paths,
184 relative_paths=self._relative_paths,
172 arguments="'%s.%s', logfile='%s'" % (185 arguments="'%s.%s', logfile='%s'" % (
173 project, self.options['settings'],186 project, self.options['settings'],
174 self.options.get('logfile'))))187 self.options.get('logfile'))))
175188
=== modified file 'src/djangorecipe/tests.py'
--- src/djangorecipe/tests.py 2011-06-07 14:09:53 +0000
+++ src/djangorecipe/tests.py 2011-06-26 15:55:54 +0000
@@ -451,6 +451,47 @@
451 'python': 'py5k', 'wsgi': 'true'}451 'python': 'py5k', 'wsgi': 'true'}
452 self.assertRaises(UserError, Recipe, *('buildout', 'test', options))452 self.assertRaises(UserError, Recipe, *('buildout', 'test', options))
453453
454 def test_relative_paths_default(self):
455 self.recipe.options['wsgi'] = 'true'
456
457 self.recipe.make_scripts([], [])
458 self.recipe.create_manage_script([], [])
459
460 manage = os.path.join(self.bin_dir, 'django')
461 wsgi_script = os.path.join(self.bin_dir, 'django.wsgi')
462
463 expected = base = 'base = os.path.dirname(os.path.abspath(os.path.realpath(__file__)))'
464 self.assertFalse(expected in open(manage).read())
465 self.assertFalse(expected in open(wsgi_script).read())
466
467 def test_relative_paths_true(self):
468 recipe = Recipe({
469 'buildout': {
470 'eggs-directory': self.eggs_dir,
471 'develop-eggs-directory': self.develop_eggs_dir,
472 'python': 'python-version',
473 'bin-directory': self.bin_dir,
474 'parts-directory': self.parts_dir,
475 'directory': self.buildout_dir,
476 'find-links': '',
477 'allow-hosts': '',
478 'develop': '.',
479 'relative-paths': 'true'
480 },
481 'python-version': {'executable': sys.executable}},
482 'django',
483 {'recipe': 'djangorecipe',
484 'wsgi': 'true'})
485 recipe.make_scripts([], [])
486 recipe.create_manage_script([], [])
487
488 manage = os.path.join(self.bin_dir, 'django')
489 wsgi_script = os.path.join(self.bin_dir, 'django.wsgi')
490
491 expected = base = 'base = os.path.dirname(os.path.abspath(os.path.realpath(__file__)))'
492 self.assertTrue(expected in open(manage).read())
493 self.assertTrue(expected in open(wsgi_script).read())
494
454495
455class ScriptTestCase(unittest.TestCase):496class ScriptTestCase(unittest.TestCase):
456497

Subscribers

People subscribed via source and target branches

to all changes: