def _process_entry_parts(entry_parts, parts, origin, maintainer, description, origin_name, origin_version): after_parts = set() parts_list = {} for part_name in entry_parts: if '/' in part_name: logger.warning( 'DEPRECATED: Found a "/" in the name of the {!r} part'.format( part_name)) source_part = parts.get(part_name) replacements = [ ('$SNAPCRAFT_PROJECT_NAME', origin_name), ('$SNAPCRAFT_PROJECT_VERSION', origin_version), ] source_part = replace_attr(source_part, replacements) if source_part: source_part = _update_source(source_part, origin) source_part['maintainer'] = maintainer source_part['description'] = description parts_list[part_name] = source_part after = source_part.get("after", []) if after: after_parts.update(set(after)) return parts_list, after_parts
def test_tuples_with_string_replacements(self): replacements = ( ( "no replacement", ("snapcraft_stage/usr/bin", "/usr/bin"), ["snapcraft_stage/usr/bin", "/usr/bin"], ), ( "replaced start", ("$SNAPCRAFT_STAGE/usr/bin", "/usr/bin"), ["{}/usr/bin".format(self.stage_dir), "/usr/bin"], ), ( "replaced between", ("--without-python", "--with-swig $SNAPCRAFT_STAGE/usr/swig"), [ "--without-python", "--with-swig {}/usr/swig".format(self.stage_dir) ], ), ) for test_name, subject, expected in replacements: self.assertThat( project_loader.replace_attr( subject, { "$SNAPCRAFT_PROJECT_NAME": "project_name", "$SNAPCRAFT_PROJECT_VERSION": "version", "$SNAPCRAFT_STAGE": self.stage_dir, }, ), Equals(expected), )
def test_tuples_with_string_replacements(self): replacements = ( ( "no replacement", ("snapcraft_stage/usr/bin", "/usr/bin"), ["snapcraft_stage/usr/bin", "/usr/bin"], ), ( "replaced start", ("$SNAPCRAFT_STAGE/usr/bin", "/usr/bin"), ["{}/usr/bin".format(self.stage_dir), "/usr/bin"], ), ( "replaced between", ("--without-python", "--with-swig $SNAPCRAFT_STAGE/usr/swig"), ["--without-python", "--with-swig {}/usr/swig".format(self.stage_dir)], ), ) for test_name, subject, expected in replacements: self.assertThat( project_loader.replace_attr( subject, { "$SNAPCRAFT_PROJECT_NAME": "project_name", "$SNAPCRAFT_PROJECT_VERSION": "version", "$SNAPCRAFT_STAGE": self.stage_dir, }, ), Equals(expected), )
def _process_entry_parts(entry_parts, parts, origin, maintainer, description, origin_name, origin_version): after_parts = set() parts_list = {} for part_name in entry_parts: if "/" in part_name: logger.warning( 'DEPRECATED: Found a "/" in the name of the {!r} part'.format( part_name)) source_part = parts.get(part_name) replacements = project_loader.environment_to_replacements({ "SNAPCRAFT_PROJECT_NAME": origin_name, "SNAPCRAFT_PROJECT_VERSION": origin_version, }) source_part = project_loader.replace_attr(source_part, replacements) if source_part: source_part = _update_source(source_part, origin) source_part["maintainer"] = maintainer source_part["description"] = description parts_list[part_name] = source_part after = source_part.get("after", []) if after: after_parts.update(set(after)) else: after_parts.add(part_name) return parts_list, after_parts
def _replace_in_part(part): for key, value in part.code.options.__dict__.items(): value = replace_attr(value, [ ('$SNAPCRAFT_PART_INSTALL', part.code.installdir), ]) setattr(part.code.options, key, value) return part
def _replace_in_part(part): for key, value in part.plugin.options.__dict__.items(): replacements = project_loader.environment_to_replacements( project_loader.snapcraft_part_environment(part)) value = project_loader.replace_attr(value, replacements) setattr(part.plugin.options, key, value) return part
def _replace_in_part(part): for key, value in part.plugin.options.__dict__.items(): replacements = project_loader.environment_to_replacements( project_loader.snapcraft_part_environment(part) ) value = project_loader.replace_attr(value, replacements) setattr(part.plugin.options, key, value) return part
def test_string_replacement_with_complex_data(self): subject = { "filesets": { "files": [ "somefile", "$SNAPCRAFT_STAGE/file1", "SNAPCRAFT_STAGE/really", ] }, "configflags": ["--with-python", "--with-swig $SNAPCRAFT_STAGE/swig"], } expected = { "filesets": { "files": [ "somefile", "{}/file1".format(self.stage_dir), "SNAPCRAFT_STAGE/really", ] }, "configflags": [ "--with-python", "--with-swig {}/swig".format(self.stage_dir), ], } self.assertThat( project_loader.replace_attr( subject, { "$SNAPCRAFT_PROJECT_NAME": "project_name", "$SNAPCRAFT_PROJECT_VERSION": "version", "$SNAPCRAFT_STAGE": self.stage_dir, }, ), Equals(expected), )