Commit 9f3d8f07 authored by Simon McVittie's avatar Simon McVittie
Browse files

run: Annotate types for mypy


Signed-off-by: Simon McVittie's avatarSimon McVittie <smcv@collabora.com>
parent 26388892
......@@ -88,10 +88,10 @@ _DEBOS_RUNTIMES_RECIPE = os.path.join(
class AptSource:
def __init__(
self,
kind,
uri,
suite,
components=('main',),
kind, # type: str
uri, # type: str
suite, # type: str
components=('main',), # type: typing.Sequence[str]
trusted=False
):
self.kind = kind
......@@ -101,6 +101,7 @@ class AptSource:
self.trusted = trusted
def __eq__(self, other):
# type: (typing.Any) -> bool
if not isinstance(other, AptSource):
return False
......@@ -123,9 +124,10 @@ class AptSource:
@classmethod
def multiple_from_string(
cls,
line,
cls, # type: typing.Type[AptSource]
line, # type: str
):
# type: (...) -> typing.Iterable[AptSource]
line = line.strip()
tokens = line.split()
......@@ -142,9 +144,10 @@ class AptSource:
@classmethod
def from_string(
cls,
line,
cls, # type: typing.Type[AptSource]
line, # type: str
):
# type: (...) -> AptSource
tokens = line.split()
trusted = False
......@@ -173,6 +176,7 @@ class AptSource:
)
def __str__(self):
# type: () -> str
if self.trusted:
maybe_options = ' [trusted=yes]'
else:
......@@ -196,12 +200,14 @@ class Builder:
__multiarch_tuple_cache = {} # type: typing.Dict[str, str]
def __init__(self):
# type: () -> None
#: The Debian suite to use
self.apt_suite = 'stretch'
#: The Flatpak branch to use for the runtime, or None for apt_suite
self.runtime_branch = None
self.runtime_branch = None # type: typing.Optional[str]
#: The Flatpak branch to use for the app
self.app_branch = None
self.app_branch = None # type: typing.Optional[str]
#: The freedesktop.org cache directory
self.xdg_cache_dir = os.getenv(
'XDG_CACHE_HOME', os.path.expanduser('~/.cache'))
......@@ -211,17 +217,18 @@ class Builder:
)
self.ostree_repo = os.path.join(self.build_area, 'ostree-repo')
self.__dpkg_archs = []
self.flatpak_arch = None
self.__dpkg_archs = [] # type: typing.Sequence[str]
self.flatpak_arch = None # type: typing.Optional[str]
self.__primary_dpkg_arch_matches_cache = {}
self.suite_details = {}
self.runtime_details = {}
self.__primary_dpkg_arch_matches_cache = {
} # type: typing.Dict[str, bool]
self.suite_details = {} # type: typing.Dict[str, typing.Any]
self.runtime_details = {} # type: typing.Dict[str, typing.Any]
self.ostree_mode = 'archive-z2'
self.export_bundles = False
self.sources_required = set()
self.sources_required = set() # type: typing.Set[str]
self.strip_source_version_suffix = None
self.apt_keyrings = []
self.apt_keyrings = [] # type: typing.List[str]
#: apt sources to use when building the runtime
self.build_apt_sources = [] # type: typing.List[AptSource]
#: apt sources to leave in /etc/apt/sources.list afterwards
......@@ -235,7 +242,11 @@ class Builder:
self.logger = logger.getChild('Builder')
@staticmethod
def yaml_dump_one_line(data, stream=None):
def yaml_dump_one_line(
data, # type: typing.Any
stream=None, # type: ignore
):
# type: (...) -> typing.Optional[str]
return yaml.safe_dump(
data,
stream=stream,
......@@ -245,6 +256,7 @@ class Builder:
@staticmethod
def get_flatpak_arch(arch=None):
# type: (typing.Optional[str]) -> str
"""
Return the Flatpak architecture name corresponding to uname
result arch.
......@@ -272,6 +284,7 @@ class Builder:
@staticmethod
def other_multiarch(arch):
# type: (str) -> typing.Optional[str]
"""
Return the other architecture that accompanies the given Debian
architecture in a multiarch setup, or None.
......@@ -286,6 +299,7 @@ class Builder:
@staticmethod
def multiarch_tuple(arch):
# type: (str) -> str
"""
Return the multiarch tuple for the given dpkg architecture name.
"""
......@@ -301,6 +315,7 @@ class Builder:
@staticmethod
def dpkg_to_flatpak_arch(arch):
# type: (str) -> str
"""
Return the Flatpak architecture name corresponding to the given
dpkg architecture name.
......@@ -325,6 +340,7 @@ class Builder:
@property
def primary_dpkg_arch(self):
# type: () -> str
"""
The Debian architecture we are building a runtime for, such as
i386 or amd64.
......@@ -333,6 +349,7 @@ class Builder:
@property
def dpkg_archs(self):
# type: () -> typing.Sequence[str]
"""
The Debian architectures we support via multiarch, such as
['amd64', 'i386'].
......@@ -341,10 +358,12 @@ class Builder:
@dpkg_archs.setter
def dpkg_archs(self, value):
# type: (typing.Sequence[str]) -> None
self.__primary_dpkg_arch_matches_cache = {}
self.__dpkg_archs = value
def primary_dpkg_arch_matches(self, arch_spec):
# type: (str) -> bool
"""
Return True if arch_spec matches primary_dpkg_arch (or
equivalently, if primary_dpkg_arch is one of the architectures
......@@ -362,6 +381,7 @@ class Builder:
return self.__primary_dpkg_arch_matches_cache[arch_spec]
def run_command_line(self):
# type: () -> None
"""
Run appropriate commands for the command-line arguments
"""
......@@ -580,14 +600,17 @@ class Builder:
return apt_sources
def command_print_flatpak_architecture(self, **kwargs):
# type: (...) -> None
print(self.flatpak_arch)
def ensure_build_area(self):
# type: () -> None
os.makedirs(self.xdg_cache_dir, 0o700, exist_ok=True)
os.makedirs(self.build_area, 0o755, exist_ok=True)
os.makedirs(os.path.join(self.build_area, 'tmp'), exist_ok=True)
def command_base(self, **kwargs):
# type: (...) -> None
with ExitStack() as stack:
scratch = stack.enter_context(
TemporaryDirectory(prefix='flatdeb.')
......@@ -727,6 +750,7 @@ class Builder:
os.rename(output + '.new', output)
def ensure_local_repo(self):
# type: () -> None
os.makedirs(os.path.dirname(self.ostree_repo), 0o755, exist_ok=True)
subprocess.check_call([
'ostree',
......@@ -736,6 +760,7 @@ class Builder:
])
def escape_variant_id(self, variant_id):
# type: (str) -> str
"""
Return a version of the variant_id that fits in the restricted
character set documented in os-release(5).
......@@ -753,10 +778,11 @@ class Builder:
def command_runtimes(
self,
*,
yaml_file,
yaml_file, # type: str
generate_sysroot_tarball=False,
**kwargs
):
# type: (...) -> None
self.ensure_local_repo()
if self.runtime_branch is None:
......@@ -914,6 +940,9 @@ class Builder:
debug_prefix = artifact_prefix + '-debug'
debug_tarball = debug_prefix + '.tar.gz'
sysroot_prefix = None # type: typing.Optional[str]
sysroot_tarball = None # type: typing.Optional[str]
if generate_sysroot_tarball:
sysroot_prefix = artifact_prefix + '-sysroot'
sysroot_tarball = sysroot_prefix + '.tar.gz'
......@@ -923,9 +952,6 @@ class Builder:
argv.append(
'sysroot_tarball:{}'.format(
sysroot_tarball + '.new'))
else:
sysroot_prefix = None
sysroot_tarball = None
sdk_details = self.runtime_details.get('sdk', {})
sdk_packages = list(sdk_details.get('add_packages', []))
......@@ -1131,6 +1157,7 @@ class Builder:
os.rename(output + '.new', output)
def configure_apt(self, overlay, apt_sources):
# type: (str, typing.Iterable[AptSource]) -> None
"""
Configure apt. We only do this once, so that all chroots
created from the same base have their version numbers
......@@ -1169,11 +1196,12 @@ class Builder:
def create_flatpak_manifest_overlay(
self,
overlay,
prefix,
runtime,
overlay, # type: str
prefix, # type: str
runtime, # type: str
sdk=False,
):
# type: (...) -> None
metadata = os.path.join(overlay, 'metadata')
os.makedirs(os.path.dirname(metadata), 0o755, exist_ok=True)
......@@ -1396,7 +1424,14 @@ class Builder:
keyfile.save_to_file(metadata)
def command_app(self, *, app_branch, yaml_manifest, **kwargs):
def command_app(
self,
*,
app_branch, # type: str
yaml_manifest, # type: str
**kwargs
):
# type: (...) -> None
self.ensure_local_repo()
with open(yaml_manifest, encoding='utf-8') as reader:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment