Skip to content

Commit

Permalink
Merge branch 'main' into kernel-config-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
arighi authored Aug 14, 2023
2 parents f8b46de + 8758571 commit 5685218
Show file tree
Hide file tree
Showing 36 changed files with 2,835 additions and 54 deletions.
1 change: 1 addition & 0 deletions constraints.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cython<3
2 changes: 1 addition & 1 deletion docs/.sphinx/pinned-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ livereload==2.6.3
MarkupSafe==2.1.1
packaging==21.3
pyenchant==3.2.2
Pygments==2.13.0
Pygments==2.15.0
pyparsing==3.0.9
pytz==2022.6
requests==2.31.0
Expand Down
4 changes: 2 additions & 2 deletions requirements-devel.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ 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.3
craft-cli==2.0.0
craft-grammar==1.1.1
craft-parts==1.21.1
craft-providers==1.13.0
craft-store==2.4.0
cryptography==41.0.0
cryptography==41.0.3
Deprecated==1.2.13
dill==0.3.6
distlib==0.3.6
Expand Down
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ 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.3
craft-cli==2.0.0
craft-grammar==1.1.1
craft-parts==1.21.1
craft-providers==1.13.0
craft-store==2.4.0
cryptography==41.0.0
cryptography==41.0.3
Deprecated==1.2.13
distro==1.8.0
docutils==0.19
Expand Down Expand Up @@ -51,7 +51,7 @@ python-dateutil==2.8.2
python-debian==0.1.49
pytz==2023.3
pyxdg==0.28
PyYAML==6.0
PyYAML==6.0.1
raven==6.10.0
requests==2.31.0
requests-toolbelt==1.0.0
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
File renamed without changes.
4 changes: 3 additions & 1 deletion snap/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ parts:
# Apply patches
echo "Patching ctypes..."
patch -s -b "${PYTHON_PACKAGE_PATH}/${CTYPES_INIT}" "${SNAPCRAFT_PROJECT_DIR}/patches/ctypes_init.diff"
patch -s -b "${PYTHON_PACKAGE_PATH}/${CTYPES_INIT}" "${SNAPCRAFT_PROJECT_DIR}/snap/local/patches/python/ctypes_init.diff"
# Save patches to allow rebuilding
mkdir -p patched/ctypes
Expand All @@ -144,6 +144,8 @@ parts:
# Limited to < 66 because we need `pkg_resources` and because `python-apt`
# does not build with the latest.
- setuptools<66
python-constraints:
- constraints.txt
python-requirements:
- requirements.txt
organize:
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
2 changes: 1 addition & 1 deletion snapcraft_legacy/cli/_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def __repr__(self):
is_flag=True,
help="Enable plugins that are experimental and not considered stable.",
envvar="SNAPCRAFT_ENABLE_EXPERIMENTAL_PLUGINS",
supported_providers=["host", "lxd", "managed-host", "multipass"],
supported_providers=_ALL_PROVIDERS,
),
dict(
param_decls=["--enable-experimental-target-arch"],
Expand Down
Loading

0 comments on commit 5685218

Please sign in to comment.