Skip to content

Commit

Permalink
Implement the platform requirement
Browse files Browse the repository at this point in the history
Signed-off-by: Jose Luis Rivero <jrivero@osrfoundation.org>
  • Loading branch information
j-rivero committed Mar 27, 2024
1 parent a7ace26 commit a7d1bee
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 10 deletions.
12 changes: 10 additions & 2 deletions plugins/config/_test_repository.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,19 @@ projects:
- name: osrf
type: stable
- name: ignition-transport7
distributions:
ubuntu:
- no-existing-distro
repositories:
- name: osrf
type: stable
type: broken
- name: ignition-transport7
distributions:
ubuntu:
- jammy
repositories:
- name: osrf
type: prerelease
type: stable
- name: ignition-.*
repositories:
- name: osrf
Expand Down
18 changes: 15 additions & 3 deletions plugins/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,25 @@ def load_config_file(config_file_path='config/repository.yaml'):
exit(-1)


def get_project_config(project, config):
def get_first_valid_project_config(project, config, linux_distro):
"""Returns the project configuration from yaml that correspond
to the first match while searching starting from top to bottom
"""
for p in config['projects']:
pattern = re.compile(p['name'])

if pattern.search(project):
return p
# project name found, check that requirements are met
try:
# 1. If distribution requirement exists check it
if linux_distro in p['distributions'][distro.id()]:
return p
except KeyError as kerror:
# 2. No disitribution requirement set
if 'distributions' in str(kerror):
return p
assert f"Unexpected keyerror: #{str(kerror)}"

return None


Expand Down Expand Up @@ -213,9 +224,10 @@ def validate_input(args):


def process_project_install(project, config, linux_distro, dry_run=False):
project_config = get_project_config(project, config)
project_config = get_first_valid_project_config(project, config, linux_distro)
if not project_config:
error('Unknown project: ' + project)

if not dry_run: # useful for tests
install_repos(get_repositories_config(project_config),
config,
Expand Down
38 changes: 33 additions & 5 deletions plugins/repository_TEST.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,25 +59,53 @@ def test_no_type(self):
class TestProjectNameResolution(TestBase):

def test_direct_match(self):
project_config = repository.get_project_config('ignition-math6',
self.config)
project_config = \
repository.get_first_valid_project_config('ignition-math6',
self.config,
'jammy')
for p in repository.get_repositories_config(project_config):
self.assertEqual(p['name'], 'osrf')
self.assertEqual(p['type'], 'stable')

def test_non_exist(self):
self.assertIsNone(repository.get_project_config('fooooo', self.config))
self.assertIsNone(
repository.get_first_valid_project_config('fooooo',
self.config,
'jammy'))

def test_regexp(self):
project_config = repository.get_project_config('ignition-plugin',
self.config)
project_config = \
repository.get_first_valid_project_config('ignition-plugin',
self.config,
'jammy')
for p in repository.get_repositories_config(project_config):
self.assertEqual(p['name'], 'osrf')
self.assertEqual(p['type'], 'regexp')

def test_precedence(self):
project_config = \
repository.get_first_valid_project_config('ignition-transport7',
self.config,
'jammy')
for p in repository.get_repositories_config(project_config):
self.assertEqual(p['name'], 'osrf')
self.assertEqual(p['type'], 'stable')


class TestProjectInstall(TestBase):

def test_no_distributions(self):
repository.process_project_install('ignition-math6',
self.config,
'jammy',
dry_run=True)

def test_distributions(self):
repository.process_project_install('ignition-transport7',
self.config,
'jammy',
dry_run=True)

def test_non_exist(self):
with self.assertRaises(SystemExit):
repository.process_project_install('fooooo',
Expand Down

0 comments on commit a7d1bee

Please sign in to comment.