summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLisandro Dalcin <dalcinl@gmail.com>2023-04-30 14:02:48 +0400
committerGitHub <noreply@github.com>2023-04-30 13:02:48 +0300
commit10cf5f6e18dbce625d32407a857cc06dd2cec637 (patch)
tree1afb328f9e119340e2a36f55a2bf7d4a68de9677
parentcdce132997b60ace744da88572ee457e3a9444de (diff)
downloadcython-10cf5f6e18dbce625d32407a857cc06dd2cec637.tar.gz
CmdLine: Fix regression when using the `--working` option (GH-5365)
Checking for the existence of source files must account for the user-specified working directory. If the source filename is not absolute, prepend the working directory if specified, then perform the check.
-rw-r--r--Cython/Compiler/CmdLine.py4
-rw-r--r--Cython/Compiler/Tests/TestCmdLine.py12
2 files changed, 15 insertions, 1 deletions
diff --git a/Cython/Compiler/CmdLine.py b/Cython/Compiler/CmdLine.py
index c330fcc05..776636c32 100644
--- a/Cython/Compiler/CmdLine.py
+++ b/Cython/Compiler/CmdLine.py
@@ -215,7 +215,11 @@ def parse_command_line_raw(parser, args):
def parse_command_line(args):
parser = create_cython_argparser()
arguments, sources = parse_command_line_raw(parser, args)
+
+ work_dir = getattr(arguments, 'working_path', '')
for source in sources:
+ if work_dir and not os.path.isabs(source):
+ source = os.path.join(work_dir, source)
if not os.path.exists(source):
import errno
raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), source)
diff --git a/Cython/Compiler/Tests/TestCmdLine.py b/Cython/Compiler/Tests/TestCmdLine.py
index 0961dfa03..290efd1d7 100644
--- a/Cython/Compiler/Tests/TestCmdLine.py
+++ b/Cython/Compiler/Tests/TestCmdLine.py
@@ -20,7 +20,17 @@ unpatched_exists = os.path.exists
def patched_exists(path):
# avoid the Cython command raising a file not found error
- if path in ('source.pyx', 'file.pyx', 'file1.pyx', 'file2.pyx', 'file3.pyx', 'foo.pyx', 'bar.pyx'):
+ if path in (
+ 'source.pyx',
+ os.path.join('/work/dir', 'source.pyx'),
+ os.path.join('my_working_path', 'source.pyx'),
+ 'file.pyx',
+ 'file1.pyx',
+ 'file2.pyx',
+ 'file3.pyx',
+ 'foo.pyx',
+ 'bar.pyx',
+ ):
return True
return unpatched_exists(path)