-
-
Notifications
You must be signed in to change notification settings - Fork 177
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
Fix problem with Win10 shell #560
Changes from all commits
37fbc05
4ac389a
a3f28c6
1317de2
c468527
e8c7fe3
e18b93f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
PathLike = Union[str, os.PathLike] | ||
|
||
IS_POSIX = os.name == "posix" | ||
IS_WINDOWS = sys.platform == "win32" | ||
|
||
# The following default flags were borrowed from Github's docs: | ||
# https://docs.github.com/en/github/getting-started-with-github/associating-text-editors-with-git | ||
|
@@ -61,7 +62,12 @@ class ShellCommand: | |
character, ``command`` needs to be properly quoted. | ||
""" | ||
|
||
def __init__(self, command: str, shell: bool = True, cwd: Optional[str] = None): | ||
def __init__( | ||
self, | ||
command: str, | ||
shell: bool = True, | ||
cwd: Optional[str] = None, | ||
): | ||
self._command = command | ||
self._shell = shell | ||
self._cwd = cwd | ||
|
@@ -81,6 +87,11 @@ def run(self, *args, **kwargs) -> subprocess.CompletedProcess: | |
"stdout": subprocess.PIPE, | ||
"stderr": subprocess.STDOUT, | ||
"universal_newlines": True, | ||
"env": { | ||
**os.environ, | ||
# try to disable i18n | ||
**dict(LC_ALL="C", LANGUAGE=""), | ||
}, | ||
**kwargs, # allow overwriting defaults | ||
} | ||
if self._shell: | ||
|
@@ -91,16 +102,22 @@ def run(self, *args, **kwargs) -> subprocess.CompletedProcess: | |
|
||
def __call__(self, *args, **kwargs) -> Iterator[str]: | ||
"""Execute the command, returning an iterator for the resulting text output""" | ||
completed = self.run(*args, **kwargs) | ||
try: | ||
completed = self.run(*args, **kwargs) | ||
except FileNotFoundError as e: | ||
msg = f"{e.strerror}: {e.filename}" | ||
logger.debug(f'last command failed with "{msg}"') | ||
raise ShellCommandException(msg) from e | ||
|
||
try: | ||
completed.check_returncode() | ||
except subprocess.CalledProcessError as ex: | ||
except subprocess.CalledProcessError as e: | ||
stdout, stderr = (e or "" for e in (completed.stdout, completed.stderr)) | ||
stdout, stderr = (e.strip() for e in (stdout, stderr)) | ||
sep = " :: " if stdout and stderr else "" | ||
sep = "; " if stdout and stderr else "" | ||
msg = sep.join([stdout, stderr]) | ||
logger.debug(f'last command failed with "{msg}"') | ||
raise ShellCommandException(msg) from ex | ||
raise ShellCommandException(msg) from e | ||
|
||
return (line for line in (completed.stdout or "").splitlines()) | ||
|
||
|
@@ -132,10 +149,10 @@ def get_git_cmd(**args): | |
Args: | ||
**args: additional keyword arguments to :obj:`~.ShellCommand` | ||
""" | ||
if sys.platform == "win32": # pragma: no cover | ||
if IS_WINDOWS: # pragma: no cover | ||
# ^ CI setup does not aggregate Windows coverage | ||
for cmd in ["git.cmd", "git.exe"]: | ||
git = ShellCommand(cmd, **args) | ||
for shell in (True, False): | ||
git = ShellCommand("git.exe", shell=shell, **args) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am very curious to understand what is happening for the command with Would be a problem with file names? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea, I am also very curious about this. We only now that one of @ksteptoe's two Windows machines seem to have a problem with the shell setup. Somehow an |
||
try: | ||
git("--version") | ||
except ShellCommandException: | ||
|
@@ -238,7 +255,7 @@ def edit(file: PathLike, *args, **kwargs) -> Path: | |
|
||
def join(parts: Iterable[Union[str, PathLike]]) -> str: | ||
"""Join different parts of a shell command into a string, quoting whitespaces.""" | ||
if sys.platform == "win32": # pragma: no cover | ||
if IS_WINDOWS: # pragma: no cover | ||
# ^ CI setup does not aggregate Windows coverage | ||
return subprocess.list2cmdline(map(str, parts)) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand from this removal that
"git.cmd"
is no longer necessary, and that we expect any distribution of git for Windows to add a.exe
to the PATH, right?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I was actually trying to find
git.cmd
by googling but had no luck. There is a "git CMD" but no "git.cmd" so maybe it was a mistake? Also setuptools-scm doesn't seem to be doing this, so at least we would fail both.