diff --git a/mathics/builtin/files_io/files.py b/mathics/builtin/files_io/files.py
index 7f6919e854..5bbd786660 100644
--- a/mathics/builtin/files_io/files.py
+++ b/mathics/builtin/files_io/files.py
@@ -46,6 +46,7 @@
path_search,
stream_manager,
)
+import mathics
from mathics.builtin.base import Builtin, Predefined, BinaryOperator, PrefixOperator
from mathics.builtin.strings import to_python_encoding
from mathics.builtin.base import MessageException
@@ -57,7 +58,7 @@
INPUTFILE_VAR = ""
TMP_DIR = tempfile.gettempdir()
-
+SymbolPath = Symbol("$Path")
def _channel_to_stream(channel, mode="r"):
if isinstance(channel, String):
@@ -2024,6 +2025,7 @@ def check_options(options):
result = None
pypath = path.get_string_value()
definitions = evaluation.definitions
+ mathics.core.streams.PATH_VAR = SymbolPath.evaluate(evaluation).to_python(string_quotes=False)
try:
if trace_fn:
trace_fn(pypath)
diff --git a/mathics/builtin/files_io/filesystem.py b/mathics/builtin/files_io/filesystem.py
index 6bcde144d9..0c5131bf5a 100644
--- a/mathics/builtin/files_io/filesystem.py
+++ b/mathics/builtin/files_io/filesystem.py
@@ -27,6 +27,7 @@
valid_context_name,
)
+import mathics.core.streams
from mathics.core.streams import (
HOME_DIR,
PATH_VAR,
diff --git a/mathics/builtin/files_io/mainloop.py b/mathics/builtin/files_io/mainloop.py
index 645485ef0f..70a7ebab25 100644
--- a/mathics/builtin/files_io/mainloop.py
+++ b/mathics/builtin/files_io/mainloop.py
@@ -5,9 +5,9 @@
An interactive session operates a loop, called the "main loop" in this way:
- - read input
- - process input
- - format and print results
+ - read input
+
- process input
+
- format and print results
- repeat
diff --git a/mathics/core/expression.py b/mathics/core/expression.py
index a83a1ef268..623c54bab3 100644
--- a/mathics/core/expression.py
+++ b/mathics/core/expression.py
@@ -2617,7 +2617,8 @@ def to_sympy(self, **kwargs):
return self.real.to_sympy() + sympy.I * self.imag.to_sympy()
def to_python(self, *args, **kwargs):
- return complex(self.real.to_python(), self.imag.to_python())
+ return complex(self.real.to_python(*args, **kwargs),
+ self.imag.to_python(*args, **kwargs))
def to_mpmath(self):
return mpmath.mpc(self.real.to_mpmath(), self.imag.to_mpmath())
@@ -2962,7 +2963,11 @@ def to_sympy(self, **kwargs):
return None
def to_python(self, *args, **kwargs) -> str:
- return '"%s"' % self.value # add quotes to distinguish from Symbols
+ if kwargs.get("string_quotes", True):
+ return '"%s"' % self.value # add quotes to distinguish from Symbols
+ else:
+ return self.value
+
def __hash__(self):
return hash(("String", self.value))
diff --git a/test/data/fortytwo.m b/test/data/fortytwo.m
new file mode 100644
index 0000000000..2971d19a3b
--- /dev/null
+++ b/test/data/fortytwo.m
@@ -0,0 +1,2 @@
+(* Example for testing issue #1329 *)
+42
diff --git a/test/test_files.py b/test/test_files.py
index 014a6c2220..15e763cbd7 100644
--- a/test/test_files.py
+++ b/test/test_files.py
@@ -1,7 +1,9 @@
# -*- coding: utf-8 -*-
+import os.path as osp
import sys
from .helper import check_evaluation, evaluate
+
def test_compress():
for text in ("", "abc", " "):
str_expr = f'Uncompress[Compress["{text}"]]'
@@ -20,6 +22,7 @@ def test_unprotected():
if sys.platform not in ("win32",):
+
def test_get_and_put():
temp_filename = evaluate('$TemporaryDirectory<>"/testfile"').to_python()
temp_filename_strip = temp_filename[1:-1]
@@ -27,6 +30,13 @@ def test_get_and_put():
check_evaluation(f"<< {temp_filename_strip}", "40!")
check_evaluation(f"DeleteFile[{temp_filename}]", "Null")
+ def test_get_path_search():
+ # Check that AppendTo[$Path] works in conjunction with Get[]
+ dirname = osp.join(osp.dirname(osp.abspath(__file__)), "data")
+ evaled = evaluate(f"""AppendTo[$Path, "{dirname}"]""")
+ assert evaled.has_form("List", 1, None)
+ check_evaluation('Get["fortytwo.m"]', "42")
+
# I do not know what is it supposed to test with this...
# def test_Inputget_and_put():