Skip to content

Commit

Permalink
static: mypy requires __init__.py
Browse files Browse the repository at this point in the history
Add missing __init__.py to workaround python/mypy#1645
Fix mypy type hint issues in the code found from this.

Signed-off-by: Sergio Schvezov <sergio.schvezov@canonical.com>
  • Loading branch information
sergiusens committed Apr 10, 2020
1 parent 1237aa6 commit 8cf2e94
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 10 deletions.
9 changes: 7 additions & 2 deletions snapcraft/cli/_channel_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ 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:
Expand Down Expand Up @@ -137,18 +137,23 @@ 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,
channel_info=channel_info,
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,
100 - percentage,
)
else:
progress_string = _HINTS.NO_PROGRESS
Expand Down
Empty file.
Empty file.
Empty file.
Empty file added snapcraft/scripts/__init__.py
Empty file.
Empty file.
5 changes: 4 additions & 1 deletion snapcraft/storeapi/v2/_api_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
14 changes: 7 additions & 7 deletions snapcraft/storeapi/v2/channel_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"][
Expand All @@ -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:
Expand Down Expand Up @@ -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"]
)
Expand All @@ -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,
Expand All @@ -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"][
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down
Empty file.
3 changes: 3 additions & 0 deletions tests/unit/build_providers/lxd/test_lxd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Empty file.

0 comments on commit 8cf2e94

Please sign in to comment.