Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix/7.5 merge #4281

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion requirements-devel.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ click==8.1.3
codespell==2.2.4
colorama==0.4.6
coverage==7.2.5
craft-archives==1.0.0
craft-archives==1.1.2
craft-cli==2.0.0
craft-grammar==1.1.1
craft-parts==1.21.1
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cffi==1.15.1
chardet==5.1.0
charset-normalizer==3.1.0
click==8.1.3
craft-archives==1.0.0
craft-archives==1.1.2
craft-cli==2.0.0
craft-grammar==1.1.1
craft-parts==1.21.1
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[codespell]
ignore-words-list = buildd,crate,keyserver,comandos,ro,astroid
skip = waf,*.tar,*.xz,*.zip,*.bz2,*.7z,*.gz,*.deb,*.rpm,*.snap,*.gpg,*.pyc,*.png,*.ico,*.jar,*.so,changelog,.git,.hg,.mypy_cache,.tox,.venv,venv,_build,buck-out,__pycache__,build,dist,.vscode,parts,stage,prime,test_appstream.py,./snapcraft.spec,./.direnv,./.pytest_cache,.ruff_cache
skip = waf,*.tar,*.xz,*.zip,*.bz2,*.7z,*.gz,*.deb,*.rpm,*.snap,*.gpg,*.pyc,*.png,*.ico,*.jar,*.so,changelog,.git,.hg,.mypy_cache,.tox,.venv,venv,_build,buck-out,__pycache__,build,dist,.vscode,parts,stage,prime,test_appstream.py,./snapcraft.spec,./.direnv,./.pytest_cache,.ruff_cache,*.asc
quiet-level = 4

[flake8]
Expand Down
6 changes: 4 additions & 2 deletions snapcraft/commands/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,11 @@ def run(self, parsed_args):

client = store.StoreClientCLI()

snap_yaml = get_data_from_snap_file(snap_file)
snap_yaml, manifest_yaml = get_data_from_snap_file(snap_file)
snap_name = snap_yaml["name"]
built_at = snap_yaml.get("snapcraft-started-at")
built_at = None
if manifest_yaml:
built_at = manifest_yaml.get("snapcraft-started-at")

client.verify_upload(snap_name=snap_name)

Expand Down
41 changes: 40 additions & 1 deletion snapcraft/meta/snap_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from pydantic_yaml import YamlModel

from snapcraft import errors
from snapcraft.projects import App, Project
from snapcraft.projects import App, Project, UniqueStrList
from snapcraft.utils import get_ld_library_paths, process_version


Expand Down Expand Up @@ -176,6 +176,41 @@ def get_content_dirs(self, installed_path: Path) -> Set[Path]:
return content_dirs


class Links(_SnapMetadataModel):
"""Metadata links used in snaps."""

contact: Optional[UniqueStrList]
donation: Optional[UniqueStrList]
issues: Optional[UniqueStrList]
source_code: Optional[UniqueStrList]
website: Optional[UniqueStrList]

@staticmethod
def _normalize_value(
value: Optional[Union[str, UniqueStrList]]
) -> Optional[List[str]]:
if isinstance(value, str):
value = [value]
return value

@classmethod
def from_project(cls, project: Project) -> "Links":
"""Create Links from a Project."""
return cls(
contact=cls._normalize_value(project.contact),
donation=cls._normalize_value(project.donation),
issues=cls._normalize_value(project.issues),
source_code=cls._normalize_value(project.source_code),
website=cls._normalize_value(project.website),
)

def __bool__(self) -> bool:
"""Return True if any of the Links attributes are set."""
return any(
[self.contact, self.donation, self.issues, self.source_code, self.website]
)


class SnapMetadata(_SnapMetadataModel):
"""The snap.yaml model.
Expand Down Expand Up @@ -210,6 +245,7 @@ class Config:
layout: Optional[Dict[str, Dict[str, str]]]
system_usernames: Optional[Dict[str, Any]]
provenance: Optional[str]
links: Optional[Links]

@classmethod
def unmarshal(cls, data: Dict[str, Any]) -> "SnapMetadata":
Expand Down Expand Up @@ -405,6 +441,8 @@ def write(project: Project, prime_dir: Path, *, arch: str):
# project provided assumes and computed assumes
total_assumes = sorted(project.assumes + list(assumes))

links = Links.from_project(project)

snap_metadata = SnapMetadata(
name=project.name,
title=project.title,
Expand All @@ -427,6 +465,7 @@ def write(project: Project, prime_dir: Path, *, arch: str):
layout=project.layout,
system_usernames=project.system_usernames,
provenance=project.provenance,
links=links if links else None,
)
if project.passthrough:
for name, value in project.passthrough.items():
Expand Down
46 changes: 31 additions & 15 deletions snapcraft_legacy/_store.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-
#
# Copyright 2016-2022 Canonical Ltd
# Copyright 2016-2023 Canonical Ltd
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3 as
Expand Down Expand Up @@ -52,6 +52,7 @@


def get_data_from_snap_file(snap_path):
manifest_yaml = None
with tempfile.TemporaryDirectory() as temp_dir:
unsquashfs_path = get_snap_tool_path("unsquashfs")
try:
Expand All @@ -61,9 +62,9 @@ def get_data_from_snap_file(snap_path):
"-d",
os.path.join(temp_dir, "squashfs-root"),
snap_path,
"-e",
# cygwin unsquashfs on windows uses unix paths.
Path("meta", "snap.yaml").as_posix(),
Path("snap", "manifest.yaml").as_posix(),
]
)
except subprocess.CalledProcessError:
Expand All @@ -73,7 +74,12 @@ def get_data_from_snap_file(snap_path):
os.path.join(temp_dir, "squashfs-root", "meta", "snap.yaml")
) as yaml_file:
snap_yaml = yaml_utils.load(yaml_file)
return snap_yaml
manifest_path = Path(temp_dir, "squashfs-root", "snap", "manifest.yaml")
if manifest_path.exists():
with open(manifest_path) as manifest_yaml_file:
manifest_yaml = yaml_utils.load(manifest_yaml_file)

return snap_yaml, manifest_yaml


@contextlib.contextmanager
Expand Down Expand Up @@ -435,11 +441,11 @@ def list_keys():
"""Lists keys available to sign assertions."""
keys = list(_get_usable_keys())
account_info = StoreClientCLI().get_account_information()
enabled_keys = {
enabled_keys = [
account_key["public-key-sha3-384"]
for account_key in account_info["account_keys"]
}
if keys and enabled_keys:
]
if keys:
tabulated_keys = tabulate(
[
(
Expand All @@ -453,19 +459,29 @@ def list_keys():
headers=["", "Name", "SHA3-384 fingerprint", ""],
tablefmt="plain",
)
print(
"The following keys are available on this system:"
)
print(tabulated_keys)
elif not keys and enabled_keys:
registered_keys = "\n".join([f"- {key}" for key in enabled_keys])
else:
print(
"No keys have been created on this system. "
" See 'snapcraft create-key --help' to create a key.\n"
"The following SHA3-384 key fingerprints have been registered "
f"but are not available on this system:\n{registered_keys}"
"See 'snapcraft create-key --help' to create a key."
)
if enabled_keys:
local_hashes = {key["sha3-384"] for key in keys}
registered_keys = "\n".join(
(f"- {key}" for key in enabled_keys if key not in local_hashes)
)
if registered_keys:
print(
"The following SHA3-384 key fingerprints have been registered "
f"but are not available on this system:\n{registered_keys}"
)
else:
print(
"No keys have been registered."
" See 'snapcraft register-key --help' to register a key."
"No keys have been registered with this account. "
"See 'snapcraft register-key --help' to register a key."
)


Expand Down Expand Up @@ -574,7 +590,7 @@ def sign_build(snap_filename, key_name=None, local=False):
if not os.path.exists(snap_filename):
raise FileNotFoundError("The file {!r} does not exist.".format(snap_filename))

snap_yaml = get_data_from_snap_file(snap_filename)
snap_yaml, _ = get_data_from_snap_file(snap_filename)
snap_name = snap_yaml["name"]
grade = snap_yaml.get("grade", "stable")

Expand Down Expand Up @@ -625,7 +641,7 @@ def upload_metadata(snap_filename, force):
logger.debug("Uploading metadata to the Store (force=%s)", force)

# get the metadata from the snap
snap_yaml = get_data_from_snap_file(snap_filename)
snap_yaml, _ = get_data_from_snap_file(snap_filename)
metadata = {
"summary": snap_yaml["summary"],
"description": snap_yaml["description"],
Expand Down
Loading
Loading