Skip to content

Commit e5410c7

Browse files
authored
Merge pull request #1384 from mathics/fix1379-rebase
Make Python package lxml optional
2 parents 5b85f11 + 2609b57 commit e5410c7

5 files changed

Lines changed: 11 additions & 8 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: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
from mathics.builtin.base import MessageException
1818

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

2324
try:
2425
import lxml.html as lhtml
2526
except ImportError:
26-
print("lxml.html is not available...")
2727
pass
2828

2929

@@ -86,13 +86,12 @@ class ParseError(Exception):
8686
pass
8787

8888

89-
if "__pypy__" in sys.builtin_module_names:
89+
if platform.python_implementation() == "PyPy":
9090

9191
def parse_html_stream(f):
9292
parser = lhtml.HTMLParser(encoding="utf8")
9393
return lhtml.parse(f, parser)
9494

95-
9695
else:
9796

9897
def parse_html_stream(f):
@@ -249,7 +248,7 @@ def traverse(parent):
249248
class DataImport(_DataImport):
250249
"""
251250
>> Import["ExampleData/PrimeMeridian.html", "Data"][[1, 1, 2, 3]]
252-
= {Washington, D.C., 77°03′56.07″ W (1897) or 77°04′02.24″ W (NAD 27) or 77°04′01.16″ W (NAD 83), New Naval Observatory meridian}
251+
= {Washington, D.C., 77...03′56.07″ W (1897) or 77...04′02.24″ W (NAD 27) or 77...04′01.16″ W (NAD 83), New Naval Observatory meridian}
253252
254253
#> Length[Import["ExampleData/PrimeMeridian.html", "Data"]]
255254
= 3

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)