Skip to content

Commit d67a0f7

Browse files
authored
Fix bug with cli run failing on MS-Windows file paths (#913)
Hi, could you please review patch to convert cli run paths to posix. It fixes #912. The path was passed verbatim to `load` and MS-Windows path separator chars `\` was treated as escape sequences. The fix also checks if path refers to a real file, so that it avoids forming invalid `load` requests. Tests updated. Thanks Co-authored-by: ikappaki <[email protected]>
1 parent 3979687 commit d67a0f7

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
### Fixed
1515
* Fix a bug where `.` characters were not allowed in keyword names (#899)
1616
* Fix a bug where nested quotation marks were not escaped properly by various print functions and at the REPL (#894)
17+
* Fixed a bug that caused a syntax error when presenting any filepath that includes the MS-Windows `\` file separator to the cli run command (#912)
1718

1819
### Other
1920
* Update Sphinx documentation theme (#909)

src/basilisp/cli.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,12 @@ def eval_str(s: str, ctx: compiler.CompilerContext, ns: runtime.Namespace, eof:
4949

5050
def eval_file(filename: str, ctx: compiler.CompilerContext, ns: runtime.Namespace):
5151
"""Evaluate a file with the given name into a Python module AST node."""
52-
return eval_str(f'(load-file "{filename}")', ctx, ns, eof=object())
52+
if os.path.exists(filename):
53+
return eval_str(
54+
f'(load-file "{Path(filename).as_posix()}")', ctx, ns, eof=object()
55+
)
56+
else:
57+
raise FileNotFoundError(f"Error: The file {filename} does not exist.")
5358

5459

5560
def eval_namespace(

tests/basilisp/cli_test.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,12 +253,23 @@ def test_run_code_with_args(self, run_cli, args: List[str], ret: str):
253253
result = run_cli(["run", "-c", self.cli_args_code, *args])
254254
assert ret == result.lisp_out
255255

256-
def test_run_file(self, isolated_filesystem, run_cli):
256+
def test_run_file_rel(self, isolated_filesystem, run_cli):
257257
with open("test.lpy", mode="w") as f:
258258
f.write("(println (+ 1 2))")
259259
result = run_cli(["run", "test.lpy"])
260260
assert f"3{os.linesep}" == result.lisp_out
261261

262+
def test_run_file_abs(self, isolated_filesystem, run_cli):
263+
with open("test.lpy", mode="w") as f:
264+
f.write("(println (+ 1 3))")
265+
full_path = os.path.abspath("test.lpy")
266+
result = run_cli(["run", full_path])
267+
assert f"4{os.linesep}" == result.lisp_out
268+
269+
def test_run_file_not_found(self, isolated_filesystem, run_cli):
270+
with pytest.raises(FileNotFoundError):
271+
run_cli(["run", "xyz.lpy"])
272+
262273
def test_run_file_main_ns(self, isolated_filesystem, run_cli):
263274
with open("test.lpy", mode="w") as f:
264275
f.write("(println *main-ns*)")

0 commit comments

Comments
 (0)