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

Added missing typings. #2123

Merged
merged 4 commits into from
May 17, 2022
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
2 changes: 1 addition & 1 deletion .github/workflows/python-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
pipenv run flake8 .
- name: Run Type Checker
run: |
pipenv run mypy src/build_workflow tests/tests_build_workflow src/checkout_workflow tests/tests_checkout_workflow src/run_assemble.py tests/test_run_assemble.py src/assemble_workflow tests/tests_assemble_workflow src/manifests tests/tests_manifests src/paths tests/tests_paths src/system tests/tests_system src/ci_workflow tests/tests_ci_workflow src/manifests_workflow tests/tests_manifests_workflow
pipenv run mypy .
peterzhuamazon marked this conversation as resolved.
Show resolved Hide resolved
- name: Run Tests with Coverage
run: |
pipenv run coverage run -m pytest --cov=./src --cov-report=xml
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ repos:
- id: mypy
stages: [commit]
name: mypy
entry: bash -c 'pipenv run mypy src/build_workflow tests/tests_build_workflow src/checkout_workflow tests/tests_checkout_workflow src/run_assemble.py tests/test_run_assemble.py src/assemble_workflow tests/tests_assemble_workflow src/manifests tests/tests_manifests src/paths tests/tests_paths src/system tests/tests_system src/ci_workflow tests/tests_ci_workflow src/manifests_workflow tests/tests_manifests_workflow'
entry: bash -c 'pipenv run mypy .'
language: system
- id: pytest
stages: [commit]
Expand Down
4 changes: 2 additions & 2 deletions src/build_workflow/build_recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@


class BuildRecorder:
def __init__(self, target: BuildTarget):
def __init__(self, target: BuildTarget) -> None:
self.build_manifest = self.BuildManifestBuilder(target)
self.target = target
self.name = target.name
Expand Down Expand Up @@ -52,7 +52,7 @@ def write_manifest(self) -> None:
logging.info(f"Created build manifest {manifest_path}")

class BuildManifestBuilder:
def __init__(self, target: BuildTarget):
def __init__(self, target: BuildTarget) -> None:
self.data: Dict[str, Any] = {}
self.data["build"] = {}
self.data["build"]["id"] = target.build_id
Expand Down
2 changes: 1 addition & 1 deletion src/build_workflow/build_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __init__(
snapshot: bool = True,
build_id: str = None,
output_dir: str = "artifacts",
):
) -> None:
self.build_id = os.getenv("BUILD_NUMBER") or build_id or uuid.uuid4().hex
self.name = name
self.version = version
Expand Down
4 changes: 4 additions & 0 deletions src/build_workflow/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@


class Builder(ABC):
component: Any
target: BuildTarget
output_path: str

def __init__(self, component: Any, target: BuildTarget) -> None:
self.output_path = "builds"
self.component = component
Expand Down
2 changes: 1 addition & 1 deletion src/ci_workflow/ci_check_list_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def checkout(self, work_dir: str) -> None:
}

class InvalidCheckError(Exception):
def __init__(self, check: Any):
def __init__(self, check: Any) -> None:
self.check = check
super().__init__(f"Invalid check: {check.name}, must be one of {CiCheckListSource.CHECKS.keys()}.")

Expand Down
10 changes: 4 additions & 6 deletions src/manifests/build/build_manifest_1_0.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
# this file be licensed under the Apache-2.0 license or a
# compatible open source license.

from typing import Any

from manifests.component_manifest import Component, ComponentManifest, Components

"""
Expand Down Expand Up @@ -75,7 +73,7 @@ class BuildManifest_1_0(ComponentManifest['BuildManifest_1_0', 'BuildComponents_
},
}

def __init__(self, data: Any):
def __init__(self, data: dict) -> None:
super().__init__(data)
self.build = self.Build(data["build"])
self.components = BuildComponents_1_0(data.get("components", [])) # type: ignore[assignment]
Expand All @@ -88,7 +86,7 @@ def __to_dict__(self) -> dict:
}

class Build:
def __init__(self, data: Any):
def __init__(self, data: dict) -> None:
self.name: str = data["name"]
self.version = data["version"]
self.architecture = data["architecture"]
Expand All @@ -109,12 +107,12 @@ def filename(self) -> str:

class BuildComponents_1_0(Components['BuildComponent_1_0']):
@classmethod
def __create__(self, data: Any) -> 'BuildComponent_1_0':
def __create__(self, data: dict) -> 'BuildComponent_1_0':
return BuildComponent_1_0(data)


class BuildComponent_1_0(Component):
def __init__(self, data: Any):
def __init__(self, data: dict) -> None:
super().__init__(data)
self.repository = data["repository"]
self.ref = data["ref"]
Expand Down
10 changes: 4 additions & 6 deletions src/manifests/build/build_manifest_1_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
# this file be licensed under the Apache-2.0 license or a
# compatible open source license.

from typing import Any

from manifests.component_manifest import Component, ComponentManifest, Components

"""
Expand Down Expand Up @@ -76,7 +74,7 @@ class BuildManifest_1_1(ComponentManifest['BuildManifest_1_1', 'BuildComponents_
},
}

def __init__(self, data: Any):
def __init__(self, data: dict) -> None:
super().__init__(data)
self.build = self.Build(data["build"])
self.components = BuildComponents_1_1(data.get("components", [])) # type: ignore[assignment]
Expand All @@ -89,7 +87,7 @@ def __to_dict__(self) -> dict:
}

class Build:
def __init__(self, data: Any):
def __init__(self, data: dict) -> None:
self.name: str = data["name"]
self.version = data["version"]
self.architecture = data["architecture"]
Expand All @@ -110,12 +108,12 @@ def filename(self) -> str:

class BuildComponents_1_1(Components['BuildComponent_1_1']):
@classmethod
def __create__(self, data: Any) -> 'BuildComponent_1_1':
def __create__(self, data: dict) -> 'BuildComponent_1_1':
return BuildComponent_1_1(data)


class BuildComponent_1_1(Component):
def __init__(self, data: Any):
def __init__(self, data: dict) -> None:
super().__init__(data)
self.repository = data["repository"]
self.ref = data["ref"]
Expand Down
10 changes: 4 additions & 6 deletions src/manifests/build_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
# this file be licensed under the Apache-2.0 license or a
# compatible open source license.

from typing import Any

from manifests.build.build_manifest_1_0 import BuildManifest_1_0
from manifests.build.build_manifest_1_1 import BuildManifest_1_1
from manifests.component_manifest import Component, ComponentManifest, Components
Expand Down Expand Up @@ -89,7 +87,7 @@ class BuildManifest(ComponentManifest['BuildManifest', 'BuildComponents']):
},
}

def __init__(self, data: Any):
def __init__(self, data: dict) -> None:
super().__init__(data)
self.build = self.Build(data["build"])
self.components = BuildComponents(data.get("components", [])) # type: ignore[assignment]
Expand All @@ -102,7 +100,7 @@ def __to_dict__(self) -> dict:
}

class Build:
def __init__(self, data: Any):
def __init__(self, data: dict) -> None:
self.name: str = data["name"]
self.version: str = data["version"]
self.platform: str = data["platform"]
Expand All @@ -127,12 +125,12 @@ def filename(self) -> str:

class BuildComponents(Components['BuildComponent']):
@classmethod
def __create__(self, data: Any) -> 'BuildComponent':
def __create__(self, data: dict) -> 'BuildComponent':
return BuildComponent(data)


class BuildComponent(Component):
def __init__(self, data: Any):
def __init__(self, data: dict) -> None:
super().__init__(data)
self.repository = data["repository"]
self.ref = data["ref"]
Expand Down
10 changes: 4 additions & 6 deletions src/manifests/bundle/bundle_manifest_1_0.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
# this file be licensed under the Apache-2.0 license or a
# compatible open source license.

from typing import Any

from manifests.component_manifest import Component, ComponentManifest, Components


Expand Down Expand Up @@ -59,7 +57,7 @@ class BundleManifest_1_0(ComponentManifest['BundleManifest_1_0', 'BundleComponen
},
}

def __init__(self, data: Any):
def __init__(self, data: dict) -> None:
super().__init__(data)
self.build = self.Build(data["build"])
self.components = BundleComponents_1_0(data.get("components", [])) # type: ignore[assignment]
Expand All @@ -72,7 +70,7 @@ def __to_dict__(self) -> dict:
}

class Build:
def __init__(self, data: Any):
def __init__(self, data: dict) -> None:
self.name = data["name"]
self.version = data["version"]
self.architecture = data["architecture"]
Expand All @@ -91,12 +89,12 @@ def __to_dict__(self) -> dict:

class BundleComponents_1_0(Components):
@classmethod
def __create__(self, data: Any) -> 'BundleComponent_1_0':
def __create__(self, data: dict) -> 'BundleComponent_1_0':
return BundleComponent_1_0(data)


class BundleComponent_1_0(Component):
def __init__(self, data: Any):
def __init__(self, data: dict) -> None:
super().__init__(data)
self.repository = data["repository"]
self.ref = data["ref"]
Expand Down
10 changes: 5 additions & 5 deletions src/manifests/bundle_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# this file be licensed under the Apache-2.0 license or a
# compatible open source license.

from typing import Any, Dict
from typing import Dict

from manifests.bundle.bundle_manifest_1_0 import BundleManifest_1_0
from manifests.component_manifest import Component, ComponentManifest, Components
Expand Down Expand Up @@ -65,7 +65,7 @@ class BundleManifest(ComponentManifest['BundleManifest', 'BundleComponents']):
},
}

def __init__(self, data: Any) -> None:
def __init__(self, data: dict) -> None:
super().__init__(data)
self.build = self.Build(data["build"])
self.components = BundleComponents(data.get("components", [])) # type: ignore[assignment]
Expand All @@ -78,7 +78,7 @@ def __to_dict__(self) -> dict:
}

class Build:
def __init__(self, data: Dict[str, str]):
def __init__(self, data: Dict[str, str]) -> None:
self.name = data["name"]
self.version = data["version"]
self.platform = data["platform"]
Expand All @@ -105,12 +105,12 @@ def filename(self) -> str:

class BundleComponents(Components['BundleComponent']):
@classmethod
def __create__(self, data: Any) -> 'BundleComponent':
def __create__(self, data: dict) -> 'BundleComponent':
return BundleComponent(data)


class BundleComponent(Component):
def __init__(self, data: Any):
def __init__(self, data: dict) -> None:
super().__init__(data)
self.repository = data["repository"]
self.ref = data["ref"]
Expand Down
4 changes: 2 additions & 2 deletions src/manifests/component_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ComponentManifest(Manifest[ManifestType], Generic[ManifestType, Components
}
}

def __init__(self, data: Any) -> None:
def __init__(self, data: dict) -> None:
super().__init__(data)

self.components = Components(data.get("components", [])) # type: ignore[assignment]
Expand All @@ -44,7 +44,7 @@ def __init__(self, data: Dict[Any, Any]) -> None:
super().__init__(map(create_component, data))

@classmethod
def __create__(self, data: Any) -> ComponentType:
def __create__(self, data: dict) -> ComponentType:
return Component(data) # type: ignore[return-value]

def __to_dict__(self) -> List[Dict[Any, Any]]:
Expand Down
2 changes: 1 addition & 1 deletion src/manifests/distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


class DistributionNotFound(Exception):
def __init__(self, urls: List[str]):
def __init__(self, urls: List[str]) -> None:
self.urls = urls
super().__init__(f"Unable to find a distribution under urls {self.urls}")

Expand Down
22 changes: 11 additions & 11 deletions src/manifests/input_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import copy
import itertools
import logging
from typing import Any, Callable, Iterator, List, Optional
from typing import Callable, Iterator, List, Optional

from git.git_repository import GitRepository
from manifests.component_manifest import Component, ComponentManifest, Components
Expand Down Expand Up @@ -101,7 +101,7 @@ class InputManifest(ComponentManifest['InputManifest', 'InputComponents']):
},
}

def __init__(self, data: Any):
def __init__(self, data: dict) -> None:
super().__init__(data)

self.build = self.Build(data["build"])
Expand All @@ -123,14 +123,14 @@ def stable(self) -> 'InputManifest':
return manifest

class Ci:
def __init__(self, data: Any):
def __init__(self, data: dict) -> None:
self.image = None if data is None else self.Image(data.get("image", None))

def __to_dict__(self) -> Optional[dict]:
return None if self.image is None else {"image": self.image.__to_dict__()}

class Image:
def __init__(self, data: Any):
def __init__(self, data: dict) -> None:
self.name = data["name"]
self.args = data.get("args", None)

Expand All @@ -141,7 +141,7 @@ def __to_dict__(self) -> dict:
}

class Build:
def __init__(self, data: Any):
def __init__(self, data: dict) -> None:
self.name: str = data["name"]
self.version = data["version"]
self.qualifier = data.get("qualifier", None)
Expand All @@ -168,7 +168,7 @@ def filename(self) -> str:

class InputComponents(Components['InputComponent']):
@classmethod
def __create__(self, data: Any) -> 'InputComponent':
def __create__(self, data: dict) -> 'InputComponent':
return InputComponent._from(data) # type: ignore[no-any-return]

def __stabilize__(self) -> None:
Expand Down Expand Up @@ -199,13 +199,13 @@ def select(self, focus: List[str] = [], platform: str = None) -> Iterator['Input


class InputComponent(Component):
def __init__(self, data: Any):
def __init__(self, data: dict) -> None:
super().__init__(data)
self.platforms = data.get("platforms", None)
self.checks = list(map(lambda entry: Check(entry), data.get("checks", [])))

@classmethod
def _from(self, data: Any) -> 'InputComponent':
def _from(self, data: dict) -> 'InputComponent':
if "repository" in data:
return InputComponentFromSource(data)
elif "dist" in data:
Expand All @@ -232,7 +232,7 @@ def __stabilize__(self) -> None:


class InputComponentFromSource(InputComponent):
def __init__(self, data: Any) -> None:
def __init__(self, data: dict) -> None:
super().__init__(data)
self.repository = data["repository"]
self.ref = data["ref"]
Expand All @@ -255,7 +255,7 @@ def __to_dict__(self) -> dict:


class InputComponentFromDist(InputComponent):
def __init__(self, data: Any):
def __init__(self, data: dict) -> None:
super().__init__(data)
self.dist = data["dist"]

Expand All @@ -269,7 +269,7 @@ def __to_dict__(self) -> dict:


class Check:
def __init__(self, data: Any) -> None:
def __init__(self, data: dict) -> None:
if isinstance(data, dict):
if len(data) != 1:
raise ValueError(f"Invalid check format: {data}")
Expand Down
Loading