Skip to content

Commit

Permalink
Moved INPUTFILE_VAR as attribute in Definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
Alessandro Piras committed Feb 5, 2024
1 parent 132be71 commit f36c73f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
3 changes: 1 addition & 2 deletions mathics/builtin/files_io/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from mathics_scanner import TranslateError

import mathics
from mathics.core import read
from mathics.core.atoms import Integer, String, SymbolString
from mathics.core.attributes import A_PROTECTED, A_READ_PROTECTED
from mathics.core.builtin import (
Expand Down Expand Up @@ -465,7 +464,7 @@ class InputFileName_(Predefined):
name = "$InputFileName"

def evaluate(self, evaluation):
return String(read.INPUTFILE_VAR)
return String(evaluation.definitions.get_inputfile_dir())


class InputStream(Builtin):
Expand Down
7 changes: 7 additions & 0 deletions mathics/core/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ def __init__(
"System`",
"Global`",
)
self.inputfile = ""

# Importing "mathics.format" populates the Symbol of the
# PrintForms and OutputForms sets.
Expand Down Expand Up @@ -243,6 +244,9 @@ def get_current_context(self):
def get_context_path(self):
return self.context_path

def get_inputfile(self):
return self.inputfile

def set_current_context(self, context) -> None:
assert isinstance(context, str)
self.set_ownvalue("System`$Context", String(context))
Expand All @@ -259,6 +263,9 @@ def set_context_path(self, context_path) -> None:
self.context_path = context_path
self.clear_cache()

def set_inputfile(self, dir) -> None:
self.inputfile = dir

def get_builtin_names(self):
return set(self.builtin)

Expand Down
5 changes: 0 additions & 5 deletions mathics/core/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,3 @@ def read_from_stream(stream, word_separators, msgfn, accepted=None):
break

word += tmp


def set_inputfile(filename):
global INPUTFILE_VAR
INPUTFILE_VAR = filename
6 changes: 4 additions & 2 deletions mathics/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from mathics.core.expression import Expression
from mathics.core.load_builtin import import_and_load_builtins
from mathics.core.parser import MathicsFileLineFeeder, MathicsLineFeeder
from mathics.core.read import channel_to_stream, set_inputfile
from mathics.core.read import channel_to_stream
from mathics.core.rules import BuiltinRule
from mathics.core.streams import stream_manager
from mathics.core.symbols import SymbolNull, strip_context
Expand Down Expand Up @@ -423,7 +423,7 @@ def dump_tracing_stats():
definitions.set_line_no(0)

if args.FILE is not None:
set_inputfile(args.FILE.name)
definitions.set_inputfile(args.FILE.name)
feeder = MathicsFileLineFeeder(args.FILE)
try:
while not feeder.empty():
Expand All @@ -443,6 +443,8 @@ def dump_tracing_stats():
definitions.set_line_no(0)
elif not args.execute:
return exit_rc
else:
definitions.set_inputfile("")

if args.execute:

Expand Down

0 comments on commit f36c73f

Please sign in to comment.