Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option for skipping checkout of existing repositories #96

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions anybox/recipe/odoo/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ def bool_opt_get(self, name, is_global=False):
taken care of by this recipe instance.
"""
options = self.b_options if is_global else self.options
return options.get(name, '').lower() == 'true'
value = options.get(name, False)
return value.lower() == 'true' if isinstance(value, str) else value

def __init__(self, buildout, name, options):
self.requirements = list(self.requirements)
Expand All @@ -185,12 +186,10 @@ def __init__(self, buildout, name, options):
# GR: would prefer lower() but doing as in 'zc.recipe.egg'
# (later) the standard way for all booleans is to use
# options.query_bool() or get_bool(), but it doesn't lower() at all
self.offline = self.b_options['offline'] == 'true'
self.clean = options.get('clean') == 'true'
clear_locks = options.get('vcs-clear-locks', '').lower()
self.vcs_clear_locks = clear_locks == 'true'
clear_retry = options.get('vcs-clear-retry', '').lower()
self.clear_retry = clear_retry == 'true'
self.offline = self.bool_opt_get('offline', is_global=True)
self.clean = self.bool_opt_get('clean')
self.vcs_clear_locks = self.bool_opt_get('vcs-clear-locks')
self.clear_retry = self.bool_opt_get('vcs-clear-retry')

if self.bool_opt_get(WITH_ODOO_REQUIREMENTS_FILE_OPTION):
logger.debug("%s option: adding 'pip' to the recipe requirements",
Expand Down Expand Up @@ -848,6 +847,7 @@ def retrieve_addons(self):
loc_type, loc_spec, addons_options = source_spec
local_dir = self.make_absolute(local_dir)
options = dict(offline=self.offline,
skip_checkout=self.bool_opt_get('skip-checkout'),
clear_locks=self.vcs_clear_locks,
clean=self.clean)
if loc_type == 'git':
Expand Down Expand Up @@ -1055,7 +1055,8 @@ def retrieve_main_software(self):
if type_spec == 'git':
options['depth'] = options.pop('git-depth', None)

options.update(source[2])
options.update(source[2],
skip_checkout=self.bool_opt_get('skip-checkout'))
if self.clean:
options['clean'] = True
vcs.get_update(type_spec, self.openerp_dir, url, rev,
Expand Down
30 changes: 17 additions & 13 deletions anybox/recipe/odoo/tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ def test_retrieve_addons_vcs(self):
self.assertEquals(
get_vcs_log(), [
(addons_dir, 'http://trunk.example', 'rev',
dict(offline=False, clear_locks=False, clean=False)
dict(offline=False, clear_locks=False, clean=False,
skip_checkout=False,)
)])
self.assertEquals(paths, [addons_dir])

Expand All @@ -90,12 +91,13 @@ def test_retrieve_addons_vcs_2(self):

self.recipe.retrieve_addons()
paths = self.recipe.addons_paths
options = dict(
offline=False, clear_locks=False, clean=False, skip_checkout=False,
)
self.assertEquals(
get_vcs_log(), [
(addons_dir, 'http://trunk.example', 'rev',
dict(offline=False, clear_locks=False, clean=False)),
(other_dir, 'http://other.example', '76',
dict(offline=False, clear_locks=False, clean=False)),
(addons_dir, 'http://trunk.example', 'rev', options),
(other_dir, 'http://other.example', '76', options),
])
self.assertEquals(paths, [addons_dir, other_dir])

Expand Down Expand Up @@ -129,7 +131,8 @@ def test_retrieve_addons_subdir(self):
self.assertEquals(get_vcs_log(), [
(web_dir, 'lp:openerp-web', 'last:1',
dict(offline=False, clear_locks=False, clean=False,
subdir="addons", bzrinit="branch"))
subdir="addons", bzrinit="branch",
skip_checkout=False))
])
self.assertEquals(paths, [web_addons_dir])

Expand All @@ -145,13 +148,13 @@ def test_retrieve_addons_standalone_grouped(self):

self.recipe.retrieve_addons()
paths = self.recipe.addons_paths
options = dict(
offline=False, clear_locks=False, clean=False,
skip_checkout=False, group="grouped",
)
self.assertEquals(get_vcs_log(), [
(addons1_dir, 'lp:my-addons1', 'last:1',
dict(offline=False, clear_locks=False, clean=False,
group="grouped")),
(addons2_dir, 'lp:my-addons2', 'last:1',
dict(offline=False, clear_locks=False, clean=False,
group="grouped"))
(addons1_dir, 'lp:my-addons1', 'last:1', options),
(addons2_dir, 'lp:my-addons2', 'last:1', options),
])
self.assertEquals(paths, [group_dir])

Expand All @@ -178,7 +181,8 @@ def test_retrieve_addons_clear_locks(self):
self.recipe.retrieve_addons()
self.assertEquals(get_vcs_log(), [
(addons_dir, 'lp:my-addons', '-1',
dict(offline=False, clear_locks=True, clean=False))
dict(offline=False, clear_locks=True, clean=False,
skip_checkout=False,))
])

def test_merge_requirements(self):
Expand Down
9 changes: 9 additions & 0 deletions anybox/recipe/odoo/vcs/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import os.path
import shutil
import subprocess
import logging
Expand Down Expand Up @@ -105,6 +106,14 @@ def revert(self, revision):
def __call__(self, revision):
"""Create if needed from remote source, and put it at wanted revision.
"""
if (self.options.get('skip_checkout') and
os.path.exists(self.target_dir)):
logger.info(
"Directory exists and skip-checkout is active. Skipping: %s",
self.target_dir,
)
return self

if self.options.get('clean'):
self.clean()

Expand Down
27 changes: 27 additions & 0 deletions anybox/recipe/odoo/vcs/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""

import os
import os.path
import subprocess

from zc.buildout import UserError
Expand Down Expand Up @@ -36,6 +37,32 @@ def test_str(self):
self.assertEqual(str(repo), "BaseRepo at '/some/path' "
"(remote='http://some/url')")

def test_skip_checkout(self):
existing_dir = self.dst_dir
non_existing_dir = os.path.join(existing_dir + 'foo')

# Repos should try checkout when not called with skip_checkout
revision = "1.0"
self.assertRaises(
NotImplementedError,
BaseRepo(existing_dir, 'http://some/url'),
revision,
)
# Specially when the target doesn't exist
self.assertRaises(
NotImplementedError,
BaseRepo(non_existing_dir, 'http://some/url'),
revision,
)
# But also when called with skip_checkout and the target doesn't exist
self.assertRaises(
NotImplementedError,
BaseRepo(non_existing_dir, 'http://some/url', skip_checkout=True),
revision,
)
# But not when it exists
BaseRepo(existing_dir, 'http://some/url', skip_checkout=True)(revision)

def test_unknown(self):
self.assertRaises(UserError,
get_update, 'unknown', '', '', 'default')
Expand Down
23 changes: 23 additions & 0 deletions doc/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,29 @@ Currently only merges on bzr and git repositories are supported

.. _eggs:

skip-checkout
-------------
This option causes the checkout of each repository specified under
:ref:`addons` or :ref:`version` to be skipped if it already exists on the
filesystem.

It's useful during development when you already have a working buildout with
many addons and would like to skip the part where each addon is checked out
again.

For examples, if you want to:

* just rebuild ``odoo.cfg`` with newer settings.

* add another python package in ``eggs =``

* temporarily work on an addon in a branch that is different than the one
specified in the ``addons`` setting but wanting to re-run buildout for one of the above reasons.

This is mostly to be used from the command line, like::

bin/buildout odoo:skip-checkout=true

eggs
----
This option behaves like the identically named one of the most common
Expand Down