Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dry module loading #1138

Merged
merged 1 commit into from
Jan 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 24 additions & 89 deletions mathics/builtin/__init__.py
Original file line number Diff line number Diff line change
@@ -1,51 +1,18 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import glob
import importlib
import re
import os.path as osp
from mathics.settings import ENABLE_FILES_MODULE

from mathics.builtin import (
algebra,
arithmetic,
assignment,
attributes,
calculus,
combinatorial,
compilation,
comparison,
constants,
control,
datentime,
diffeqns,
evaluation,
exptrig,
functional,
graphics,
graphics3d,
image,
inout,
integer,
iohooks,
linalg,
lists,
logic,
manipulate,
quantities,
numbertheory,
numeric,
options,
patterns,
plot,
physchemdata,
randomnumbers,
recurrence,
specialfunctions,
scoping,
strings,
structure,
system,
tensors,
xmlformat,
optimization,
)
# Get a list of file in this directory. We'll exclude from the start
# files with leading characters we don't want like __init__ with its leading underscore.
__py_files__ = [
osp.basename(f[0:-3])
for f in glob.glob(osp.join(osp.dirname(__file__), "[a-z]*.py"))
]

from mathics.builtin.base import (
Builtin,
Expand All @@ -57,55 +24,23 @@

from mathics.settings import ENABLE_FILES_MODULE

modules = [
algebra,
arithmetic,
assignment,
attributes,
calculus,
combinatorial,
compilation,
comparison,
constants,
control,
datentime,
diffeqns,
evaluation,
exptrig,
functional,
graphics,
graphics3d,
image,
inout,
integer,
iohooks,
linalg,
lists,
logic,
manipulate,
quantities,
numbertheory,
numeric,
options,
patterns,
plot,
physchemdata,
randomnumbers,
recurrence,
specialfunctions,
scoping,
strings,
structure,
system,
tensors,
xmlformat,
optimization,
exclude_files = set(("files", "codetables", "base", "importexport", "colors"))
module_names = [
f for f in __py_files__ if re.match("^[a-z0-9]+$", f) if f not in exclude_files
]

if ENABLE_FILES_MODULE:
from mathics.builtin import files, importexport
module_names += ["files", "importexport"]

modules = []

modules += [files, importexport]
for module_name in module_names:
try:
module = importlib.import_module("mathics.builtin." + module_name)
except:
# print("XXX", module_name)
continue
modules.append(module)

builtins = []
builtins_by_module = {}
Expand Down
2 changes: 0 additions & 2 deletions mathics/builtin/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -4444,8 +4444,6 @@ class ResetDirectory(Builtin):

def apply(self, evaluation):
"ResetDirectory[]"
global DIRECTORY_STACK

try:
tmp = DIRECTORY_STACK.pop()
except IndexError:
Expand Down