forked from gnu-octave/symbolic
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
private/python_ipc_system: Convert to Cygwin path when needed.
This should fix some errors when Python is running in Cygwin-like environment. But there could still be errors in other places. See gnu-octave#1182. * inst/private/cygpath.m: New function. * inst/private/python_env_is_cygwin_like.m: New function. * inst/private/python_ipc_system.m: Use them.
- Loading branch information
Alex Vong
authored and
Alex Vong
committed
Jul 30, 2022
1 parent
1b9849e
commit 9558e9a
Showing
3 changed files
with
101 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
%% Copyright (C) 2022 Alex Vong | ||
%% | ||
%% This file is part of OctSymPy. | ||
%% | ||
%% OctSymPy is free software; you can redistribute it and/or modify | ||
%% it under the terms of the GNU General Public License as published | ||
%% by the Free Software Foundation; either version 3 of the License, | ||
%% or (at your option) any later version. | ||
%% | ||
%% This software is distributed in the hope that it will be useful, | ||
%% but WITHOUT ANY WARRANTY; without even the implied warranty | ||
%% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See | ||
%% the GNU General Public License for more details. | ||
%% | ||
%% You should have received a copy of the GNU General Public | ||
%% License along with this software; see the file COPYING. | ||
%% If not, see <https://www.gnu.org/licenses/>. | ||
|
||
%% -*- texinfo -*- | ||
%% @defun cygpath () | ||
%% Convert Windows native path to Cygwin POSIX-style path. | ||
%% | ||
%% @seealso{python_env_is_cygwin_like} | ||
%% @end defun | ||
|
||
function posix_path = cygpath (native_path) | ||
%% FIXME: only allow safe characters inside "..." | ||
if ~isempty (strfind (native_path, '"')) | ||
error ('cygpath: native path %s must not contain "', native_path); | ||
end | ||
|
||
[status, out] = system (['cygpath -u "' native_path '"']); | ||
if status ~= 0 | ||
error ('cygpath: cygpath exited with status %d', status); | ||
end | ||
|
||
%% validate output | ||
assert (ischar (out) && logical (regexp (out, '^[^\r\n]+[\r]?[\n]$'))); | ||
posix_path = regexprep (out, '[\r]?[\n]$', ''); % strip trailing newline | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
%% Copyright (C) 2022 Alex Vong | ||
%% | ||
%% This file is part of OctSymPy. | ||
%% | ||
%% OctSymPy is free software; you can redistribute it and/or modify | ||
%% it under the terms of the GNU General Public License as published | ||
%% by the Free Software Foundation; either version 3 of the License, | ||
%% or (at your option) any later version. | ||
%% | ||
%% This software is distributed in the hope that it will be useful, | ||
%% but WITHOUT ANY WARRANTY; without even the implied warranty | ||
%% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See | ||
%% the GNU General Public License for more details. | ||
%% | ||
%% You should have received a copy of the GNU General Public | ||
%% License along with this software; see the file COPYING. | ||
%% If not, see <https://www.gnu.org/licenses/>. | ||
|
||
%% -*- texinfo -*- | ||
%% @defun python_env_is_cygwin_like (pyexec) | ||
%% Check if Python @var{pyexec} is running in a Cygwin-like POSIX environment, | ||
%% such as Cygwin or MSYS2. The result is memoized to speed up subsequent | ||
%% calls. | ||
%% | ||
%% @seealso{cygpath} | ||
%% @end defun | ||
|
||
function r = python_env_is_cygwin_like (pyexec) | ||
persistent python_env_is_cygwin_like_memo | ||
|
||
if ~isempty (python_env_is_cygwin_like_memo) | ||
r = python_env_is_cygwin_like_memo; | ||
elseif ispc () | ||
if system ('where /q cygpath') ~= 0 | ||
r = false; | ||
python_env_is_cygwin_like_memo = r; | ||
return | ||
end | ||
|
||
[status, out] = system ([pyexec ' -c "import os; print(os.name)"']); | ||
if status ~= 0 | ||
error ('python_env_is_cygwin_like: %s exited with status %d', ... | ||
pyexec, status); | ||
end | ||
assert (ischar (out)); | ||
|
||
r = ~isempty (regexp(out, 'posix', 'match')); | ||
python_env_is_cygwin_like_memo = r; | ||
else | ||
r = false; | ||
python_env_is_cygwin_like_memo = r; | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters