Skip to content

Commit c280808

Browse files
authored
Merge pull request #996 from mathics/pymathics-fixup
PyMathics fixups
2 parents 5263aa8 + d8ecaef commit c280808

File tree

20 files changed

+413
-2385
lines changed

20 files changed

+413
-2385
lines changed

mathics/builtin/assignment.py

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1692,23 +1692,6 @@ class LoadModule(Builtin):
16921692
>> LoadModule["sys"]
16931693
: Python module sys is not a pymathics module.
16941694
= $Failed
1695-
# >> LoadModule["pymathics.testpymathicsmodule"]
1696-
# = pymathics.testpymathicsmodule
1697-
# >> MyPyTestContext`MyPyTestFunction[a]
1698-
# = This is a PyMathics output
1699-
# >> MyPyTestContext`MyPyTestSymbol
1700-
# = 1234
1701-
# >> ?? MyPyTestContext`MyPyTestFunction
1702-
# =
1703-
# . 'MyPyTestFunction'[m]
1704-
# . Just an example function in pymathics module.
1705-
# .
1706-
# . Attributes[MyPyTestContext`MyPyTestFunction] = {HoldFirst, OneIdentity, Protected}
1707-
# >> Quit[]
1708-
#n>> MyPyTestContext`MyPyTestSymbol
1709-
# = MyPyTestContext`MyPyTestSymbol
1710-
# >> ?? MyPyTestContext`MyPyTestFunction
1711-
# = Null
17121695
"""
17131696
name = "LoadModule"
17141697
messages = {'notfound': 'Python module `1` does not exist.',
@@ -1727,4 +1710,17 @@ def apply(self, module, evaluation):
17271710
except PyMathicsLoadException as e:
17281711
evaluation.message(self.get_name(), 'notmathicslib', module)
17291712
return Symbol('$Failed')
1713+
else:
1714+
# Add PyMathics` to $ContextPath so that when user don't
1715+
# have to qualify PyMathics variables and functions,
1716+
# as the those in teh module just loaded.
1717+
1718+
# Following the example of $ContextPath in the WL
1719+
# reference manual where PackletManager appears first in
1720+
# the list, it seems to be preferable to add this PyMathics
1721+
# at the beginning.
1722+
context_path = evaluation.definitions.get_context_path()
1723+
if "PyMathics`" not in context_path:
1724+
context_path.insert(0, "PyMathics`")
1725+
evaluation.definitions.set_context_path(context_path)
17301726
return module

0 commit comments

Comments
 (0)