Skip to content

Commit

Permalink
Fix compiler configuration path resolution (#1617)
Browse files Browse the repository at this point in the history
Move the call to `os.chdir` to change working directory at the
last possible minute. Fixes #1614.

When a custom compiler configuration file is used Pyccel cannot change
the file name to an absolute path as we do not immediately know whether
the argument contains a path or simply a key word indicating the
compiler family. This should not cause problems, as long as the working
directory remains unchanged. As the working directory was changed to
the `__pyccel__` folder too early, we encountered the problem reported in
pyccel/psydac#341 (comment).
  • Loading branch information
EmilyBourne committed Nov 22, 2023
1 parent d01083b commit f884e24
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ All notable changes to this project will be documented in this file.
- #1553 : Fix `np.sign` when using the `ifort` compiler.
- #1582 : Allow homogeneous tuples in classes.
- #1619 : Give priority to imported functions over builtin functions.
- #1614 : Allow relative paths for custom compilation file.

### Changed

Expand Down
6 changes: 3 additions & 3 deletions pyccel/codegen/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,6 @@ def handle_error(stage):
if not (syntax_only or semantic_only):
os.makedirs(pyccel_dirpath, exist_ok=True)

# Change working directory to 'folder'
os.chdir(folder)

if conda_warnings not in ('off', 'basic', 'verbose'):
raise ValueError("conda warnings accept {off, basic,verbose}")

Expand All @@ -196,6 +193,9 @@ def handle_error(stage):

Scope.name_clash_checker = name_clash_checkers[language]

# Change working directory to 'folder'
os.chdir(folder)

# Parse Python file
try:
parser = Parser(pymod_filepath)
Expand Down
10 changes: 9 additions & 1 deletion tests/pyccel/test_pyccel.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def get_python_output(abs_path, cwd = None):
def compile_pyccel(path_dir, test_file, options = ""):
if "python" in options and "--output" not in options:
options += " --output=__pyccel__"
cmd = [shutil.which("pyccel"), "%s" % test_file]
cmd = [shutil.which("pyccel"), test_file]
if options != "":
cmd += options.strip().split()
p = subprocess.Popen(cmd, universal_newlines=True, cwd=path_dir)
Expand Down Expand Up @@ -1048,6 +1048,7 @@ def test_inline_import(language):
language = language)

#------------------------------------------------------------------------------
@pytest.mark.xdist_incompatible
def test_json():
pyccel_test("scripts/runtest_funcs.py", language = 'fortran',
pyccel_commands='--export-compile-info test.json')
Expand All @@ -1060,6 +1061,13 @@ def test_json():

assert dict_1 == dict_2

@pytest.mark.xdist_incompatible
def test_json_relative_path():
pyccel_test("scripts/runtest_funcs.py", language = 'fortran',
pyccel_commands='--export-compile-info test.json')
shutil.move(get_abs_path('scripts/test.json'), get_abs_path('scripts/hope_benchmarks/test.json'))
compile_pyccel(get_abs_path('scripts/hope_benchmarks'), "../runtest_funcs.py", '--compiler test.json')

#------------------------------------------------------------------------------
def test_reserved_file_name():
with pytest.raises(ValueError) as exc_info:
Expand Down

0 comments on commit f884e24

Please sign in to comment.