Skip to content

Commit dfc6f64

Browse files
committed
Make Python package lxml optional
Fixes #1378
1 parent f6fd7e6 commit dfc6f64

5 files changed

Lines changed: 12 additions & 16 deletions

File tree

mathics/builtin/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
PrecisionReal,
2424
String,
2525
Symbol,
26-
SymbolTrue,
2726
SymbolFalse,
27+
SymbolTrue,
2828
ensure_context,
2929
strip_context,
3030
)

mathics/builtin/fileformats/htmlformat.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,15 @@
1717
from mathics.builtin.base import MessageException
1818

1919
from io import BytesIO
20+
import platform
2021
import re
21-
import sys
2222

2323

2424
try:
2525
import lxml.html as lhtml
2626

2727
lhtml_available = True
2828
except ImportError:
29-
from mathics.builtin.fileformats.xmlformat import parse_xml_stream
30-
3129
lhtml_available = False
3230

3331

@@ -90,22 +88,16 @@ class ParseError(Exception):
9088
pass
9189

9290

93-
if "__pypy__" in sys.builtin_module_names:
91+
if platform.python_implementation() == "PyPy":
9492

9593
def parse_html_stream(f):
96-
if lhtml_available:
97-
parser = lhtml.HTMLParser(encoding="utf8")
98-
return lhtml.parse(f, parser)
99-
else:
100-
return parse_xml_stream(f)
94+
parser = lhtml.HTMLParser(encoding="utf8")
95+
return lhtml.parse(f, parser)
10196

10297
else:
10398

10499
def parse_html_stream(f):
105-
if lhtml_available:
106-
return lhtml.parse(f)
107-
else:
108-
return parse_xml_stream(f)
100+
return lhtml.parse(f)
109101

110102

111103
def parse_html_file(filename):

mathics/builtin/inout.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1930,7 +1930,7 @@ class General(Builtin):
19301930
"syntax": "`1`",
19311931
"invalidargs": "Invalid arguments.",
19321932
"notboxes": "`1` is not a valid box structure.",
1933-
"pyimport": '`1`[] is not available. Your Python installation misses the "`2`" module.',
1933+
"pyimport": '`1`[] is not available. Python module "`2`" is not installed.',
19341934
}
19351935

19361936

mathics/builtin/lists.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,6 +1117,8 @@ def apply_makeboxes(self, list, i, f, evaluation):
11171117
def apply(self, list, i, evaluation):
11181118
"Part[list_, i___]"
11191119

1120+
if list == SymbolFailed:
1121+
return
11201122
indices = i.get_sequence()
11211123
# How to deal with ByteArrays
11221124
if list.get_head_name() == "System`ByteArray":

setup.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ def read(*rnames):
102102
"requests",
103103
"scikit-image",
104104
"wordcloud", # Used in builtin/image.py by WordCloud()
105-
"lxml", # Used in builtin/fileformats/html
105+
106+
# lxml is an optional dependency for HTML parsing
107+
# "lxml", # Used in builtin/fileformats/html
106108
]
107109

108110

0 commit comments

Comments
 (0)