Skip to content

Commit 8794e5a

Browse files
authored
Merge pull request #1439 from TiagoCavalcanteTrindade/remove-notebook-from-settings
Remove System`$Notebooks from settings.m
2 parents 4e61b94 + 3235eed commit 8794e5a

File tree

4 files changed

+61
-19
lines changed

4 files changed

+61
-19
lines changed

mathics/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,18 @@
5050
if "cython" in version_info:
5151
version_string += f", cython {version_info['cython']}"
5252

53+
54+
def load_default_settings_files(definitions, load_cli_settings: bool = True):
55+
import os.path as osp
56+
from mathics.core.definitions import autoload_files
57+
58+
root_dir = osp.realpath(osp.dirname(__file__))
59+
60+
autoload_files(definitions, root_dir, "autoload", False)
61+
if load_cli_settings:
62+
autoload_files(definitions, root_dir, "autoload-cli", False)
63+
64+
5365
license_string = """\
5466
Copyright (C) 2011-2021 The Mathics Team.
5567
This program comes with ABSOLUTELY NO WARRANTY.

mathics/autoload/settings.m

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,3 @@
1010
Settings`$PreferredBackendMethod::usage = "Set this do whether to use mpmath, numpy or Sympy for numeric and symbolic constants and methods when there is a choice";
1111
Settings`$PreferredBackendMethod = "sympy"
1212
Unprotect[Settings`$PreferredBackendMethod]
13-
14-
(* FIXME: remove this when all front-ends are adjusted to set this. *)
15-
(* Some packages like Feyncalc, test for whether a they are being used
16-
inside a notbook. *)
17-
System`$Notebooks::usage = "Set True if the Mathics is being used with a notebook-based front end.";
18-
System`$Notebooks = False;
19-
Unprotect[System`$Notebooks];

mathics/core/definitions.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,25 +41,31 @@ def valuesname(name) -> str:
4141
return name[7:-6].lower()
4242

4343

44-
def autoload_files(defs, root_dir_path: str, autoload_dir):
44+
def autoload_files(
45+
defs,
46+
root_dir_path: str,
47+
autoload_dir: str,
48+
block_global_definitions: bool = True
49+
):
4550
from mathics.core.evaluation import Evaluation
4651

4752
# Load symbols from the autoload folder
4853
for root, dirs, files in os.walk(os.path.join(root_dir_path, autoload_dir)):
4954
for path in [os.path.join(root, f) for f in files if f.endswith(".m")]:
5055
Expression("Get", String(path)).evaluate(Evaluation(defs))
5156

52-
# Move any user definitions created by autoloaded files to
53-
# builtins, and clear out the user definitions list. This
54-
# means that any autoloaded definitions become shared
55-
# between users and no longer disappear after a Quit[].
56-
#
57-
# Autoloads that accidentally define a name in Global`
58-
# could cause confusion, so check for this.
59-
#
60-
for name in defs.user:
61-
if name.startswith("Global`"):
62-
raise ValueError("autoload defined %s." % name)
57+
if block_global_definitions:
58+
# Move any user definitions created by autoloaded files to
59+
# builtins, and clear out the user definitions list. This
60+
# means that any autoloaded definitions become shared
61+
# between users and no longer disappear after a Quit[].
62+
#
63+
# Autoloads that accidentally define a name in Global`
64+
# could cause confusion, so check for this.
65+
66+
for name in defs.user:
67+
if name.startswith("Global`"):
68+
raise ValueError("autoload defined %s." % name)
6369

6470

6571
class PyMathicsLoadException(Exception):

test/test_settings.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# -*- coding: utf-8 -*-
2+
from .helper import session
3+
from mathics import load_default_settings_files
4+
5+
6+
def test_settings():
7+
load_default_settings_files(session.definitions)
8+
9+
assert type(session.evaluate("Settings`$TraceGet").to_python()) is bool
10+
11+
assert (
12+
session.evaluate("Settings`$TraceGet::usage").to_python()
13+
!= "Settings`$TraceGet::usage"
14+
)
15+
16+
assert (
17+
session.evaluate("Settings`$PreferredBackendMethod::usage").to_python()
18+
!= "Settings`$PreferredBackendMethod::usage"
19+
)
20+
21+
assert type(session.evaluate("Settings`$PreferredBackendMethod").to_python()) is str
22+
23+
assert (
24+
session.evaluate("System`$Notebooks::usage").to_python()
25+
!= "System`$Notebooks::usage"
26+
)
27+
28+
29+
def test_is_not_notebook():
30+
# the settings already were loaded
31+
assert session.evaluate("System`$Notebooks").to_python() == False

0 commit comments

Comments
 (0)