mozilla/moz-sql-parser

Broken at import

Closed this issue · 9 comments

lores commented

Import of moz-sql-parser fails with 'Error: expecting same'

$ pip3 install moz-sql-parser
Defaulting to user installation because normal site-packages is not writeable
Collecting moz-sql-parser
Downloading moz-sql-parser-4.18.21031.tar.gz (68 kB)
|████████████████████████████████| 68 kB 3.2 MB/s
Collecting mo-dots==4.2.20340
Downloading mo-dots-4.2.20340.tar.gz (17 kB)
Collecting mo-future==3.147.20327
Downloading mo-future-3.147.20327.tar.gz (4.3 kB)
Collecting mo-logs==4.3.20340
Downloading mo-logs-4.3.20340.tar.gz (37 kB)
Collecting mo-imports==3.149.20327
Downloading mo-imports-3.149.20327.tar.gz (5.4 kB)
Collecting mo-kwargs==3.93.20259
Downloading mo-kwargs-3.93.20259.tar.gz (6.4 kB)
Building wheels for collected packages: moz-sql-parser, mo-dots, mo-future, mo-imports, mo-logs, mo-kwargs
Building wheel for moz-sql-parser (setup.py) ... done
Created wheel for moz-sql-parser: filename=moz_sql_parser-4.18.21031-py3-none-any.whl size=76363 sha256=2e5f805cc924c4b3578ae8d813da32c37bdb820be830cee13cecb2901f003ba9
Stored in directory: /home/flatline/.cache/pip/wheels/59/e9/c1/979028906228bd1867db592dc5e9979c4539201e3bf6b70c8f
Building wheel for mo-dots (setup.py) ... done
Created wheel for mo-dots: filename=mo_dots-4.2.20340-py3-none-any.whl size=19740 sha256=84015664d7d973275915d93db637a548638ae5a22172f8f134f12c22ec66eb59
Stored in directory: /home/flatline/.cache/pip/wheels/91/78/99/cbefcaf98760af8b753e1489b7efc55d7e16e074b767180f1a
Building wheel for mo-future (setup.py) ... done
Created wheel for mo-future: filename=mo_future-3.147.20327-py3-none-any.whl size=4516 sha256=1d8fc0cc3ad8c3523bc0015e3d501a43ad21840531813efcb84fee184b1b73d5
Stored in directory: /home/flatline/.cache/pip/wheels/c1/26/d1/e8d3078d4e9b58c63830ed261dd4ecf36933f4749a2370e1f2
Building wheel for mo-imports (setup.py) ... done
Created wheel for mo-imports: filename=mo_imports-3.149.20327-py3-none-any.whl size=5088 sha256=3a776656a1c50494b006369053625edb80108ba5239763274c0e9d2f0266466f
Stored in directory: /home/flatline/.cache/pip/wheels/5d/34/43/2788a6b98c178f8c0fd3b74f55b3490a22fcedcd0c09c806e4
Building wheel for mo-logs (setup.py) ... done
Created wheel for mo-logs: filename=mo_logs-4.3.20340-py3-none-any.whl size=39452 sha256=61e1d0b67bd3eb4e41a4cccd36b356adfb3216753936c9a53458f51a88a120db
Stored in directory: /home/flatline/.cache/pip/wheels/2c/39/be/7fcef666b27418f80e358e450a136bbad4bcbdd169eb3bb78c
Building wheel for mo-kwargs (setup.py) ... done
Created wheel for mo-kwargs: filename=mo_kwargs-3.93.20259-py3-none-any.whl size=6656 sha256=2020939a6f1e7e5de6f6c90932a3600d407ec16ef8f4fdc7b45090ee79b8ca97
Stored in directory: /home/flatline/.cache/pip/wheels/91/4f/e0/52766d643c807edb177e16bd1cc441940967b1e593a1580280
Successfully built moz-sql-parser mo-dots mo-future mo-imports mo-logs mo-kwargs
Installing collected packages: mo-future, mo-imports, mo-dots, mo-kwargs, mo-logs, moz-sql-parser
Successfully installed mo-dots-4.2.20340 mo-future-3.147.20327 mo-imports-3.149.20327 mo-kwargs-3.93.20259 mo-logs-4.3.20340 moz-sql-parser-4.18.21031

$ python3
Python 3.6.9 (default, Oct 8 2020, 12:12:24)
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
$$$ import moz_sql_parser
Traceback (most recent call last):
File "", line 1, in
File "/home/flatline/.local/lib/python3.6/site-packages/moz_sql_parser/init.py", line 15, in
from moz_sql_parser.sql_parser import SQLParser, scrub_literal, scrub
File "/home/flatline/.local/lib/python3.6/site-packages/moz_sql_parser/sql_parser.py", line 12, in
from mo_parsing.engine import Engine
File "/home/flatline/.local/lib/python3.6/site-packages/mo_parsing/init.py", line 55, in
from mo_parsing.regex import Regex
File "/home/flatline/.local/lib/python3.6/site-packages/mo_parsing/regex.py", line 192, in
simple_char = Word(printables, exclude=r".^$*+{}[]|()").addParseAction(lambda t: Literal(t.value()))
File "/home/flatline/.local/lib/python3.6/site-packages/mo_parsing/tokens.py", line 307, in init
init_chars, exclude=exclude
File "/home/flatline/.local/lib/python3.6/site-packages/mo_parsing/tokens.py", line 374, in init
regex = regex_range(include)
File "/home/flatline/.local/lib/python3.6/site-packages/mo_parsing/utils.py", line 137, in regex_range
acc.append(esc(start))
File "/home/flatline/.local/lib/python3.6/site-packages/mo_parsing/utils.py", line 118, in esc
Log.error("expecting same")
File "/home/flatline/.local/lib/python3.6/site-packages/mo_logs/init.py", line 407, in error
raise_from_none(e)
File "", line 2, in raise_from_none
mo_logs.exceptions.Except: ERROR: expecting same
File "/home/flatline/.local/lib/python3.6/site-packages/mo_parsing/utils.py", line 118, in esc
File "/home/flatline/.local/lib/python3.6/site-packages/mo_parsing/utils.py", line 137, in regex_range
File "/home/flatline/.local/lib/python3.6/site-packages/mo_parsing/tokens.py", line 374, in init
File "/home/flatline/.local/lib/python3.6/site-packages/mo_parsing/tokens.py", line 307, in init
File "/home/flatline/.local/lib/python3.6/site-packages/mo_parsing/regex.py", line 192, in
File "", line 219, in _call_with_frames_removed
File "", line 678, in exec_module
File "", line 665, in _load_unlocked
File "", line 955, in _find_and_load_unlocked
File "", line 971, in _find_and_load
File "/home/flatline/.local/lib/python3.6/site-packages/mo_parsing/init.py", line 55, in
File "", line 219, in _call_with_frames_removed
File "", line 678, in exec_module
File "", line 665, in _load_unlocked
File "", line 955, in _find_and_load_unlocked
File "", line 971, in _find_and_load
File "", line 219, in _call_with_frames_removed
File "", line 941, in _find_and_load_unlocked
File "", line 971, in _find_and_load
File "/home/flatline/.local/lib/python3.6/site-packages/moz_sql_parser/sql_parser.py", line 12, in
File "", line 219, in _call_with_frames_removed
File "", line 678, in exec_module
File "", line 665, in _load_unlocked
File "", line 955, in _find_and_load_unlocked
File "", line 971, in _find_and_load
File "/home/flatline/.local/lib/python3.6/site-packages/moz_sql_parser/init.py", line 15, in
File "", line 219, in _call_with_frames_removed
File "", line 678, in exec_module
File "", line 665, in _load_unlocked
File "", line 955, in _find_and_load_unlocked
File "", line 971, in _find_and_load
File "", line 1, in

Thank you for this. Looking at it...

@lores It seems 3.6.* only have source downloads, so it will be hard for me to verify this. Looking at the line numbers in the stack trace They seem wrong, as if it is running code from more than one version. Still looking....

It might be related to internationalization. It appears to be failing on this line

simple_char = Word(
    printables, exclude=r".^$*+{}[]\|()"
).addParseAction(lambda t: Literal(t.value()))

The printables seem to be the problem

printables = "".join(c for c in string.printable if c not in string.whitespace)

May you send me what you get for printables? Run this

import string
import json

print(json.dumps("".join(c for c in string.printable if c not in string.whitespace)))

Here is what I get


C:\Users\kyle\code\moz-sql-parser>python
Python 3.7.8 (tags/v3.7.8:4b47a5b6ba, Jun 28 2020, 08:53:46) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import string
>>> import json
>>>
>>> print(json.dumps("".join(c for c in string.printable if c not in string.whitespace)))
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"
>>>
>>>

thank you

lores commented
lores commented

I can confirm the problem seems specific to 3.6 - it does not happen on the same machine with freshly installed pythons 3.7 or 3.8, but does on a fresh 3.6 install.

@lores Thank you for your time looking into this.

It may be the Python regex library. What do you get for

import string
import re

print(re.escape("".join(c for c in string.printable if c not in string.whitespace)))

Here is my run

C:\Users\kyle>python
Python 3.7.8 (tags/v3.7.8:4b47a5b6ba, Jun 28 2020, 08:53:46) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import string
>>> import re
>>>
>>> print(re.escape("".join(c for c in string.printable if c not in string.whitespace)))
0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"\#\$%\&'\(\)\*\+,\-\./:;<=>\?@\[\\\]\^_`\{\|\}\~
lores commented

Sure, here it is:

Python 3.6.9 (default, Oct  8 2020, 12:12:24) 
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import string
>>> import re
>>> 
>>> print(re.escape("".join(c for c in string.printable if c not in string.whitespace)))
0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\!\"\#\$\%\&\'\(\)\*\+\,\-\.\/\:\;\<\=\>\?\@\[\\\]\^_\`\{\|\}\~
>>> 

@lores please confirm it is fixed with https://pypi.org/project/moz-sql-parser/4.21.21059/

Thank you.

@lores if this is fixed, please close this issue. Thank you.