Skip to content

Commit a7d1bee

Browse files
committed
Implement the platform requirement
Signed-off-by: Jose Luis Rivero <jrivero@osrfoundation.org>
1 parent a7ace26 commit a7d1bee

File tree

3 files changed

+58
-10
lines changed

3 files changed

+58
-10
lines changed

plugins/config/_test_repository.yaml

+10-2
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,19 @@ projects:
2727
- name: osrf
2828
type: stable
2929
- name: ignition-transport7
30+
distributions:
31+
ubuntu:
32+
- no-existing-distro
3033
repositories:
3134
- name: osrf
32-
type: stable
35+
type: broken
36+
- name: ignition-transport7
37+
distributions:
38+
ubuntu:
39+
- jammy
40+
repositories:
3341
- name: osrf
34-
type: prerelease
42+
type: stable
3543
- name: ignition-.*
3644
repositories:
3745
- name: osrf

plugins/repository.py

+15-3
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,25 @@ def load_config_file(config_file_path='config/repository.yaml'):
6565
exit(-1)
6666

6767

68-
def get_project_config(project, config):
68+
def get_first_valid_project_config(project, config, linux_distro):
6969
"""Returns the project configuration from yaml that correspond
7070
to the first match while searching starting from top to bottom
7171
"""
7272
for p in config['projects']:
7373
pattern = re.compile(p['name'])
74+
7475
if pattern.search(project):
75-
return p
76+
# project name found, check that requirements are met
77+
try:
78+
# 1. If distribution requirement exists check it
79+
if linux_distro in p['distributions'][distro.id()]:
80+
return p
81+
except KeyError as kerror:
82+
# 2. No disitribution requirement set
83+
if 'distributions' in str(kerror):
84+
return p
85+
assert f"Unexpected keyerror: #{str(kerror)}"
86+
7687
return None
7788

7889

@@ -213,9 +224,10 @@ def validate_input(args):
213224

214225

215226
def process_project_install(project, config, linux_distro, dry_run=False):
216-
project_config = get_project_config(project, config)
227+
project_config = get_first_valid_project_config(project, config, linux_distro)
217228
if not project_config:
218229
error('Unknown project: ' + project)
230+
219231
if not dry_run: # useful for tests
220232
install_repos(get_repositories_config(project_config),
221233
config,

plugins/repository_TEST.py

+33-5
Original file line numberDiff line numberDiff line change
@@ -59,25 +59,53 @@ def test_no_type(self):
5959
class TestProjectNameResolution(TestBase):
6060

6161
def test_direct_match(self):
62-
project_config = repository.get_project_config('ignition-math6',
63-
self.config)
62+
project_config = \
63+
repository.get_first_valid_project_config('ignition-math6',
64+
self.config,
65+
'jammy')
6466
for p in repository.get_repositories_config(project_config):
6567
self.assertEqual(p['name'], 'osrf')
6668
self.assertEqual(p['type'], 'stable')
6769

6870
def test_non_exist(self):
69-
self.assertIsNone(repository.get_project_config('fooooo', self.config))
71+
self.assertIsNone(
72+
repository.get_first_valid_project_config('fooooo',
73+
self.config,
74+
'jammy'))
7075

7176
def test_regexp(self):
72-
project_config = repository.get_project_config('ignition-plugin',
73-
self.config)
77+
project_config = \
78+
repository.get_first_valid_project_config('ignition-plugin',
79+
self.config,
80+
'jammy')
7481
for p in repository.get_repositories_config(project_config):
7582
self.assertEqual(p['name'], 'osrf')
7683
self.assertEqual(p['type'], 'regexp')
7784

85+
def test_precedence(self):
86+
project_config = \
87+
repository.get_first_valid_project_config('ignition-transport7',
88+
self.config,
89+
'jammy')
90+
for p in repository.get_repositories_config(project_config):
91+
self.assertEqual(p['name'], 'osrf')
92+
self.assertEqual(p['type'], 'stable')
93+
7894

7995
class TestProjectInstall(TestBase):
8096

97+
def test_no_distributions(self):
98+
repository.process_project_install('ignition-math6',
99+
self.config,
100+
'jammy',
101+
dry_run=True)
102+
103+
def test_distributions(self):
104+
repository.process_project_install('ignition-transport7',
105+
self.config,
106+
'jammy',
107+
dry_run=True)
108+
81109
def test_non_exist(self):
82110
with self.assertRaises(SystemExit):
83111
repository.process_project_install('fooooo',

0 commit comments

Comments
 (0)