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

Optional lexpr in A_Expr printer #54

Merged
merged 2 commits into from
May 8, 2020

Conversation

aiham
Copy link
Contributor

@aiham aiham commented May 6, 2020

Fixes #53

This allows lexpr to be missing in A_Expr printer so it can print queries like SELECT -(1+1).

Notes:

  • As far as I can tell this is only appropriate for AEXPR_OP, not the other expression kinds.
  • I considered raising an Exception if node.name isn't -, +, or ~ but I'm worried there are other valid cases I don't know about so I left it more permissive.
  • Wrapped $PATH in the Makefile with quotes to handle spaces. I couldn't run make commands without this. Happy to split into another PR if strictly necessary.
  • I'm targeting master instead of v2 since its a bug fix that applies to v1.

@aiham
Copy link
Contributor Author

aiham commented May 6, 2020

I couldn't run tests. make build completes successfully. You should consider using github actions to run tests for all PRs.

$ make check
Bootstrapping Python 3 virtualenv...
Upgrading pip...
Collecting pip
  Downloading https://files.pythonhosted.org/packages/54/2e/df11ea7e23e7e761d484ed3740285a34e38548cf2bad2bed3dd5768ec8b9/pip-20.1-py2.py3-none-any.whl (1.5MB)
     |████████████████████████████████| 1.5MB 4.3MB/s
Installing collected packages: pip
  Found existing installation: pip 19.2.3
    Uninstalling pip-19.2.3:
      Successfully uninstalled pip-19.2.3
Successfully installed pip-20.1
Installing pre-requirements...
Ignoring aenum: markers 'python_version < "3.6"' don't match your environment
Collecting coverage==4.5.4
  Downloading coverage-4.5.4-cp37-cp37m-macosx_10_13_x86_64.whl (181 kB)
     |████████████████████████████████| 181 kB 3.8 MB/s
Collecting pytest-cov==2.7.1
  Downloading pytest_cov-2.7.1-py2.py3-none-any.whl (17 kB)
Collecting pytest==5.1.2
  Downloading pytest-5.1.2-py3-none-any.whl (224 kB)
     |████████████████████████████████| 224 kB 11.4 MB/s
Collecting cython==0.29.13
  Downloading Cython-0.29.13-cp37-cp37m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (2.9 MB)
     |████████████████████████████████| 2.9 MB 11.8 MB/s
Collecting metapensiero.tool.bump_version==1.3
  Downloading metapensiero.tool.bump_version-1.3.tar.gz (5.7 kB)
Collecting pycparser==2.19
  Downloading pycparser-2.19.tar.gz (158 kB)
     |████████████████████████████████| 158 kB 11.5 MB/s
Collecting readme_renderer==24.0
  Downloading readme_renderer-24.0-py2.py3-none-any.whl (15 kB)
Collecting sphinx==1.8.5
  Downloading Sphinx-1.8.5-py2.py3-none-any.whl (3.1 MB)
     |████████████████████████████████| 3.1 MB 18.3 MB/s
Collecting twine==1.13.0
  Downloading twine-1.13.0-py2.py3-none-any.whl (34 kB)
Collecting attrs>=17.4.0
  Downloading attrs-19.3.0-py2.py3-none-any.whl (39 kB)
Collecting importlib-metadata>=0.12; python_version < "3.8"
  Downloading importlib_metadata-1.6.0-py2.py3-none-any.whl (30 kB)
Collecting packaging
  Downloading packaging-20.3-py2.py3-none-any.whl (37 kB)
Collecting more-itertools>=4.0.0
  Downloading more_itertools-8.2.0-py3-none-any.whl (43 kB)
     |████████████████████████████████| 43 kB 19.6 MB/s
Collecting atomicwrites>=1.0
  Downloading atomicwrites-1.4.0-py2.py3-none-any.whl (6.8 kB)
Collecting py>=1.5.0
  Downloading py-1.8.1-py2.py3-none-any.whl (83 kB)
     |████████████████████████████████| 83 kB 16.0 MB/s
Collecting pluggy<1.0,>=0.12
  Downloading pluggy-0.13.1-py2.py3-none-any.whl (18 kB)
Collecting wcwidth
  Downloading wcwidth-0.1.9-py2.py3-none-any.whl (19 kB)
Requirement already satisfied: setuptools in ./env/lib/python3.7/site-packages (from metapensiero.tool.bump_version==1.3->-r requirements.txt (line 12)) (41.2.0)
Collecting Versio
  Downloading Versio-0.4.0.tar.gz (21 kB)
Collecting Pygments
  Downloading Pygments-2.6.1-py3-none-any.whl (914 kB)
     |████████████████████████████████| 914 kB 12.6 MB/s
Collecting docutils>=0.13.1
  Downloading docutils-0.16-py2.py3-none-any.whl (548 kB)
     |████████████████████████████████| 548 kB 22.3 MB/s
Collecting bleach>=2.1.0
  Downloading bleach-3.1.5-py2.py3-none-any.whl (151 kB)
     |████████████████████████████████| 151 kB 9.6 MB/s
Collecting six
  Downloading six-1.14.0-py2.py3-none-any.whl (10 kB)
Collecting sphinxcontrib-websupport
  Downloading sphinxcontrib_websupport-1.2.2-py2.py3-none-any.whl (39 kB)
Collecting Jinja2>=2.3
  Downloading Jinja2-2.11.2-py2.py3-none-any.whl (125 kB)
     |████████████████████████████████| 125 kB 14.3 MB/s
Collecting alabaster<0.8,>=0.7
  Downloading alabaster-0.7.12-py2.py3-none-any.whl (14 kB)
Collecting imagesize
  Downloading imagesize-1.2.0-py2.py3-none-any.whl (4.8 kB)
Collecting requests>=2.0.0
  Downloading requests-2.23.0-py2.py3-none-any.whl (58 kB)
     |████████████████████████████████| 58 kB 21.8 MB/s
Collecting babel!=2.0,>=1.3
  Downloading Babel-2.8.0-py2.py3-none-any.whl (8.6 MB)
     |████████████████████████████████| 8.6 MB 18.3 MB/s
Collecting snowballstemmer>=1.1
  Downloading snowballstemmer-2.0.0-py2.py3-none-any.whl (97 kB)
     |████████████████████████████████| 97 kB 12.0 MB/s
Collecting pkginfo>=1.4.2
  Downloading pkginfo-1.5.0.1-py2.py3-none-any.whl (25 kB)
Collecting requests-toolbelt!=0.9.0,>=0.8.0
  Downloading requests_toolbelt-0.9.1-py2.py3-none-any.whl (54 kB)
     |████████████████████████████████| 54 kB 19.7 MB/s
Collecting tqdm>=4.14
  Downloading tqdm-4.46.0-py2.py3-none-any.whl (63 kB)
     |████████████████████████████████| 63 kB 22.9 MB/s
Collecting zipp>=0.5
  Downloading zipp-3.1.0-py3-none-any.whl (4.9 kB)
Collecting pyparsing>=2.0.2
  Downloading pyparsing-2.4.7-py2.py3-none-any.whl (67 kB)
     |████████████████████████████████| 67 kB 14.6 MB/s
Collecting webencodings
  Downloading webencodings-0.5.1-py2.py3-none-any.whl (11 kB)
Collecting MarkupSafe>=0.23
  Downloading MarkupSafe-1.1.1-cp37-cp37m-macosx_10_6_intel.whl (18 kB)
Collecting idna<3,>=2.5
  Downloading idna-2.9-py2.py3-none-any.whl (58 kB)
     |████████████████████████████████| 58 kB 14.2 MB/s
Collecting certifi>=2017.4.17
  Downloading certifi-2020.4.5.1-py2.py3-none-any.whl (157 kB)
     |████████████████████████████████| 157 kB 11.1 MB/s
Collecting chardet<4,>=3.0.2
  Downloading chardet-3.0.4-py2.py3-none-any.whl (133 kB)
     |████████████████████████████████| 133 kB 11.7 MB/s
Collecting urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1
  Downloading urllib3-1.25.9-py2.py3-none-any.whl (126 kB)
     |████████████████████████████████| 126 kB 11.8 MB/s
Collecting pytz>=2015.7
  Downloading pytz-2020.1-py2.py3-none-any.whl (510 kB)
     |████████████████████████████████| 510 kB 11.2 MB/s
Could not build wheels for metapensiero.tool.bump-version, since package 'wheel' is not installed.
Could not build wheels for pycparser, since package 'wheel' is not installed.
Could not build wheels for setuptools, since package 'wheel' is not installed.
Could not build wheels for Versio, since package 'wheel' is not installed.
Installing collected packages: coverage, attrs, zipp, importlib-metadata, pyparsing, six, packaging, more-itertools, atomicwrites, py, pluggy, wcwidth, pytest, pytest-cov, cython, Versio, metapensiero.tool.bump-version, pycparser, Pygments, docutils, webencodings, bleach, readme-renderer, sphinxcontrib-websupport, MarkupSafe, Jinja2, alabaster, imagesize, idna, certifi, chardet, urllib3, requests, pytz, babel, snowballstemmer, sphinx, pkginfo, requests-toolbelt, tqdm, twine
    Running setup.py install for Versio ... done
    Running setup.py install for metapensiero.tool.bump-version ... done
    Running setup.py install for pycparser ... done
Successfully installed Jinja2-2.11.2 MarkupSafe-1.1.1 Pygments-2.6.1 Versio-0.4.0 alabaster-0.7.12 atomicwrites-1.4.0 attrs-19.3.0 babel-2.8.0 bleach-3.1.5 certifi-2020.4.5.1 chardet-3.0.4 coverage-4.5.4 cython-0.29.13 docutils-0.16 idna-2.9 imagesize-1.2.0 importlib-metadata-1.6.0 metapensiero.tool.bump-version-1.3 more-itertools-8.2.0 packaging-20.3 pkginfo-1.5.0.1 pluggy-0.13.1 py-1.8.1 pycparser-2.19 pyparsing-2.4.7 pytest-5.1.2 pytest-cov-2.7.1 pytz-2020.1 readme-renderer-24.0 requests-2.23.0 requests-toolbelt-0.9.1 six-1.14.0 snowballstemmer-2.0.0 sphinx-1.8.5 sphinxcontrib-websupport-1.2.2 tqdm-4.46.0 twine-1.13.0 urllib3-1.25.9 wcwidth-0.1.9 webencodings-0.5.1 zipp-3.1.0
/Users/aiham/dev/pglast/env/bin/python tools/extract_enums.py -I libpg_query/src/postgres/include libpg_query/src/postgres/include/nodes/lockoptions.h pglast/enums/lockoptions.py docs/lockoptions.rst
/Users/aiham/dev/pglast/env/bin/python tools/extract_enums.py -I libpg_query/src/postgres/include libpg_query/src/postgres/include/storage/lockdefs.h pglast/enums/lockdefs.py docs/lockdefs.rst
/Users/aiham/dev/pglast/env/bin/python tools/extract_enums.py -I libpg_query/src/postgres/include libpg_query/src/postgres/include/nodes/nodes.h pglast/enums/nodes.py docs/nodes.rst
/Users/aiham/dev/pglast/env/bin/python tools/extract_enums.py -I libpg_query/src/postgres/include libpg_query/src/postgres/include/nodes/parsenodes.h pglast/enums/parsenodes.py docs/parsenodes.rst
/Users/aiham/dev/pglast/env/bin/python tools/extract_enums.py -I libpg_query/src/postgres/include libpg_query/src/postgres/include/catalog/pg_class.h pglast/enums/pg_class.py docs/pg_class.rst
/Users/aiham/dev/pglast/env/bin/python tools/extract_enums.py -I libpg_query/src/postgres/include libpg_query/src/postgres/include/catalog/pg_trigger.h pglast/enums/pg_trigger.py docs/pg_trigger.rst
/Users/aiham/dev/pglast/env/bin/python tools/extract_enums.py -I libpg_query/src/postgres/include libpg_query/src/postgres/include/nodes/primnodes.h pglast/enums/primnodes.py docs/primnodes.rst
/Users/aiham/dev/pglast/env/bin/python tools/extract_keywords.py libpg_query/src/postgres/include/parser/kwlist.h pglast/keywords.py
/Applications/Xcode.app/Contents/Developer/usr/bin/make -C libpg_query build
compiling src/pg_query.c
compiling src/pg_query_fingerprint.c
compiling src/pg_query_json.c
compiling src/pg_query_json_plpgsql.c
compiling src/pg_query_normalize.c
compiling src/pg_query_parse.c
compiling src/pg_query_parse_plpgsql.c
compiling src/postgres/contrib_pgcrypto_sha1.c
compiling src/postgres/src_backend_catalog_namespace.c
compiling src/postgres/src_backend_catalog_pg_proc.c
compiling src/postgres/src_backend_lib_stringinfo.c
compiling src/postgres/src_backend_libpq_pqcomm.c
compiling src/postgres/src_backend_nodes_bitmapset.c
compiling src/postgres/src_backend_nodes_copyfuncs.c
compiling src/postgres/src_backend_nodes_equalfuncs.c
compiling src/postgres/src_backend_nodes_extensible.c
compiling src/postgres/src_backend_nodes_list.c
compiling src/postgres/src_backend_nodes_makefuncs.c
compiling src/postgres/src_backend_nodes_nodeFuncs.c
compiling src/postgres/src_backend_nodes_value.c
compiling src/postgres/src_backend_parser_gram.c
compiling src/postgres/src_backend_parser_parse_expr.c
compiling src/postgres/src_backend_parser_parser.c
compiling src/postgres/src_backend_parser_scan.c
compiling src/postgres/src_backend_parser_scansup.c
compiling src/postgres/src_backend_postmaster_postmaster.c
compiling src/postgres/src_backend_storage_ipc_ipc.c
compiling src/postgres/src_backend_storage_lmgr_s_lock.c
compiling src/postgres/src_backend_tcop_postgres.c
compiling src/postgres/src_backend_utils_adt_datum.c
compiling src/postgres/src_backend_utils_adt_expandeddatum.c
compiling src/postgres/src_backend_utils_adt_format_type.c
compiling src/postgres/src_backend_utils_adt_ruleutils.c
compiling src/postgres/src_backend_utils_error_assert.c
compiling src/postgres/src_backend_utils_error_elog.c
compiling src/postgres/src_backend_utils_hash_dynahash.c
compiling src/postgres/src_backend_utils_init_globals.c
compiling src/postgres/src_backend_utils_mb_encnames.c
compiling src/postgres/src_backend_utils_mb_mbutils.c
compiling src/postgres/src_backend_utils_mb_wchar.c
compiling src/postgres/src_backend_utils_misc_guc.c
compiling src/postgres/src_backend_utils_mmgr_aset.c
compiling src/postgres/src_backend_utils_mmgr_mcxt.c
compiling src/postgres/src_common_keywords.c
compiling src/postgres/src_common_psprintf.c
compiling src/postgres/src_pl_plpgsql_src_pl_comp.c
compiling src/postgres/src_pl_plpgsql_src_pl_funcs.c
compiling src/postgres/src_pl_plpgsql_src_pl_gram.c
compiling src/postgres/src_pl_plpgsql_src_pl_handler.c
compiling src/postgres/src_pl_plpgsql_src_pl_scanner.c
compiling src/postgres/src_port_erand48.c
compiling src/postgres/src_port_pgsleep.c
compiling src/postgres/src_port_qsort.c
compiling src/postgres/src_port_random.c
ar: creating archive libpg_query.a
/Users/aiham/dev/pglast/env/bin/python setup.py build_ext --inplace
running build_ext
building 'pglast.parser' extension
creating build
creating build/temp.macosx-10.15-x86_64-3.7
creating build/temp.macosx-10.15-x86_64-3.7/pglast
clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include -I/usr/local/opt/postgresql@10/include -I/Users/aiham/dev/pglast/libpg_query -I/Users/aiham/dev/pglast/env/include -I/Users/aiham/.pyenv/versions/3.7.7/include/python3.7m -c pglast/parser.c -o build/temp.macosx-10.15-x86_64-3.7/pglast/parser.o
creating build/lib.macosx-10.15-x86_64-3.7
creating build/lib.macosx-10.15-x86_64-3.7/pglast
clang -bundle -undefined dynamic_lookup -L/usr/local/opt/readline/lib -L/usr/local/opt/readline/lib -L/Users/aiham/.pyenv/versions/3.7.7/lib -L/usr/local/opt/postgresql@10/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/readline/lib -L/Users/aiham/.pyenv/versions/3.7.7/lib -L/usr/local/opt/postgresql@10/lib -L/usr/local/opt/postgresql@10/lib -I/usr/local/opt/postgresql@10/include build/temp.macosx-10.15-x86_64-3.7/pglast/parser.o -L/Users/aiham/dev/pglast/libpg_query -lpg_query -o build/lib.macosx-10.15-x86_64-3.7/pglast/parser.cpython-37m-darwin.so
copying build/lib.macosx-10.15-x86_64-3.7/pglast/parser.cpython-37m-darwin.so -> pglast
/Users/aiham/dev/pglast/env/bin/pytest  tests/
====================================================================== test session starts =======================================================================
platform darwin -- Python 3.7.7, pytest-5.1.2, py-1.8.1, pluggy-0.13.1
rootdir: /Users/aiham/dev/pglast, inifile: setup.cfg
plugins: cov-2.7.1
collected 0 items / 6 errors
Coverage.py warning: No data was collected. (no-data-collected)

============================================================================= ERRORS =============================================================================
_______________________________________________________________ ERROR collecting tests/test_cli.py _______________________________________________________________
ImportError while importing test module '/Users/aiham/dev/pglast/tests/test_cli.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
tests/test_cli.py:37: in <module>
    from pglast.__main__ import main
E   ModuleNotFoundError: No module named 'pglast'
______________________________________________________________ ERROR collecting tests/test_node.py _______________________________________________________________
ImportError while importing test module '/Users/aiham/dev/pglast/tests/test_node.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
tests/test_node.py:13: in <module>
    from pglast import Missing, Node
E   ModuleNotFoundError: No module named 'pglast'
_____________________________________________________________ ERROR collecting tests/test_parser.py ______________________________________________________________
ImportError while importing test module '/Users/aiham/dev/pglast/tests/test_parser.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
tests/test_parser.py:11: in <module>
    from pglast import (
E   ModuleNotFoundError: No module named 'pglast'
_____________________________________________________________ ERROR collecting tests/test_printer.py _____________________________________________________________
ImportError while importing test module '/Users/aiham/dev/pglast/tests/test_printer.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
tests/test_printer.py:11: in <module>
    from pglast import Node, printer, split
E   ModuleNotFoundError: No module named 'pglast'
_____________________________________________________ ERROR collecting tests/test_printers_prettification.py _____________________________________________________
ImportError while importing test module '/Users/aiham/dev/pglast/tests/test_printers_prettification.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
tests/test_printers_prettification.py:14: in <module>
    from pglast.printer import IndentedStream
E   ModuleNotFoundError: No module named 'pglast'
_______________________________________________________ ERROR collecting tests/test_printers_roundtrip.py ________________________________________________________
ImportError while importing test module '/Users/aiham/dev/pglast/tests/test_printers_roundtrip.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
tests/test_printers_roundtrip.py:13: in <module>
    from pglast import Node, _remove_stmt_len_and_location
E   ModuleNotFoundError: No module named 'pglast'

---------- coverage: platform darwin, python 3.7.7-final-0 -----------
Name                          Stmts   Miss  Cover   Missing
-----------------------------------------------------------
pglast/__init__.py               43     43     0%   9-129
pglast/__main__.py               44     44     0%   9-85
pglast/enums/__init__.py          7      7     0%   10-20
pglast/enums/lockdefs.py         11     11     0%   8-34
pglast/enums/lockoptions.py      12     12     0%   8-25
pglast/enums/nodes.py           447    447     0%   8-473
pglast/enums/parsenodes.py      360    360     0%   8-456
pglast/enums/pg_class.py         54     54     0%   8-120
pglast/enums/pg_trigger.py       30     30     0%   8-72
pglast/enums/primnodes.py        84     84     0%   8-114
pglast/error.py                   1      1     0%   9
pglast/keywords.py                4      4     0%   8-35
pglast/node.py                  147    147     0%   9-288
pglast/printer.py               288    288     0%   9-652
pglast/printers/__init__.py       1      1     0%   9
pglast/printers/ddl.py         1327   1327     0%   9-1813
pglast/printers/dml.py          883    883     0%   9-1222
pglast/printers/sfuncs.py        17     17     0%   9-42
-----------------------------------------------------------
TOTAL                          3760   3760     0%

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 6 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
======================================================================== 6 error in 0.52s ========================================================================
make: *** [check] Error 2

@lelit
Copy link
Owner

lelit commented May 6, 2020

Thank you!

WRT tests, I'm pretty sure it worked on PRs, maybe something changed... I will investigate on GH Actions, never used.

@lelit lelit merged commit 83ac658 into lelit:master May 8, 2020
@aiham aiham deleted the fix/a-expr-printer-optional-lexpr branch May 9, 2020 07:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

A_Expr printer does not handle missing lexpr
2 participants