Merge "docs: Add docstring information for pegleg.config"

This commit is contained in:
Zuul 2018-10-29 16:48:41 +00:00 committed by Gerrit Code Review
commit 25dfde96e5
4 changed files with 49 additions and 17 deletions

View File

@ -215,7 +215,7 @@ def site(*, site_repository, clone_path, extra_repositories, repo_key,
config.set_site_repo(site_repository)
config.set_clone_path(clone_path)
config.set_extra_repo_store(extra_repositories or [])
config.set_extra_repo_overrides(extra_repositories or [])
config.set_repo_key(repo_key)
config.set_repo_username(repo_username)
@ -341,7 +341,7 @@ def type(*, site_repository, clone_path, extra_repositories, repo_key,
"""
config.set_site_repo(site_repository)
config.set_clone_path(clone_path)
config.set_extra_repo_store(extra_repositories or [])
config.set_extra_repo_overrides(extra_repositories or [])
config.set_repo_key(repo_key)
config.set_repo_username(repo_username)

View File

@ -12,6 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# TODO(felipemonteiro): This pattern below should be swapped out for click
# context passing but will require a somewhat heavy code refactor. See:
# http://click.pocoo.org/5/commands/#nested-handling-and-contexts
try:
if GLOBAL_CONTEXT:
pass
@ -26,81 +30,109 @@ except NameError:
def get_site_repo():
"""Get the primary site repository specified via ``-r`` CLI flag."""
return GLOBAL_CONTEXT['site_repo']
def set_site_repo(r):
"""Set the primary site repository."""
GLOBAL_CONTEXT['site_repo'] = r.rstrip('/') + '/'
def get_clone_path():
"""Get specified clone path (corresponds to ``-p`` CLI flag)."""
return GLOBAL_CONTEXT['clone_path']
def set_clone_path(p):
"""Set specified clone path (corresponds to ``-p`` CLI flag)."""
GLOBAL_CONTEXT['clone_path'] = p
def get_extra_repo_store():
return GLOBAL_CONTEXT.get('extra_repo_store', [])
def get_extra_repo_overrides():
"""Get extra repository overrides specified via ``-e`` CLI flag."""
return GLOBAL_CONTEXT.get('extra_repo_overrides', [])
def set_extra_repo_store(r):
GLOBAL_CONTEXT['extra_repo_store'] = r
def set_extra_repo_overrides(r):
"""Set extra repository overrides.
.. note:: Only CLI should call this.
"""
GLOBAL_CONTEXT['extra_repo_overrides'] = r
def set_repo_key(k):
"""Set additional repository key, like extra metadata to track."""
GLOBAL_CONTEXT['repo_key'] = k
def get_repo_key():
"""Get additional repository key."""
return GLOBAL_CONTEXT.get('repo_key', None)
def set_repo_username(u):
"""Set repo username for SSH auth, corresponds to ``-u`` CLI flag."""
GLOBAL_CONTEXT['repo_username'] = u
def get_repo_username():
"""Get repo username for SSH auth."""
return GLOBAL_CONTEXT.get('repo_username', None)
def set_extra_repo_list(a):
"""Set the extra repository list to be used by ``pegleg.engine``."""
GLOBAL_CONTEXT['extra_repos'] = [r.rstrip('/') + '/' for r in a]
def add_extra_repo(a):
GLOBAL_CONTEXT['extra_repos'].append(a.rstrip('/') + '/')
def get_extra_repo_list():
"""Get the extra repository list.
.. note::
Use this instead of ``get_extra_repo_overrides`` as it handles
both overrides and site-definition.yaml defaults.
"""
return GLOBAL_CONTEXT['extra_repos']
def add_extra_repo(a):
"""Add an extra repo to the extra repository list."""
GLOBAL_CONTEXT['extra_repos'].append(a.rstrip('/') + '/')
def each_extra_repo():
"""Iterate over each extra repo."""
for a in GLOBAL_CONTEXT['extra_repos']:
yield a
def all_repos():
"""Return the primary site repo, in addition to all extra ones."""
repos = [get_site_repo()]
repos.extend(get_extra_repo_list())
return repos
def get_rel_site_path():
"""Get the relative site path name, default is "site"."""
return GLOBAL_CONTEXT.get('site_path', 'site')
def set_rel_site_path(p):
"""Set the relative site path name."""
p = p or 'site'
GLOBAL_CONTEXT['site_path'] = p
def get_rel_type_path():
"""Get the relative type path name, default is "type"."""
return GLOBAL_CONTEXT.get('type_path', 'type')
def set_rel_type_path(p):
"""Set the relative type path name."""
p = p or 'type'
GLOBAL_CONTEXT['type_path'] = p

View File

@ -228,7 +228,7 @@ def _process_repository_overrides(site_def_repos):
"""
# Extra repositories to process.
provided_repo_overrides = config.get_extra_repo_store()
provided_repo_overrides = config.get_extra_repo_overrides()
# Map repository names to the associated URL/revision for cloning.
repo_overrides = {}

View File

@ -181,7 +181,7 @@ def _test_process_repositories(site_repo=None,
elif repo_overrides:
with mock.patch.object(
config,
'get_extra_repo_store',
'get_extra_repo_overrides',
autospec=True,
return_value=list(repo_overrides.values())):
do_test()
@ -372,7 +372,7 @@ def test_process_repositiories_extraneous_user_repo_value(m_log, *_):
# Get rid of REPO_USERNAME through an override.
with mock.patch.object(
config,
'get_extra_repo_store',
'get_extra_repo_overrides',
autospec=True,
return_value=repo_overrides):
_test_process_repositories_inner(
@ -426,7 +426,7 @@ def test_process_repositiories_no_site_def_repos_with_extraneous_overrides(
# Provide repo overrides.
with mock.patch.object(
config,
'get_extra_repo_store',
'get_extra_repo_overrides',
autospec=True,
return_value=repo_overrides):
_test_process_repositories_inner(
@ -466,12 +466,12 @@ def test_process_repositories_without_repositories_key_in_site_definition(
autospec=True,
return_value=TEST_REPOSITORIES)
@mock.patch.object(util.git, 'is_repository', autospec=True, return_value=True)
@mock.patch.object(config, 'get_extra_repo_store', autospec=True)
@mock.patch.object(config, 'get_extra_repo_overrides', autospec=True)
def test_process_extra_repositories_malformed_format_raises_exception(
m_get_extra_repo_store, *_):
m_get_extra_repo_overrides, *_):
# Will fail since it doesn't contain "=".
broken_repo_url = 'broken_url'
m_get_extra_repo_store.return_value = [broken_repo_url]
m_get_extra_repo_overrides.return_value = [broken_repo_url]
error = ("The repository %s must be in the form of "
"name=repoUrl[@revision]" % broken_repo_url)