Skip to content

Commit d3b4dc9

Browse files
committed
Set $InputFileName inside Get[]
1 parent 7ab2271 commit d3b4dc9

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

mathics/builtin/files.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from itertools import chain
2424

2525

26-
from mathics.core.expression import (Expression, Real, Complex, String, Symbol,
26+
from mathics.core.expression import (Expression, Real, Complex, String, Symbol, SymbolNull,
2727
from_python, Integer, BoxError,
2828
MachineReal, Number, valid_context_name)
2929
from mathics.core.numbers import dps
@@ -2122,14 +2122,17 @@ def apply(self, path, evaluation, options):
21222122
trace_fn = py_options["TraceFn"]
21232123
result = None
21242124
pypath = path.get_string_value()
2125+
definitions = evaluation.definitions
2126+
old_path = definitions.get_ownvalue("System`$InputFilename") or String("")
21252127
try:
21262128
if trace_fn:
21272129
trace_fn(pypath)
21282130
with mathics_open(pypath, 'r') as f:
2131+
definitions.set_ownvalue("System`$InputFileName", String(pypath))
21292132
feeder = FileLineFeeder(f, trace_fn)
21302133
while not feeder.empty():
21312134
try:
2132-
query = parse(evaluation.definitions, feeder)
2135+
query = parse(definitions, feeder)
21332136
except TranslateError:
21342137
return Symbol('Null')
21352138
finally:
@@ -2143,6 +2146,8 @@ def apply(self, path, evaluation, options):
21432146
except MessageException as e:
21442147
e.message(evaluation)
21452148
return Symbol('$Failed')
2149+
finally:
2150+
definitions.set_ownvalue("System`$InputFileName", old_path)
21462151
return result
21472152

21482153
def apply_default(self, filename, evaluation):

0 commit comments

Comments
 (0)