Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_yaml_conversion(self, init_spy):
state_string = yaml_utils.dump(self.state)
# Verify that the dumped tag was correct
self.assertThat(state_string.splitlines()[0], Equals("!BuildState"))
# Now verify the conversion
state_from_yaml = yaml_utils.load(state_string)
self.assertThat(state_from_yaml, Equals(self.state))
# Verify that init was not called
init_spy.assert_not_called()
def generate_meta_yaml(
self, *, build=False, actual_prime_dir=None, snapcraft_yaml_file_path=None
):
if snapcraft_yaml_file_path is None:
snapcraft_yaml_file_path = self.snapcraft_yaml_file_path
os.makedirs("snap", exist_ok=True)
with open(snapcraft_yaml_file_path, "w") as f:
f.write(yaml_utils.dump(self.config_data))
self.project = Project(snapcraft_yaml_file_path=snapcraft_yaml_file_path)
if actual_prime_dir is not None:
self.project._prime_dir = actual_prime_dir
self.meta_dir = os.path.join(self.project.prime_dir, "meta")
self.hooks_dir = os.path.join(self.meta_dir, "hooks")
self.snap_yaml = os.path.join(self.meta_dir, "snap.yaml")
self.config = project_loader.load_config(project=self.project)
if build:
for part in self.config.parts.all_parts:
part.pull()
part.build()
part.stage()
part.prime()
def test_ordereddict_yaml(self):
from collections import OrderedDict
data = OrderedDict()
data["name"] = "test"
data["description"] = "description"
output = yaml_utils.dump(data)
self.assertTrue(isinstance(yaml_utils.load(output), OrderedDict))
def mark_done(self, step, state=None):
if not state:
state = {}
with open(states.get_step_state_file(self.plugin.statedir, step), "w") as f:
f.write(yaml_utils.dump(state))
def _save_registry(
registry_data: Dict[str, List[Any]], registry_filepath: Optional[str]
) -> None:
if registry_filepath is None:
return
dirpath = os.path.dirname(registry_filepath)
if dirpath:
os.makedirs(dirpath, exist_ok=True)
with open(registry_filepath, "w") as registry_file:
yaml_utils.dump(registry_data, stream=registry_file)
# Create sources directory for source archives.
os.makedirs(self._repo_sources_dir, exist_ok=True)
# Process each part with sources.
for part_name, part_config in self._snapcraft_config["parts"].items():
part_config = self._process_part_sources(part_name, part_config)
self._prepared_snapcraft_config["parts"][part_name] = part_config
# Set version.
self._set_prepared_project_version()
# Write updated snapcraft yaml config.
snapcraft_yaml_path = os.path.join(self._repo_snap_dir, "snapcraft.yaml")
with open(snapcraft_yaml_path, "w") as f:
yaml_utils.dump(self._prepared_snapcraft_config, stream=f)
return self._repo_dir
def define(part_name):
try:
remote_part = _RemoteParts().get_part(part_name, full=True)
except errors.SnapcraftPartMissingError as e:
raise errors.PartNotInCacheError(part_name=part_name) from e
print("Maintainer: {!r}".format(remote_part.pop("maintainer")))
print("Description: {}".format(remote_part.pop("description")))
print("")
yaml_utils.dump({part_name: remote_part}, stream=sys.stdout)
def save(self, *, filepath: str) -> None:
dirpath = os.path.dirname(filepath)
if dirpath:
os.makedirs(dirpath, exist_ok=True)
with open(filepath, "w") as state_file:
yaml_utils.dump(self, stream=state_file)
output = urllib.request.urlopen(index).read()
except urllib.error.URLError as e:
logging.error("Unable to access index: {!r}".format(e))
return 1
data = _process_index(output)
master_parts_list = data["master_parts_list"]
wiki_errors = data["wiki_errors"]
if wiki_errors:
logger.warning("{} wiki errors found!".format(wiki_errors))
_write_parts_list(path, master_parts_list)
if args["--debug"]:
print(yaml_utils.dump(master_parts_list))
return wiki_errors
def expand_extensions(**kwargs):
"""Display snapcraft.yaml with all extensions applied."""
project = get_project(**kwargs)
yaml_with_extensions = project_loader.apply_extensions(
project.info.get_raw_snapcraft()
)
# Loading the config applied all the extensions, so just dump it back out
yaml_utils.dump(yaml_with_extensions, stream=sys.stdout)