Skip to content

Commit d937268

Browse files
authored
Merge pull request #1338 from mathics/file-module
Segregate I/O, Files, and Filesystem builtins
2 parents 8f45adc + b565064 commit d937268

10 files changed

Lines changed: 263 additions & 240 deletions

File tree

mathics/builtin/__init__.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,22 +116,25 @@ def is_builtin(var):
116116

117117

118118
# FIXME: redo using importlib since that is probably less fragile.
119-
exclude_files = set(("files", "codetables", "base", "importexport", "colors"))
119+
exclude_files = set(("codetables", "base"))
120120
module_names = [
121121
f for f in __py_files__ if re.match("^[a-z0-9]+$", f) if f not in exclude_files
122122
]
123123

124-
if ENABLE_FILES_MODULE:
125-
module_names += ["files", "importexport"]
126-
127124
modules = []
128125
import_builtins(module_names)
129126

130127
_builtins = []
131128
builtins_by_module = {}
132129

133-
for subdir in ("drawing", "numbers", "specialfns",):
130+
disable_file_module_names = [] if ENABLE_FILES_MODULE else ["files_io.files", "files_io.importexport"]
131+
132+
for subdir in ("drawing", "files_io", "numbers", "specialfns",):
134133
import_name = f"{__name__}.{subdir}"
134+
135+
if import_name in disable_file_module_names:
136+
continue
137+
135138
builtin_module = importlib.import_module(import_name)
136139
submodule_names = [
137140
modname

mathics/builtin/evaluation.py

Lines changed: 0 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -317,145 +317,6 @@ class Sequence(Builtin):
317317
"""
318318

319319

320-
class Line(Builtin):
321-
"""
322-
<dl>
323-
<dt>'$Line'
324-
<dd>holds the current input line number.
325-
</dl>
326-
>> $Line
327-
= 1
328-
>> $Line
329-
= 2
330-
>> $Line = 12;
331-
>> 2 * 5
332-
= 10
333-
>> Out[13]
334-
= 10
335-
>> $Line = -1;
336-
: Non-negative integer expected.
337-
"""
338-
339-
name = "$Line"
340-
341-
342-
class HistoryLength(Builtin):
343-
"""
344-
<dl>
345-
<dt>'$HistoryLength'
346-
<dd>specifies the maximum number of 'In' and 'Out' entries.
347-
</dl>
348-
>> $HistoryLength
349-
= 100
350-
>> $HistoryLength = 1;
351-
>> 42
352-
= 42
353-
>> %
354-
= 42
355-
>> %%
356-
= %3
357-
>> $HistoryLength = 0;
358-
>> 42
359-
= 42
360-
>> %
361-
= %7
362-
"""
363-
364-
name = "$HistoryLength"
365-
366-
rules = {
367-
"$HistoryLength": "100",
368-
}
369-
370-
371-
class In(Builtin):
372-
"""
373-
<dl>
374-
<dt>'In[$k$]'
375-
<dd>gives the $k$th line of input.
376-
</dl>
377-
>> x = 1
378-
= 1
379-
>> x = x + 1
380-
= 2
381-
>> Do[In[2], {3}]
382-
>> x
383-
= 5
384-
>> In[-1]
385-
= 5
386-
>> Definition[In]
387-
= Attributes[In] = {Listable, Protected}
388-
.
389-
. In[6] = Definition[In]
390-
.
391-
. In[5] = In[-1]
392-
.
393-
. In[4] = x
394-
.
395-
. In[3] = Do[In[2], {3}]
396-
.
397-
. In[2] = x = x + 1
398-
.
399-
. In[1] = x = 1
400-
"""
401-
402-
attributes = ("Listable", "Protected")
403-
404-
rules = {
405-
"In[k_Integer?Negative]": "In[$Line + k]",
406-
}
407-
408-
409-
class Out(Builtin):
410-
"""
411-
<dl>
412-
<dt>'Out[$k$]'
413-
<dt>'%$k$'
414-
<dd>gives the result of the $k$th input line.
415-
<dt>'%', '%%', etc.
416-
<dd>gives the result of the previous input line, of the line before the previous input line, etc.
417-
</dl>
418-
419-
>> 42
420-
= 42
421-
>> %
422-
= 42
423-
>> 43;
424-
>> %
425-
= 43
426-
>> 44
427-
= 44
428-
>> %1
429-
= 42
430-
>> %%
431-
= 44
432-
>> Hold[Out[-1]]
433-
= Hold[%]
434-
>> Hold[%4]
435-
= Hold[%4]
436-
>> Out[0]
437-
= Out[0]
438-
439-
#> 10
440-
= 10
441-
#> Out[-1] + 1
442-
= 11
443-
#> Out[] + 1
444-
= 12
445-
"""
446-
447-
attributes = ("Listable", "Protected")
448-
449-
rules = {
450-
"Out[k_Integer?Negative]": "Out[$Line + k]",
451-
"Out[]": "Out[$Line - 1]",
452-
"MakeBoxes[Out[k_Integer?((-10 <= # < 0)&)],"
453-
" f:StandardForm|TraditionalForm|InputForm|OutputForm]": r'StringJoin[ConstantArray["%%", -k]]',
454-
"MakeBoxes[Out[k_Integer?Positive],"
455-
" f:StandardForm|TraditionalForm|InputForm|OutputForm]": r'"%%" <> ToString[k]',
456-
}
457-
458-
459320
class Quit(Builtin):
460321
"""
461322
<dl>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"""
2+
Input/Output, Files, and Filesystem
3+
"""
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
)
3838

3939
from mathics.builtin.base import Builtin, Predefined
40-
from mathics.builtin.files import (
40+
from mathics.builtin.files_io.files import (
4141
DIRECTORY_STACK,
4242
INITIAL_DIR, # noqa is used via global
4343
mathics_open
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
get_option,
2828
)
2929

30-
from .pymimesniffer import magic
30+
from mathics.builtin.pymimesniffer import magic
3131
import mimetypes
3232
import sys
3333
from itertools import chain

0 commit comments

Comments
 (0)