Browse Source

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

Zuul 5 months ago
parent
commit
25dfde96e5
4 changed files with 48 additions and 16 deletions
  1. 2
    2
      pegleg/cli.py
  2. 39
    7
      pegleg/config.py
  3. 1
    1
      pegleg/engine/repository.py
  4. 6
    6
      tests/unit/engine/test_site_repository.py

+ 2
- 2
pegleg/cli.py View File

@@ -215,7 +215,7 @@ def site(*, site_repository, clone_path, extra_repositories, repo_key,
215 215
 
216 216
     config.set_site_repo(site_repository)
217 217
     config.set_clone_path(clone_path)
218
-    config.set_extra_repo_store(extra_repositories or [])
218
+    config.set_extra_repo_overrides(extra_repositories or [])
219 219
     config.set_repo_key(repo_key)
220 220
     config.set_repo_username(repo_username)
221 221
 
@@ -341,7 +341,7 @@ def type(*, site_repository, clone_path, extra_repositories, repo_key,
341 341
     """
342 342
     config.set_site_repo(site_repository)
343 343
     config.set_clone_path(clone_path)
344
-    config.set_extra_repo_store(extra_repositories or [])
344
+    config.set_extra_repo_overrides(extra_repositories or [])
345 345
     config.set_repo_key(repo_key)
346 346
     config.set_repo_username(repo_username)
347 347
 

+ 39
- 7
pegleg/config.py View File

@@ -12,6 +12,10 @@
12 12
 # See the License for the specific language governing permissions and
13 13
 # limitations under the License.
14 14
 
15
+# TODO(felipemonteiro): This pattern below should be swapped out for click
16
+# context passing but will require a somewhat heavy code refactor. See:
17
+# http://click.pocoo.org/5/commands/#nested-handling-and-contexts
18
+
15 19
 try:
16 20
     if GLOBAL_CONTEXT:
17 21
         pass
@@ -26,81 +30,109 @@ except NameError:
26 30
 
27 31
 
28 32
 def get_site_repo():
33
+    """Get the primary site repository specified via ``-r`` CLI flag."""
29 34
     return GLOBAL_CONTEXT['site_repo']
30 35
 
31 36
 
32 37
 def set_site_repo(r):
38
+    """Set the primary site repository."""
33 39
     GLOBAL_CONTEXT['site_repo'] = r.rstrip('/') + '/'
34 40
 
35 41
 
36 42
 def get_clone_path():
43
+    """Get specified clone path (corresponds to ``-p`` CLI flag)."""
37 44
     return GLOBAL_CONTEXT['clone_path']
38 45
 
39 46
 
40 47
 def set_clone_path(p):
48
+    """Set specified clone path (corresponds to ``-p`` CLI flag)."""
41 49
     GLOBAL_CONTEXT['clone_path'] = p
42 50
 
43 51
 
44
-def get_extra_repo_store():
45
-    return GLOBAL_CONTEXT.get('extra_repo_store', [])
52
+def get_extra_repo_overrides():
53
+    """Get extra repository overrides specified via ``-e`` CLI flag."""
54
+    return GLOBAL_CONTEXT.get('extra_repo_overrides', [])
55
+
46 56
 
57
+def set_extra_repo_overrides(r):
58
+    """Set extra repository overrides.
47 59
 
48
-def set_extra_repo_store(r):
49
-    GLOBAL_CONTEXT['extra_repo_store'] = r
60
+    .. note:: Only CLI should call this.
61
+    """
62
+    GLOBAL_CONTEXT['extra_repo_overrides'] = r
50 63
 
51 64
 
52 65
 def set_repo_key(k):
66
+    """Set additional repository key, like extra metadata to track."""
53 67
     GLOBAL_CONTEXT['repo_key'] = k
54 68
 
55 69
 
56 70
 def get_repo_key():
71
+    """Get additional repository key."""
57 72
     return GLOBAL_CONTEXT.get('repo_key', None)
58 73
 
59 74
 
60 75
 def set_repo_username(u):
76
+    """Set repo username for SSH auth, corresponds to ``-u`` CLI flag."""
61 77
     GLOBAL_CONTEXT['repo_username'] = u
62 78
 
63 79
 
64 80
 def get_repo_username():
81
+    """Get repo username for SSH auth."""
65 82
     return GLOBAL_CONTEXT.get('repo_username', None)
66 83
 
67 84
 
68 85
 def set_extra_repo_list(a):
86
+    """Set the extra repository list to be used by ``pegleg.engine``."""
69 87
     GLOBAL_CONTEXT['extra_repos'] = [r.rstrip('/') + '/' for r in a]
70 88
 
71 89
 
72
-def add_extra_repo(a):
73
-    GLOBAL_CONTEXT['extra_repos'].append(a.rstrip('/') + '/')
90
+def get_extra_repo_list():
91
+    """Get the extra repository list.
74 92
 
93
+    .. note::
75 94
 
76
-def get_extra_repo_list():
95
+        Use this instead of ``get_extra_repo_overrides`` as it handles
96
+        both overrides and site-definition.yaml defaults.
97
+    """
77 98
     return GLOBAL_CONTEXT['extra_repos']
78 99
 
79 100
 
101
+def add_extra_repo(a):
102
+    """Add an extra repo to the extra repository list."""
103
+    GLOBAL_CONTEXT['extra_repos'].append(a.rstrip('/') + '/')
104
+
105
+
80 106
 def each_extra_repo():
107
+    """Iterate over each extra repo."""
81 108
     for a in GLOBAL_CONTEXT['extra_repos']:
82 109
         yield a
83 110
 
84 111
 
85 112
 def all_repos():
113
+    """Return the primary site repo, in addition to all extra ones."""
86 114
     repos = [get_site_repo()]
87 115
     repos.extend(get_extra_repo_list())
88 116
     return repos
89 117
 
90 118
 
91 119
 def get_rel_site_path():
120
+    """Get the relative site path name, default is "site"."""
92 121
     return GLOBAL_CONTEXT.get('site_path', 'site')
93 122
 
94 123
 
95 124
 def set_rel_site_path(p):
125
+    """Set the relative site path name."""
96 126
     p = p or 'site'
97 127
     GLOBAL_CONTEXT['site_path'] = p
98 128
 
99 129
 
100 130
 def get_rel_type_path():
131
+    """Get the relative type path name, default is "type"."""
101 132
     return GLOBAL_CONTEXT.get('type_path', 'type')
102 133
 
103 134
 
104 135
 def set_rel_type_path(p):
136
+    """Set the relative type path name."""
105 137
     p = p or 'type'
106 138
     GLOBAL_CONTEXT['type_path'] = p

+ 1
- 1
pegleg/engine/repository.py View File

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

+ 6
- 6
tests/unit/engine/test_site_repository.py View File

@@ -181,7 +181,7 @@ def _test_process_repositories(site_repo=None,
181 181
     elif repo_overrides:
182 182
         with mock.patch.object(
183 183
                 config,
184
-                'get_extra_repo_store',
184
+                'get_extra_repo_overrides',
185 185
                 autospec=True,
186 186
                 return_value=list(repo_overrides.values())):
187 187
             do_test()
@@ -372,7 +372,7 @@ def test_process_repositiories_extraneous_user_repo_value(m_log, *_):
372 372
         # Get rid of REPO_USERNAME through an override.
373 373
         with mock.patch.object(
374 374
                 config,
375
-                'get_extra_repo_store',
375
+                'get_extra_repo_overrides',
376 376
                 autospec=True,
377 377
                 return_value=repo_overrides):
378 378
             _test_process_repositories_inner(
@@ -426,7 +426,7 @@ def test_process_repositiories_no_site_def_repos_with_extraneous_overrides(
426 426
     # Provide repo overrides.
427 427
     with mock.patch.object(
428 428
             config,
429
-            'get_extra_repo_store',
429
+            'get_extra_repo_overrides',
430 430
             autospec=True,
431 431
             return_value=repo_overrides):
432 432
         _test_process_repositories_inner(
@@ -466,12 +466,12 @@ def test_process_repositories_without_repositories_key_in_site_definition(
466 466
     autospec=True,
467 467
     return_value=TEST_REPOSITORIES)
468 468
 @mock.patch.object(util.git, 'is_repository', autospec=True, return_value=True)
469
-@mock.patch.object(config, 'get_extra_repo_store', autospec=True)
469
+@mock.patch.object(config, 'get_extra_repo_overrides', autospec=True)
470 470
 def test_process_extra_repositories_malformed_format_raises_exception(
471
-        m_get_extra_repo_store, *_):
471
+        m_get_extra_repo_overrides, *_):
472 472
     # Will fail since it doesn't contain "=".
473 473
     broken_repo_url = 'broken_url'
474
-    m_get_extra_repo_store.return_value = [broken_repo_url]
474
+    m_get_extra_repo_overrides.return_value = [broken_repo_url]
475 475
     error = ("The repository %s must be in the form of "
476 476
              "name=repoUrl[@revision]" % broken_repo_url)
477 477
 

Loading…
Cancel
Save