Popen_safe and wrappers can accept os.PathLike for cwd
Do not require users to convert it to a string first. This is a waste of time and effort for exactly the same results.
This commit is contained in:
parent
dd4e712024
commit
d73e81c77b
|
@ -185,14 +185,14 @@ class GitException(MesonException):
|
||||||
self.output = output.strip() if output else ''
|
self.output = output.strip() if output else ''
|
||||||
|
|
||||||
GIT = shutil.which('git')
|
GIT = shutil.which('git')
|
||||||
def git(cmd: T.List[str], workingdir: str, check: bool = False, **kwargs: T.Any) -> T.Tuple[subprocess.Popen, str, str]:
|
def git(cmd: T.List[str], workingdir: T.Union[str, bytes, os.PathLike], check: bool = False, **kwargs: T.Any) -> T.Tuple[subprocess.Popen, str, str]:
|
||||||
cmd = [GIT] + cmd
|
cmd = [GIT] + cmd
|
||||||
p, o, e = Popen_safe(cmd, cwd=workingdir, **kwargs)
|
p, o, e = Popen_safe(cmd, cwd=workingdir, **kwargs)
|
||||||
if check and p.returncode != 0:
|
if check and p.returncode != 0:
|
||||||
raise GitException('Git command failed: ' + str(cmd), e)
|
raise GitException('Git command failed: ' + str(cmd), e)
|
||||||
return p, o, e
|
return p, o, e
|
||||||
|
|
||||||
def quiet_git(cmd: T.List[str], workingdir: str, check: bool = False) -> T.Tuple[bool, str]:
|
def quiet_git(cmd: T.List[str], workingdir: T.Union[str, bytes, os.PathLike], check: bool = False) -> T.Tuple[bool, str]:
|
||||||
if not GIT:
|
if not GIT:
|
||||||
m = 'Git program not found.'
|
m = 'Git program not found.'
|
||||||
if check:
|
if check:
|
||||||
|
@ -203,7 +203,7 @@ def quiet_git(cmd: T.List[str], workingdir: str, check: bool = False) -> T.Tuple
|
||||||
return False, e
|
return False, e
|
||||||
return True, o
|
return True, o
|
||||||
|
|
||||||
def verbose_git(cmd: T.List[str], workingdir: str, check: bool = False) -> bool:
|
def verbose_git(cmd: T.List[str], workingdir: T.Union[str, bytes, os.PathLike], check: bool = False) -> bool:
|
||||||
if not GIT:
|
if not GIT:
|
||||||
m = 'Git program not found.'
|
m = 'Git program not found.'
|
||||||
if check:
|
if check:
|
||||||
|
|
|
@ -205,7 +205,7 @@ class ExternalProject(NewExtensionModule):
|
||||||
output.flush()
|
output.flush()
|
||||||
else:
|
else:
|
||||||
mlog.log(m)
|
mlog.log(m)
|
||||||
p, *_ = Popen_safe(command, cwd=str(workdir), env=self.run_env,
|
p, *_ = Popen_safe(command, cwd=workdir, env=self.run_env,
|
||||||
stderr=subprocess.STDOUT,
|
stderr=subprocess.STDOUT,
|
||||||
stdout=output)
|
stdout=output)
|
||||||
if p.returncode != 0:
|
if p.returncode != 0:
|
||||||
|
|
Loading…
Reference in New Issue