Skip to content

Commit

Permalink
Support older pythons
Browse files Browse the repository at this point in the history
  • Loading branch information
singiamtel committed Nov 22, 2024
1 parent f56a6fd commit ad3935e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions alibuild_helpers/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
from textwrap import dedent
from subprocess import TimeoutExpired
from shlex import quote
from typing import Union, Tuple, List

from alibuild_helpers.log import debug, warning, dieOnError

def decode_with_fallback(data : bytes | str) -> str:
def decode_with_fallback(data : Union[bytes, str]) -> str:
"""Try to decode DATA as utf-8; if that doesn't work, fall back to latin-1.
This combination should cover every possible byte string, as latin-1 covers
Expand Down Expand Up @@ -37,7 +38,7 @@ def getoutput(command:str, timeout=None) -> str:
return decode_with_fallback(stdout)


def getstatusoutput(command:str, timeout: int | None = None) -> tuple[int, str]:
def getstatusoutput(command:str, timeout: Union[int, None] = None) -> Tuple[int, str]:
"""Run command and return its return code and output (stdout and stderr)."""
proc = Popen(command, shell=isinstance(command, str), stdout=PIPE, stderr=STDOUT)
try:
Expand All @@ -54,7 +55,7 @@ def getstatusoutput(command:str, timeout: int | None = None) -> tuple[int, str]:
return proc.returncode, merged_output


def execute(command: str | list[str], printer=debug, timeout:int | None =None) -> int:
def execute(command: Union[str, List[str]], printer=debug, timeout:Union[int, None] =None) -> int:
popen = Popen(command, shell=isinstance(command, str), stdout=PIPE, stderr=STDOUT)
start_time = time.time()
assert popen.stdout is not None, "Could not open stdout for command"
Expand Down
4 changes: 2 additions & 2 deletions alibuild_helpers/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from alibuild_helpers.cmd import execute
from alibuild_helpers.log import debug, info, error, dieOnError, ProgressPrint
from alibuild_helpers.utilities import resolve_store_path, resolve_links_path, symlink
from typing import TypeAlias
from typing import Union

class NoRemoteSync:
"""Helper class which does not do anything to sync"""
Expand Down Expand Up @@ -677,7 +677,7 @@ def upload_symlinks_and_tarball(self, spec):
self.s3.upload_file(Bucket=self.writeStore, Key=tar_path,
Filename=os.path.join(self.workdir, tar_path))

RemoteSync: TypeAlias = HttpRemoteSync | S3RemoteSync | Boto3RemoteSync | CVMFSRemoteSync | RsyncRemoteSync | NoRemoteSync
RemoteSync = Union[HttpRemoteSync, S3RemoteSync, Boto3RemoteSync, CVMFSRemoteSync, RsyncRemoteSync, NoRemoteSync]

def remote_from_url(read_url: str, write_url: str, architecture: str, work_dir: str, insecure=False) -> RemoteSync:
"""Parse remote store URLs and return the correct RemoteSync instance for them."""
Expand Down

0 comments on commit ad3935e

Please sign in to comment.