def _read_manifest(self, f): """Read manifest file and set up user specs.""" self.yaml = _read_yaml(f) self.spec_lists = OrderedDict() for item in config_dict(self.yaml).get('definitions', []): entry = copy.deepcopy(item) when = _eval_conditional(entry.pop('when', 'True')) assert len(entry) == 1 if when: name, spec_list = next(iter(entry.items())) user_specs = SpecList(name, spec_list, self.spec_lists.copy()) if name in self.spec_lists: self.spec_lists[name].extend(user_specs) else: self.spec_lists[name] = user_specs spec_list = config_dict(self.yaml).get(user_speclist_name) user_specs = SpecList(user_speclist_name, [s for s in spec_list if s], self.spec_lists.copy()) self.spec_lists[user_speclist_name] = user_specs enable_view = config_dict(self.yaml).get('view') # enable_view can be boolean, string, or None if enable_view is True or enable_view is None: self.views = { default_view_name: ViewDescriptor(self.view_path_default)} elif isinstance(enable_view, six.string_types): self.views = {default_view_name: ViewDescriptor(enable_view)} elif enable_view: self.views = dict((name, ViewDescriptor.from_dict(values)) for name, values in enable_view.items()) else: self.views = {}
def test_spec_list_recursion_specs_as_constraints(self): input = ['mpileaks', '$mpis', {'matrix': [['hypre'], ['$%gccs', '$%clangs']]}, 'libelf'] reference = {'gccs': SpecList('gccs', ['[email protected]']), 'clangs': SpecList('clangs', ['[email protected]']), 'mpis': SpecList('mpis', ['[email protected]', '[email protected]'])} speclist = SpecList('specs', input, reference) assert speclist.specs_as_yaml_list == self.default_expansion assert speclist.specs_as_constraints == self.default_constraints assert speclist.specs == self.default_specs
def test_spec_list_update_reference(self): speclist = SpecList('specs', self.default_input, self.default_reference) assert speclist.specs_as_yaml_list == self.default_expansion assert speclist.specs_as_constraints == self.default_constraints assert speclist.specs == self.default_specs new_mpis = SpecList('mpis', self.default_reference['mpis'].yaml_list) new_mpis.add('[email protected]') new_reference = self.default_reference.copy() new_reference['mpis'] = new_mpis speclist.update_reference(new_reference) expansion = list(self.default_expansion) expansion.insert(3, '[email protected]') constraints = list(self.default_constraints) constraints.insert(3, [Spec('[email protected]')]) specs = list(self.default_specs) specs.insert(3, Spec('[email protected]')) assert speclist.specs_as_yaml_list == expansion assert speclist.specs_as_constraints == constraints assert speclist.specs == specs
def test_spec_list_add(self): speclist = SpecList('specs', self.default_input, self.default_reference) assert speclist.specs_as_yaml_list == self.default_expansion assert speclist.specs_as_constraints == self.default_constraints assert speclist.specs == self.default_specs speclist.add('libdwarf') assert speclist.specs_as_yaml_list == self.default_expansion + [ 'libdwarf'] assert speclist.specs_as_constraints == self.default_constraints + [ [Spec('libdwarf')]] assert speclist.specs == self.default_specs + [Spec('libdwarf')]
def test_spec_list_expansions(self): speclist = SpecList('specs', self.default_input, self.default_reference) assert speclist.specs_as_yaml_list == self.default_expansion assert speclist.specs_as_constraints == self.default_constraints assert speclist.specs == self.default_specs
def _set_user_specs_from_lockfile(self): """Copy user_specs from a read-in lockfile.""" self.spec_lists = { user_speclist_name: SpecList(user_speclist_name, [str(s) for s in self.concretized_user_specs]) }
def test_spec_list_remove(self): speclist = SpecList('specs', self.default_input, self.default_reference) assert speclist.specs_as_yaml_list == self.default_expansion assert speclist.specs_as_constraints == self.default_constraints assert speclist.specs == self.default_specs speclist.remove('libelf') assert speclist.specs_as_yaml_list + ['libelf' ] == self.default_expansion assert speclist.specs_as_constraints + [[Spec('libelf')] ] == self.default_constraints assert speclist.specs + [Spec('libelf')] == self.default_specs
def clear(self): self.spec_lists = {user_speclist_name: SpecList()} # specs from yaml self.concretized_user_specs = [] # user specs from last concretize self.concretized_order = [] # roots of last concretize, in order self.specs_by_hash = {} # concretized specs by hash self.new_specs = [] # write packages for these on write() self._repo = None # RepoPath for this env (memoized) self._previous_active = None # previously active environment
def test_spec_list_matrix_exclude(self, mock_packages): # Test on non-boolean variants for regression for #16841 matrix = [{ 'matrix': [['multivalue-variant'], ['foo=bar', 'foo=baz']], 'exclude': ['foo=bar'] }] speclist = SpecList('specs', matrix) assert len(speclist.specs) == 1
def test_spec_list_nested_matrices(self): inner_matrix = [{'matrix': [['zlib', 'libelf'], ['%gcc', '%intel']]}] outer_addition = ['+shared', '~shared'] outer_matrix = [{'matrix': [inner_matrix, outer_addition]}] speclist = SpecList('specs', outer_matrix) expected_components = itertools.product(['zlib', 'libelf'], ['%gcc', '%intel'], ['+shared', '~shared']) expected = [Spec(' '.join(combo)) for combo in expected_components] assert set(speclist.specs) == set(expected)
def test_spec_list_extension(self): speclist = SpecList('specs', self.default_input, self.default_reference) assert speclist.specs_as_yaml_list == self.default_expansion assert speclist.specs_as_constraints == self.default_constraints assert speclist.specs == self.default_specs new_ref = self.default_reference.copy() otherlist = SpecList('specs', ['zlib', {'matrix': [['callpath'], ['%intel@18']]}], new_ref) speclist.extend(otherlist) assert speclist.specs_as_yaml_list == (self.default_expansion + otherlist.specs_as_yaml_list) assert speclist.specs == self.default_specs + otherlist.specs assert speclist._reference is new_ref
def test_spec_list_constraint_ordering(self): specs = [{ 'matrix': [['^zmpi'], ['%[email protected]'], ['hypre', 'libelf'], ['~shared'], ['cflags=-O3', 'cflags="-g -O0"'], ['^foo']] }] speclist = SpecList('specs', specs) expected_specs = [ Spec('hypre cflags=-O3 ~shared %[email protected] ^foo ^zmpi'), Spec('hypre cflags="-g -O0" ~shared %[email protected] ^foo ^zmpi'), Spec('libelf cflags=-O3 ~shared %[email protected] ^foo ^zmpi'), Spec('libelf cflags="-g -O0" ~shared %[email protected] ^foo ^zmpi'), ] assert speclist.specs == expected_specs
class TestSpecList(object): default_input = ['mpileaks', '$mpis', {'matrix': [['hypre'], ['$gccs', '$clangs']]}, 'libelf'] default_reference = {'gccs': SpecList('gccs', ['%[email protected]']), 'clangs': SpecList('clangs', ['%[email protected]']), 'mpis': SpecList('mpis', ['[email protected]', '[email protected]'])} default_expansion = ['mpileaks', '[email protected]', '[email protected]', {'matrix': [ ['hypre'], ['%[email protected]', '%[email protected]'], ]}, 'libelf'] default_constraints = [[Spec('mpileaks')], [Spec('[email protected]')], [Spec('[email protected]')], [Spec('hypre'), Spec('%[email protected]')], [Spec('hypre'), Spec('%[email protected]')], [Spec('libelf')]] default_specs = [Spec('mpileaks'), Spec('[email protected]'), Spec('[email protected]'), Spec('hypre%[email protected]'), Spec('hypre%[email protected]'), Spec('libelf')] def test_spec_list_expansions(self): speclist = SpecList('specs', self.default_input, self.default_reference) assert speclist.specs_as_yaml_list == self.default_expansion assert speclist.specs_as_constraints == self.default_constraints assert speclist.specs == self.default_specs def test_spec_list_constraint_ordering(self): specs = [{'matrix': [ ['^zmpi'], ['%[email protected]'], ['hypre', 'libelf'], ['~shared'], ['cflags=-O3', 'cflags="-g -O0"'], ['^foo'] ]}] speclist = SpecList('specs', specs) expected_specs = [ Spec('hypre cflags=-O3 ~shared %[email protected] ^foo ^zmpi'), Spec('hypre cflags="-g -O0" ~shared %[email protected] ^foo ^zmpi'), Spec('libelf cflags=-O3 ~shared %[email protected] ^foo ^zmpi'), Spec('libelf cflags="-g -O0" ~shared %[email protected] ^foo ^zmpi'), ] assert speclist.specs == expected_specs def test_spec_list_add(self): speclist = SpecList('specs', self.default_input, self.default_reference) assert speclist.specs_as_yaml_list == self.default_expansion assert speclist.specs_as_constraints == self.default_constraints assert speclist.specs == self.default_specs speclist.add('libdwarf') assert speclist.specs_as_yaml_list == self.default_expansion + [ 'libdwarf'] assert speclist.specs_as_constraints == self.default_constraints + [ [Spec('libdwarf')]] assert speclist.specs == self.default_specs + [Spec('libdwarf')] def test_spec_list_remove(self): speclist = SpecList('specs', self.default_input, self.default_reference) assert speclist.specs_as_yaml_list == self.default_expansion assert speclist.specs_as_constraints == self.default_constraints assert speclist.specs == self.default_specs speclist.remove('libelf') assert speclist.specs_as_yaml_list + [ 'libelf' ] == self.default_expansion assert speclist.specs_as_constraints + [ [Spec('libelf')] ] == self.default_constraints assert speclist.specs + [Spec('libelf')] == self.default_specs def test_spec_list_update_reference(self): speclist = SpecList('specs', self.default_input, self.default_reference) assert speclist.specs_as_yaml_list == self.default_expansion assert speclist.specs_as_constraints == self.default_constraints assert speclist.specs == self.default_specs new_mpis = SpecList('mpis', self.default_reference['mpis'].yaml_list) new_mpis.add('[email protected]') new_reference = self.default_reference.copy() new_reference['mpis'] = new_mpis speclist.update_reference(new_reference) expansion = list(self.default_expansion) expansion.insert(3, '[email protected]') constraints = list(self.default_constraints) constraints.insert(3, [Spec('[email protected]')]) specs = list(self.default_specs) specs.insert(3, Spec('[email protected]')) assert speclist.specs_as_yaml_list == expansion assert speclist.specs_as_constraints == constraints assert speclist.specs == specs def test_spec_list_extension(self): speclist = SpecList('specs', self.default_input, self.default_reference) assert speclist.specs_as_yaml_list == self.default_expansion assert speclist.specs_as_constraints == self.default_constraints assert speclist.specs == self.default_specs new_ref = self.default_reference.copy() otherlist = SpecList('specs', ['zlib', {'matrix': [['callpath'], ['%intel@18']]}], new_ref) speclist.extend(otherlist) assert speclist.specs_as_yaml_list == (self.default_expansion + otherlist.specs_as_yaml_list) assert speclist.specs == self.default_specs + otherlist.specs assert speclist._reference is new_ref def test_spec_list_nested_matrices(self): inner_matrix = [{'matrix': [['zlib', 'libelf'], ['%gcc', '%intel']]}] outer_addition = ['+shared', '~shared'] outer_matrix = [{'matrix': [inner_matrix, outer_addition]}] speclist = SpecList('specs', outer_matrix) expected_components = itertools.product(['zlib', 'libelf'], ['%gcc', '%intel'], ['+shared', '~shared']) expected = [Spec(' '.join(combo)) for combo in expected_components] assert set(speclist.specs) == set(expected) @pytest.mark.regression('16897') def test_spec_list_recursion_specs_as_constraints(self): input = ['mpileaks', '$mpis', {'matrix': [['hypre'], ['$%gccs', '$%clangs']]}, 'libelf'] reference = {'gccs': SpecList('gccs', ['[email protected]']), 'clangs': SpecList('clangs', ['[email protected]']), 'mpis': SpecList('mpis', ['[email protected]', '[email protected]'])} speclist = SpecList('specs', input, reference) assert speclist.specs_as_yaml_list == self.default_expansion assert speclist.specs_as_constraints == self.default_constraints assert speclist.specs == self.default_specs def test_spec_list_matrix_exclude(self, mock_packages): # Test on non-boolean variants for regression for #16841 matrix = [{'matrix': [['multivalue-variant'], ['foo=bar', 'foo=baz']], 'exclude': ['foo=bar']}] speclist = SpecList('specs', matrix) assert len(speclist.specs) == 1
def test_spec_list_constraint_ordering(self, specs, expected): speclist = SpecList('specs', specs) expected_specs = [Spec(x) for x in expected] assert speclist.specs == expected_specs
class TestSpecList(object): default_input = [ 'mpileaks', '$mpis', { 'matrix': [['hypre'], ['$gccs', '$clangs']] }, 'libelf' ] default_reference = { 'gccs': SpecList('gccs', ['%[email protected]']), 'clangs': SpecList('clangs', ['%[email protected]']), 'mpis': SpecList('mpis', ['[email protected]', '[email protected]']) } default_expansion = [ 'mpileaks', '[email protected]', '[email protected]', { 'matrix': [ ['hypre'], ['%[email protected]', '%[email protected]'], ] }, 'libelf' ] default_constraints = [[Spec('mpileaks')], [Spec('[email protected]')], [Spec('[email protected]')], [Spec('hypre'), Spec('%[email protected]')], [Spec('hypre'), Spec('%[email protected]')], [Spec('libelf')]] default_specs = [ Spec('mpileaks'), Spec('[email protected]'), Spec('[email protected]'), Spec('hypre%[email protected]'), Spec('hypre%[email protected]'), Spec('libelf') ] def test_spec_list_expansions(self): speclist = SpecList('specs', self.default_input, self.default_reference) assert speclist.specs_as_yaml_list == self.default_expansion assert speclist.specs_as_constraints == self.default_constraints assert speclist.specs == self.default_specs def test_spec_list_constraint_ordering(self): specs = [{ 'matrix': [['^zmpi'], ['%[email protected]'], ['hypre', 'libelf'], ['~shared'], ['cflags=-O3', 'cflags="-g -O0"'], ['^foo']] }] speclist = SpecList('specs', specs) expected_specs = [ Spec('hypre cflags=-O3 ~shared %[email protected] ^foo ^zmpi'), Spec('hypre cflags="-g -O0" ~shared %[email protected] ^foo ^zmpi'), Spec('libelf cflags=-O3 ~shared %[email protected] ^foo ^zmpi'), Spec('libelf cflags="-g -O0" ~shared %[email protected] ^foo ^zmpi'), ] assert speclist.specs == expected_specs def test_spec_list_add(self): speclist = SpecList('specs', self.default_input, self.default_reference) assert speclist.specs_as_yaml_list == self.default_expansion assert speclist.specs_as_constraints == self.default_constraints assert speclist.specs == self.default_specs speclist.add('libdwarf') assert speclist.specs_as_yaml_list == self.default_expansion + [ 'libdwarf' ] assert speclist.specs_as_constraints == self.default_constraints + [[ Spec('libdwarf') ]] assert speclist.specs == self.default_specs + [Spec('libdwarf')] def test_spec_list_remove(self): speclist = SpecList('specs', self.default_input, self.default_reference) assert speclist.specs_as_yaml_list == self.default_expansion assert speclist.specs_as_constraints == self.default_constraints assert speclist.specs == self.default_specs speclist.remove('libelf') assert speclist.specs_as_yaml_list + ['libelf' ] == self.default_expansion assert speclist.specs_as_constraints + [[Spec('libelf')] ] == self.default_constraints assert speclist.specs + [Spec('libelf')] == self.default_specs def test_spec_list_update_reference(self): speclist = SpecList('specs', self.default_input, self.default_reference) assert speclist.specs_as_yaml_list == self.default_expansion assert speclist.specs_as_constraints == self.default_constraints assert speclist.specs == self.default_specs new_mpis = SpecList('mpis', self.default_reference['mpis'].yaml_list) new_mpis.add('[email protected]') new_reference = self.default_reference.copy() new_reference['mpis'] = new_mpis speclist.update_reference(new_reference) expansion = list(self.default_expansion) expansion.insert(3, '[email protected]') constraints = list(self.default_constraints) constraints.insert(3, [Spec('[email protected]')]) specs = list(self.default_specs) specs.insert(3, Spec('[email protected]')) assert speclist.specs_as_yaml_list == expansion assert speclist.specs_as_constraints == constraints assert speclist.specs == specs def test_spec_list_extension(self): speclist = SpecList('specs', self.default_input, self.default_reference) assert speclist.specs_as_yaml_list == self.default_expansion assert speclist.specs_as_constraints == self.default_constraints assert speclist.specs == self.default_specs new_ref = self.default_reference.copy() otherlist = SpecList( 'specs', ['zlib', { 'matrix': [['callpath'], ['%intel@18']] }], new_ref) speclist.extend(otherlist) assert speclist.specs_as_yaml_list == (self.default_expansion + otherlist.specs_as_yaml_list) assert speclist.specs == self.default_specs + otherlist.specs assert speclist._reference is new_ref