Add some doctests for gitclone recipe

parent f869cb59
......@@ -249,9 +249,11 @@ the full path in cpan like in ::
Notes
=====
Currently, the modules will be installed in site-perl directory. Location of this
Currently, the modules will be installed in site-perl directory. Location of this
directory changes depending on the perl installation.
****************************
slapos.recipe.build:gitclone
****************************
......@@ -262,20 +264,36 @@ Supports slapos.libnetworkcache if present.
Examples
********
Those examples use slapos.recipe.build repository as an example.
Simple clone
------------
Only `url` parameter is required. For each buildout run,
Only `repository` parameter is required. For each buildout run,
the recipe will pick up the latest commit on the remote master branch::
[buildout]
parts = git-clone
[git-clone]
recipe = slapos.recipe.build:gitclone
repository = http://example.net/example.git/
>>> write(sample_buildout, 'buildout.cfg',
... """
... [buildout]
... parts = git-clone
...
... [git-clone]
... recipe = slapos.recipe.build:gitclone
... repository = http://git.erp5.org/repos/slapos.recipe.build.git
... """)
This will clone the git repository in `parts/git-clone` directory.
Then let's run the buildout::
>>> print system(buildout)
Installing git-clone.
Cloning into '/sample-buildout/parts/git-clone'...
Let's take a look at the buildout parts directory now::
>>> ls(sample_buildout, 'parts')
d buildout
d git-clone
Specific branch
---------------
......@@ -283,13 +301,35 @@ Specific branch
You can specify a specific branch using `branch` option. For each
run it will take the latest commit on this remote branch::
[buildout]
parts = git-clone
>>> write(sample_buildout, 'buildout.cfg',
... """
... [buildout]
... parts = git-clone
...
... [git-clone]
... recipe = slapos.recipe.build:gitclone
... repository = http://git.erp5.org/repos/slapos.recipe.build.git
... branch = build
... """)
[git-clone]
recipe = slapos.recipe.build:gitclone
repository = http://example.net/example.git/
branch = testing
Then let's run the buildout::
>>> print system(buildout)
Uninstalling git-clone.
Installing git-clone.
Cloning into '/sample-buildout/parts/git-clone'...
Let's take a look at the buildout parts directory now::
>>> ls(sample_buildout, 'parts')
d buildout
d git-clone
And let's see that current branch is "build"::
>>> import subprocess
>>> cd('parts', 'git-clone')
>>> subprocess.check_output(['git', 'branch'])
'* build\n'
Specific revision
-----------------
......@@ -297,13 +337,37 @@ Specific revision
You can specify a specific commit hash or tag using `revision` option.
This option is not compatible with "branch" option::
[buildout]
parts = git-clone
>>> cd(sample_buildout)
>>> write(sample_buildout, 'buildout.cfg',
... """
... [buildout]
... parts = git-clone
...
... [git-clone]
... recipe = slapos.recipe.build:gitclone
... repository = http://git.erp5.org/repos/slapos.recipe.build.git
... revision = 2566127
... """)
[git-clone]
recipe = slapos.recipe.build:gitclone
repository = http://example.net/example.git/
revision = 0123456789abcdef
Then let's run the buildout::
>>> print system(buildout)
Uninstalling git-clone.
Installing git-clone.
Cloning into '/sample-buildout/parts/git-clone'...
Let's take a look at the buildout parts directory now::
>>> ls(sample_buildout, 'parts')
d buildout
d git-clone
And let's see that current branch is "gitclone"::
>>> import subprocess
>>> cd(sample_buildout, 'parts', 'git-clone')
>>> subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD'])
'2566127\n'
Specific git binary
-------------------
......@@ -361,7 +425,7 @@ Here is example to install one or several modules::
modules =
colors
express
# Optional argument specifying perl buildout part, if existing.
# If specified, recipe will use the perl installed by buildout.
# If not specified, will take the globally available perl executable.
......
......@@ -26,6 +26,11 @@ setup(name=name,
'zc.buildout', # plays with buildout
'slapos.libnetworkcache>=0.13.1', # Uses helper new in this version
],
extras_require={
'test' : ['zope.testing'],
},
tests_require = ['zope.testing'],
test_suite = '%s.tests.test_suite' % name,
zip_safe=True,
entry_points={
'zc.buildout': [
......
......@@ -57,6 +57,9 @@ def upload_network_cached(path, name, revision, networkcache_options):
"""
Creates uploads repository to cache.
"""
if not (LIBNETWORKCACHE_ENABLED and networkcache_options.get(
'shacache-cert-file')):
return False
try:
print 'Uploading git repository to cache...'
metadata_dict = {
......@@ -126,8 +129,7 @@ class Recipe(object):
if options.get('develop') in TRUE_VALUES:
self.develop = True
# XXX clean
self.networkcache = buildout.get('networkcache')
self.networkcache = buildout.get('networkcache', {})
# Check if input is correct
if not self.repository:
......@@ -175,7 +177,7 @@ class Recipe(object):
except CalledProcessError:
print ("Unable to download from git repository. Trying from network "
"cache...")
if not download_network_cached(self.location, self.name, self.revision,
if not download_network_cached(self.location, self.name, self.revision,
self.networkcache):
if os.path.exists(self.location):
shutil.rmtree(self.location)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment