diff --git a/snapcraft/cli/_channel_map.py b/snapcraft/cli/_channel_map.py index cdf9c169ee..7b1cf6f114 100644 --- a/snapcraft/cli/_channel_map.py +++ b/snapcraft/cli/_channel_map.py @@ -37,7 +37,9 @@ class _HINTS: PROGRESSING_TO: Final[str] = "→" -def _get_channel_hint(*, channel_map, fallback: str, architecture: str) -> str: +def _get_channel_hint( + *, channel_map, fallback: Optional[str], architecture: str +) -> str: tick = _HINTS.CLOSED for c in channel_map: if c.channel == fallback and c.architecture == architecture: @@ -137,6 +139,7 @@ def _get_channel_lines_for_channel( progressive_revision = snap_channel_map.get_revision( progressive_mapped_channel.revision ) + progressive_mapped_channel_line = _get_channel_line( mapped_channel=progressive_mapped_channel, revision=progressive_revision, @@ -144,12 +147,13 @@ def _get_channel_lines_for_channel( hint=hint, progress_string=f"{_HINTS.PROGRESSING_TO} {progressive_mapped_channel.progressive.percentage:.0f}%", ) + if progressive_mapped_channel.progressive.percentage is None: + percentage = 0.0 + else: + percentage = progressive_mapped_channel.progressive.percentage # Setup progress for the actually released revision, this needs to be # calculated. But only show it if the channel is open. - progress_string = "{} {:.0f}%".format( - _HINTS.PROGRESSING_TO, - 100 - progressive_mapped_channel.progressive.percentage, - ) + progress_string = "{} {:.0f}%".format(_HINTS.PROGRESSING_TO, 100 - percentage) else: progress_string = _HINTS.NO_PROGRESS diff --git a/snapcraft/internal/lxd/__init__.py b/snapcraft/internal/lxd/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/snapcraft/plugins/_python/__init__.py b/snapcraft/plugins/_python/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/snapcraft/plugins/v2/__init__.py b/snapcraft/plugins/v2/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/snapcraft/scripts/__init__.py b/snapcraft/scripts/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/snapcraft/storeapi/v2/__init__.py b/snapcraft/storeapi/v2/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/snapcraft/storeapi/v2/_api_schema.py b/snapcraft/storeapi/v2/_api_schema.py index 8e77bdf4da..d1423ae3b5 100644 --- a/snapcraft/storeapi/v2/_api_schema.py +++ b/snapcraft/storeapi/v2/_api_schema.py @@ -18,7 +18,10 @@ # Snapcraft does not have been commented out from this schema originally # imported from # https://dashboard.snapcraft.io/docs/v2/en/snaps.html#snap-channel-map -CHANNEL_MAP_JSONSCHEMA = { + +from typing import Any, Dict + +CHANNEL_MAP_JSONSCHEMA: Dict[str, Any] = { "additionalProperties": False, "properties": { "channel-map": { diff --git a/snapcraft/storeapi/v2/channel_map.py b/snapcraft/storeapi/v2/channel_map.py index 0b0d813edf..2065b6fdd8 100644 --- a/snapcraft/storeapi/v2/channel_map.py +++ b/snapcraft/storeapi/v2/channel_map.py @@ -14,7 +14,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from typing import Any, Dict, List, Optional, Set, Union +from typing import Any, Dict, List, Optional, Set import jsonschema @@ -35,7 +35,7 @@ class Progressive: """ @classmethod - def unmarshal(cls, payload: Dict[str, Union[str, Optional[bool]]]) -> "Progressive": + def unmarshal(cls, payload: Dict[str, Any]) -> "Progressive": jsonschema.validate( payload, CHANNEL_MAP_JSONSCHEMA["properties"]["channel-map"]["items"]["properties"][ @@ -48,7 +48,7 @@ def unmarshal(cls, payload: Dict[str, Union[str, Optional[bool]]]) -> "Progressi percentage=payload["percentage"], ) - def marshal(self) -> Dict[str, Union[str, Optional[bool]]]: + def marshal(self) -> Dict[str, Any]: return {"key": self.key, "paused": self.paused, "percentage": self.percentage} def __repr__(self) -> str: @@ -114,7 +114,7 @@ class Revision: """ @classmethod - def unmarshal(cls, payload: Dict[str, Union[int, str, List[str]]]) -> "Revision": + def unmarshal(cls, payload: Dict[str, Any]) -> "Revision": jsonschema.validate( payload, CHANNEL_MAP_JSONSCHEMA["properties"]["revisions"]["items"] ) @@ -124,7 +124,7 @@ def unmarshal(cls, payload: Dict[str, Union[int, str, List[str]]]) -> "Revision" architectures=payload["architectures"], ) - def marshal(self) -> Dict[str, Union[int, str, List[str]]]: + def marshal(self) -> Dict[str, Any]: return { "revision": self.revision, "version": self.version, @@ -148,7 +148,7 @@ class SnapChannel: """ @classmethod - def unmarshal(cls, payload: Dict[str, Optional[str]]) -> "SnapChannel": + def unmarshal(cls, payload: Dict[str, Any]) -> "SnapChannel": jsonschema.validate( payload, CHANNEL_MAP_JSONSCHEMA["properties"]["snap"]["properties"]["channels"][ @@ -163,7 +163,7 @@ def unmarshal(cls, payload: Dict[str, Optional[str]]) -> "SnapChannel": fallback=payload["fallback"], ) - def marshal(self) -> Dict[str, Optional[str]]: + def marshal(self) -> Dict[str, Any]: return { "name": self.name, "track": self.track, @@ -235,7 +235,7 @@ def marshal(self) -> Dict[str, Any]: } def __repr__(self) -> str: - return "<{self.__class__.__name__}: {!r}>".format(self.snap.name) + return f"<{self.__class__.__name__}: {self.snap.name!r}>" def __init__( self, *, channel_map: List[MappedChannel], revisions: List[Revision], snap: Snap diff --git a/tests/unit/build_providers/lxd/__init__.py b/tests/unit/build_providers/lxd/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/unit/build_providers/lxd/test_lxd.py b/tests/unit/build_providers/lxd/test_lxd.py index 1e08e1ea0f..0daeb69dac 100644 --- a/tests/unit/build_providers/lxd/test_lxd.py +++ b/tests/unit/build_providers/lxd/test_lxd.py @@ -59,13 +59,16 @@ def __init__(self, config: Dict[str, Any], wait: bool) -> None: class FakeContainerFiles: delete_available = True + @staticmethod def get(file_name) -> bytes: self.files_get_mock(file_name=file_name) return b"fake-pull" + @staticmethod def put(destination: str, contents: bytes) -> None: self.files_put_mock(destination=destination, contents=contents) + @staticmethod def delete(file_name) -> None: self.files_delete_mock(file_name=file_name) @@ -156,7 +159,7 @@ def test_create(self): self.fake_pylxd_client.containers.create_mock.assert_called_once_with( config={ "name": "snapcraft-project-name", - "raw.idmap": "both 1000 0", + "raw.idmap": f"both {os.getuid()} 0", "source": { "mode": "pull", "type": "image", @@ -324,7 +327,7 @@ def test_create_for_type_base(self): self.fake_pylxd_client.containers.create_mock.assert_called_once_with( config={ "name": "snapcraft-core18", - "raw.idmap": "both 1000 0", + "raw.idmap": f"both {os.getuid()} 0", "source": { "mode": "pull", "type": "image", diff --git a/tests/unit/review_tools/__init__.py b/tests/unit/review_tools/__init__.py new file mode 100644 index 0000000000..e69de29bb2