Skip to content

Commit 5d01a3a

Browse files
committed
Move load_settings out of __init__...
Add access routines to get and set Settings.
1 parent b99d2d6 commit 5d01a3a

File tree

4 files changed

+48
-13
lines changed

4 files changed

+48
-13
lines changed

mathics/__init__.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,6 @@
5151
version_string += f", cython {version_info['cython']}"
5252

5353

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-
6554
license_string = """\
6655
Copyright (C) 2011-2021 The Mathics Team.
6756
This program comes with ABSOLUTELY NO WARRANTY.

mathics/session.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,55 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
This module contains routines to simplify front-end use.
4+
5+
In particular we provide:
6+
7+
* a class to create a Mathics session,
8+
* load the Mathics core settings files (written in WL),
9+
* read and set Mathics Settings.
10+
"""
11+
12+
import os.path as osp
13+
from mathics.core.definitions import autoload_files
114
from mathics.core.parser import parse, MathicsSingleLineFeeder
215
from mathics.core.definitions import Definitions
316
from mathics.core.evaluation import Evaluation
417

518

19+
def load_default_settings_files(
20+
definitions: Definitions, load_cli_settings: bool = True
21+
):
22+
"""
23+
Loads the system default settings for Mathics core.
24+
25+
Other settings files may get loaded later and override these
26+
defaults.
27+
"""
28+
root_dir = osp.realpath(osp.dirname(__file__))
29+
30+
autoload_files(definitions, root_dir, "autoload", False)
31+
if load_cli_settings:
32+
autoload_files(definitions, root_dir, "autoload-cli", False)
33+
34+
35+
def get_settings_value(definitions: Definitions, setting_name: str):
36+
"""Get a Mathics Settings` value with name "setting_name" from definitions."""
37+
return definitions.get_ownvalue(setting_name).replace.to_python(string_quotes=False)
38+
39+
40+
def set_settings_value(definitions: Definitions, setting_name: str, value):
41+
"""Set a Mathics Settings` with name "setting_name" from definitions to value
42+
"value".
43+
"""
44+
return definitions.set_ownvalue(setting_name, value)
45+
46+
647
class MathicsSession:
48+
"""A session stores definitions or evaluation results. This class
49+
also simplifies the common activity of reading as string, parsing
50+
it and evaluating it in the context of the current session.
51+
"""
52+
753
def __init__(self, add_builtin=True, catch_interrupt=False, form="InputForm"):
854
self.definitions = Definitions(add_builtin)
955
self.evaluation = Evaluation(

mathics/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
# well as importing into Python. That's why there is no
66
# space around "=" below.
77
# fmt: off
8-
__version__="3.0.1.dev0" # noqa
8+
__version__="3.1.0.dev0" # noqa

test/test_settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22
from .helper import session
3-
from mathics import load_default_settings_files
3+
from mathics.session import load_default_settings_files
44

55

66
def test_settings():

0 commit comments

Comments
 (0)