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

static: mypy requires __init__.py #3027

Merged
merged 4 commits into from
Apr 10, 2020
Merged
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
14 changes: 9 additions & 5 deletions snapcraft/cli/_channel_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -137,19 +139,21 @@ 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,
)
progress_string = "{} {:.0f}%".format(_HINTS.PROGRESSING_TO, 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
16 changes: 8 additions & 8 deletions snapcraft/storeapi/v2/channel_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from typing import Any, Dict, List, Optional, Set, Union
from typing import Any, Dict, List, Optional, Set

import jsonschema

Expand All @@ -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.
7 changes: 5 additions & 2 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 Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
Empty file.