diff options
author | Wojtek Kosior <koszko@koszko.org> | 2022-10-11 10:26:55 +0200 |
---|---|---|
committer | Wojtek Kosior <koszko@koszko.org> | 2022-10-11 13:12:11 +0200 |
commit | 0c8d70daae4c4dfc989edad465db94ffc665416d (patch) | |
tree | 86f1b23e863b2dae1efd00686d46890b4b72ccb2 /src/hydrilla/builder | |
parent | 9074d98f711b6ccc099df8bccb1ed28390bcf0da (diff) | |
download | haketilo-hydrilla-0c8d70daae4c4dfc989edad465db94ffc665416d.tar.gz haketilo-hydrilla-0c8d70daae4c4dfc989edad465db94ffc665416d.zip |
[builder][server] restore compatibility with python 3.7
Diffstat (limited to 'src/hydrilla/builder')
-rw-r--r-- | src/hydrilla/builder/build.py | 18 | ||||
-rw-r--r-- | src/hydrilla/builder/local_apt.py | 15 | ||||
-rw-r--r-- | src/hydrilla/builder/piggybacking.py | 14 |
3 files changed, 26 insertions, 21 deletions
diff --git a/src/hydrilla/builder/build.py b/src/hydrilla/builder/build.py index 58225d4..8a97a20 100644 --- a/src/hydrilla/builder/build.py +++ b/src/hydrilla/builder/build.py @@ -101,7 +101,7 @@ class FileRef: self.contents_hash = sha256(contents).digest().hex() - def make_ref_dict(self) -> dict[str, str]: + def make_ref_dict(self) -> t.Dict[str, str]: """ Represent the file reference through a dict that can be included in JSON defintions. @@ -154,9 +154,9 @@ class Build: if piggyback_default_path.exists(): self.piggyback_files = piggyback_default_path - self.files_by_path: dict[PurePosixPath, FileRef] = {} - self.resource_list: list[dict] = [] - self.mapping_list: list[dict] = [] + self.files_by_path: t.Dict[PurePosixPath, FileRef] = {} + self.resource_list: t.List[dict] = [] + self.mapping_list: t.List[dict] = [] if not index_json_path.is_absolute(): index_json_path = (self.srcdir / index_json_path) @@ -170,14 +170,14 @@ class Build: FileRef(index_desired_path, index_json_path.read_bytes()) # We know from successful validation that instance is a dict. - self._process_index_json(t.cast('dict[str, t.Any]', index_obj)) + self._process_index_json(t.cast('t.Dict[str, t.Any]', index_obj)) def _process_file( self, filename: t.Union[str, PurePosixPath], piggybacked: Piggybacked, include_in_distribution: bool = True - ) -> dict[str, str]: + ) -> t.Dict[str, str]: """ Resolve 'filename' relative to srcdir, load it to memory (if not loaded before), compute its hash and store its information in @@ -207,7 +207,9 @@ class Build: path = piggybacked.resolve_file(desired_path) if path is None: path = (self.srcdir / desired_path).resolve() - if not path.is_relative_to(self.srcdir): + try: + path.relative_to(self.srcdir) + except ValueError: raise FileReferenceError(_('loading_{}_outside_package_dir') .format(filename)) @@ -270,7 +272,7 @@ class Build: as_what: str, item_def: dict, piggybacked: Piggybacked - ) -> dict[str, t.Any]: + ) -> t.Dict[str, t.Any]: """ Process 'item_def' as definition of a resource or mapping (determined by 'as_what' param) and store in memory its processed form and files used diff --git a/src/hydrilla/builder/local_apt.py b/src/hydrilla/builder/local_apt.py index 925fd61..385a533 100644 --- a/src/hydrilla/builder/local_apt.py +++ b/src/hydrilla/builder/local_apt.py @@ -143,7 +143,7 @@ class SourcesList: """Representation of apt's sources.list contents.""" def __init__( self, - list: list[str] = [], + list: t.List[str] = [], codename: t.Optional[str] = None ) -> None: """Initialize this SourcesList.""" @@ -187,7 +187,7 @@ pkgCacheGen::Essential "none"; Dir::Etc::Trusted "{directory}/etc/trusted.gpg"; ''' -def apt_keyring(keys: list[str]) -> bytes: +def apt_keyring(keys: t.List[str]) -> bytes: """ Download the requested keys if necessary and export them as a keyring suitable for passing to APT. @@ -234,7 +234,8 @@ def cache_apt_root(apt_root: Path, destination_zip: Path) -> None: if temporary_zip_path is not None and temporary_zip_path.exists(): temporary_zip_path.unlink() -def setup_local_apt(directory: Path, list: SourcesList, keys: list[str]) -> Apt: +def setup_local_apt(directory: Path, list: SourcesList, keys: t.List[str]) \ + -> Apt: """ Create files and directories necessary for running APT without root rights inside 'directory'. @@ -282,7 +283,7 @@ def setup_local_apt(directory: Path, list: SourcesList, keys: list[str]) -> Apt: return apt @contextmanager -def local_apt(list: SourcesList, keys: list[str]) -> t.Iterator[Apt]: +def local_apt(list: SourcesList, keys: t.List[str]) -> t.Iterator[Apt]: """ Create a temporary directory with proper local APT configuration in it. Yield an Apt object that can be used to issue apt-get commands. @@ -296,11 +297,11 @@ def local_apt(list: SourcesList, keys: list[str]) -> t.Iterator[Apt]: def download_apt_packages( list: SourcesList, - keys: list[str], - packages: list[str], + keys: t.List[str], + packages: t.List[str], destination_dir: Path, with_deps: bool -) -> list[str]: +) -> t.List[str]: """ Set up a local APT, update it using the specified sources.list configuration and use it to download the specified packages. diff --git a/src/hydrilla/builder/piggybacking.py b/src/hydrilla/builder/piggybacking.py index 3e4084f..c152135 100644 --- a/src/hydrilla/builder/piggybacking.py +++ b/src/hydrilla/builder/piggybacking.py @@ -52,10 +52,10 @@ class Piggybacked: """ def __init__( self, - archives: dict[str, Path] = {}, - roots: dict[str, Path] = {}, - package_license_files: list[PurePosixPath] = [], - resource_must_depend: list[dict] = [] + archives: t.Dict[str, Path] = {}, + roots: t.Dict[str, Path] = {}, + package_license_files: t.List[PurePosixPath] = [], + resource_must_depend: t.List[dict] = [] ) -> None: """ Initialize this Piggybacked object. @@ -106,13 +106,15 @@ class Piggybacked: path = path.resolve() - if not path.is_relative_to(root_path): + try: + path.relative_to(root_path) + except ValueError: raise FileReferenceError(_('loading_{}_outside_piggybacked_dir') .format(file_ref_name)) return path - def archive_files(self) -> t.Iterator[tuple[PurePosixPath, Path]]: + def archive_files(self) -> t.Iterator[t.Tuple[PurePosixPath, Path]]: """ Yield all archive files in use. Each yielded tuple holds file's desired path relative to the piggybacked archives directory to be created and |