From d8ae15b621555f313f4050ed4a6be129b8469819 Mon Sep 17 00:00:00 2001 From: Lele Gaifax Date: Wed, 10 Jan 2024 09:39:52 +0100 Subject: [PATCH 1/3] Remove redundant call to enumerate() --- tools/extract_enums.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/extract_enums.py b/tools/extract_enums.py index 187fa91..09d1489 100644 --- a/tools/extract_enums.py +++ b/tools/extract_enums.py @@ -218,7 +218,7 @@ def write_enum_doc(name, enum, output, toc, url, mod_name): if name in toc: output.write('\n Corresponds to the `%s enum <%s#L%d>`__.\n' % (name, url, toc[name])) - for index, item in enumerate(enum.values.enumerators): + for item in enum.values.enumerators: output.write('\n .. data:: %s\n' % item.name) From 6f4a6d8d28f26be0c05c3dbbc441c17c2e1b442f Mon Sep 17 00:00:00 2001 From: Lele Gaifax Date: Wed, 10 Jan 2024 09:42:51 +0100 Subject: [PATCH 2/3] Drop precomputed FETCH_ALL constant In the PG headers FETCH_ALL is a synonym of LONG_MAX, and the latter value depends on the actual architecture so cannot be precomputed and hardcoded in the extracted enums. Given that it's used in a single place, instead of doing fancy gymnic to compute it lazily, take the straight path and directly use the LONG_MAX symbol exposed in the parser module, that correspond to its homonym C value. This fixes issue #142. While there, tweak the FetchStmt printer to emit slightly nicer representation. --- docs/parsenodes.rst | 6 +--- pglast/enums/parsenodes.py | 4 +-- pglast/printers/dml.py | 30 ++++++++-------- .../dml/fetch.sql | 35 +++++++++++++++++++ .../test_printers_prettification/dml/move.sql | 35 +++++++++++++++++++ tools/extract_enums.py | 12 +------ 6 files changed, 89 insertions(+), 33 deletions(-) create mode 100644 tests/test_printers_prettification/dml/fetch.sql create mode 100644 tests/test_printers_prettification/dml/move.sql diff --git a/docs/parsenodes.rst b/docs/parsenodes.rst index 630b813..63e6336 100644 --- a/docs/parsenodes.rst +++ b/docs/parsenodes.rst @@ -2,7 +2,7 @@ .. :Project: pglast -- DO NOT EDIT: generated automatically .. :Author: Lele Gaifax .. :License: GNU General Public License version 3 or later -.. :Copyright: © 2017-2023 Lele Gaifax +.. :Copyright: © 2017-2024 Lele Gaifax .. ============================================================================== @@ -985,7 +985,3 @@ __ https://github.com/pganalyze/libpg_query/blob/db39825/src/postgres/include/no .. data:: CURSOR_OPT_PARALLEL_OK See `here for details `__. - -.. data:: FETCH_ALL - - See `here for details `__. diff --git a/pglast/enums/parsenodes.py b/pglast/enums/parsenodes.py index 45e409a..c90e6bf 100644 --- a/pglast/enums/parsenodes.py +++ b/pglast/enums/parsenodes.py @@ -2,7 +2,7 @@ # :Project: pglast -- DO NOT EDIT: automatically extracted from parsenodes.h @ 15-4.2.4-0-gdb39825 # :Author: Lele Gaifax # :License: GNU General Public License version 3 or later -# :Copyright: © 2017-2023 Lele Gaifax +# :Copyright: © 2017-2024 Lele Gaifax # from enum import Enum, IntEnum, IntFlag, auto @@ -486,5 +486,3 @@ class WCOKind(IntEnum): CURSOR_OPT_CUSTOM_PLAN = 0x0400 CURSOR_OPT_PARALLEL_OK = 0x0800 - -FETCH_ALL = 9223372036854775807 diff --git a/pglast/printers/dml.py b/pglast/printers/dml.py index 0f2dde8..422c11e 100644 --- a/pglast/printers/dml.py +++ b/pglast/printers/dml.py @@ -3,10 +3,11 @@ # :Created: sab 05 ago 2017 16:34:08 CEST # :Author: Lele Gaifax # :License: GNU General Public License version 3 or later -# :Copyright: © 2017, 2018, 2019, 2020, 2021, 2022, 2023 Lele Gaifax +# :Copyright: © 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024 Lele Gaifax # from .. import ast, enums +from ..parser import LONG_MAX from . import IntEnumPrinter, get_string_value, node_printer @@ -634,29 +635,29 @@ class FetchDirectionPrinter(IntEnumPrinter): enum = enums.FetchDirection def FETCH_FORWARD(self, node, output): - if node.howMany == enums.FETCH_ALL: - output.write('ALL ') - elif node.howMany != 1: - output.write(f'FORWARD {node.howMany} ') + if node.howMany == 1: + output.write('NEXT') + else: + output.write('FORWARD') + output.swrite('ALL' if node.howMany == LONG_MAX else str(node.howMany)) def FETCH_BACKWARD(self, node, output): - if node.howMany == enums.FETCH_ALL: - output.write('BACKWARD ALL ') - elif node.howMany != 1: - output.write(f'BACKWARD {node.howMany} ') + if node.howMany == 1: + output.write('PRIOR') else: - output.write('PRIOR ') + output.write('BACKWARD') + output.swrite('ALL' if node.howMany == LONG_MAX else str(node.howMany)) def FETCH_ABSOLUTE(self, node, output): if node.howMany == 1: - output.write('FIRST ') + output.write('FIRST') elif node.howMany == -1: - output.write('LAST ') + output.write('LAST') else: - output.write(f'ABSOLUTE {node.howMany} ') + output.write(f'ABSOLUTE {node.howMany}') def FETCH_RELATIVE(self, node, output): - output.write(f'RELATIVE {node.howMany} ') + output.write(f'RELATIVE {node.howMany}') fetch_direction_printer = FetchDirectionPrinter() @@ -666,6 +667,7 @@ def FETCH_RELATIVE(self, node, output): def fetch_stmt(node, output): output.write('MOVE ' if node.ismove else 'FETCH ') fetch_direction_printer(node.direction, node, output) + output.write(' IN ' if node.ismove else ' FROM ') output.print_name(node.portalname) diff --git a/tests/test_printers_prettification/dml/fetch.sql b/tests/test_printers_prettification/dml/fetch.sql new file mode 100644 index 0000000..3d3ee3a --- /dev/null +++ b/tests/test_printers_prettification/dml/fetch.sql @@ -0,0 +1,35 @@ +fetch all foo += +FETCH FORWARD ALL FROM foo + +fetch next in foo += +FETCH NEXT FROM foo + +fetch forward 1 from foo += +FETCH NEXT FROM foo + +fetch 1 from foo += +FETCH NEXT FROM foo + +fetch backward 1 from foo += +FETCH PRIOR FROM foo + +fetch prior in foo += +FETCH PRIOR FROM foo + +fetch absolute 1 foo += +FETCH FIRST FROM foo + +fetch absolute -1 foo += +FETCH LAST FROM foo + +fetch absolute 42 foo += +FETCH ABSOLUTE 42 FROM foo diff --git a/tests/test_printers_prettification/dml/move.sql b/tests/test_printers_prettification/dml/move.sql new file mode 100644 index 0000000..3034c7b --- /dev/null +++ b/tests/test_printers_prettification/dml/move.sql @@ -0,0 +1,35 @@ +move all foo += +MOVE FORWARD ALL IN foo + +move next in foo += +MOVE NEXT IN foo + +move forward 1 from foo += +MOVE NEXT IN foo + +move 1 from foo += +MOVE NEXT IN foo + +move backward 1 from foo += +MOVE PRIOR IN foo + +move prior in foo += +MOVE PRIOR IN foo + +move absolute 1 foo += +MOVE FIRST IN foo + +move absolute -1 foo += +MOVE LAST IN foo + +move absolute 42 foo += +MOVE ABSOLUTE 42 IN foo diff --git a/tools/extract_enums.py b/tools/extract_enums.py index 09d1489..d6497df 100644 --- a/tools/extract_enums.py +++ b/tools/extract_enums.py @@ -3,7 +3,7 @@ # :Created: gio 03 ago 2017 14:54:39 CEST # :Author: Lele Gaifax # :License: GNU General Public License version 3 or later -# :Copyright: © 2017, 2018, 2019, 2020, 2021, 2022 Lele Gaifax +# :Copyright: © 2017, 2018, 2019, 2020, 2021, 2022, 2024 Lele Gaifax # from datetime import date @@ -13,12 +13,6 @@ from pycparser import c_ast, c_parser -try: - from pglast.parser import LONG_MAX -except ModuleNotFoundError: - # bootstrap - from sys import maxsize as LONG_MAX - PY_HEADER = """\ # -*- coding: utf-8 -*- @@ -144,10 +138,6 @@ def extract_defines(source): line) if m is not None: yield m.group(1), m.group(2) - else: - m = match(r"#define\s+([a-zA-Z_]+)\s+LONG_MAX", line) - if m is not None: - yield m.group(1), LONG_MAX def emit_constant(value): From 4007f24a16ba1275e60be50e709f71414bec41b1 Mon Sep 17 00:00:00 2001 From: Lele Gaifax Date: Wed, 10 Jan 2024 09:57:39 +0100 Subject: [PATCH 3/3] Update copyright years --- docs/ast.rst | 2 +- docs/conf.py | 2 +- docs/dml.rst | 2 +- docs/lockdefs.rst | 2 +- docs/lockoptions.rst | 2 +- docs/nodes.rst | 2 +- docs/pg_am.rst | 2 +- docs/pg_attribute.rst | 2 +- docs/pg_class.rst | 2 +- docs/pg_trigger.rst | 2 +- docs/primnodes.rst | 2 +- docs/xml.rst | 2 +- pglast/ast.py | 2 +- pglast/ast.pyx | 2 +- pglast/enums/lockdefs.py | 2 +- pglast/enums/lockoptions.py | 2 +- pglast/enums/nodes.py | 2 +- pglast/enums/pg_am.py | 2 +- pglast/enums/pg_attribute.py | 2 +- pglast/enums/pg_class.py | 2 +- pglast/enums/pg_trigger.py | 2 +- pglast/enums/primnodes.py | 2 +- pglast/enums/xml.py | 2 +- pglast/structs.pxd | 2 +- 24 files changed, 24 insertions(+), 24 deletions(-) diff --git a/docs/ast.rst b/docs/ast.rst index bfe1056..b0352dc 100644 --- a/docs/ast.rst +++ b/docs/ast.rst @@ -2,7 +2,7 @@ .. :Project: pglast -- DO NOT EDIT: generated automatically .. :Author: Lele Gaifax .. :License: GNU General Public License version 3 or later -.. :Copyright: © 2021-2023 Lele Gaifax +.. :Copyright: © 2021-2024 Lele Gaifax .. .. _pglast.ast: diff --git a/docs/conf.py b/docs/conf.py index 2798465..f0a4944 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -47,7 +47,7 @@ # General information about the project. project = 'pglast' -copyright = '2017-2023 Lele Gaifax' +copyright = '2017-2024 Lele Gaifax' author = 'Lele Gaifax' # The version info for the project you're documenting, acts as replacement for diff --git a/docs/dml.rst b/docs/dml.rst index 25a2dda..b0e1200 100644 --- a/docs/dml.rst +++ b/docs/dml.rst @@ -2,7 +2,7 @@ .. :Project: pglast -- DO NOT EDIT: generated automatically .. :Author: Lele Gaifax .. :License: GNU General Public License version 3 or later -.. :Copyright: © 2017-2023 Lele Gaifax +.. :Copyright: © 2017-2024 Lele Gaifax .. ====================================================== diff --git a/docs/lockdefs.rst b/docs/lockdefs.rst index 2ebb66d..05da255 100644 --- a/docs/lockdefs.rst +++ b/docs/lockdefs.rst @@ -2,7 +2,7 @@ .. :Project: pglast -- DO NOT EDIT: generated automatically .. :Author: Lele Gaifax .. :License: GNU General Public License version 3 or later -.. :Copyright: © 2017-2023 Lele Gaifax +.. :Copyright: © 2017-2024 Lele Gaifax .. ========================================================================== diff --git a/docs/lockoptions.rst b/docs/lockoptions.rst index a56fa1d..c0c0ec1 100644 --- a/docs/lockoptions.rst +++ b/docs/lockoptions.rst @@ -2,7 +2,7 @@ .. :Project: pglast -- DO NOT EDIT: generated automatically .. :Author: Lele Gaifax .. :License: GNU General Public License version 3 or later -.. :Copyright: © 2017-2023 Lele Gaifax +.. :Copyright: © 2017-2024 Lele Gaifax .. ================================================================================ diff --git a/docs/nodes.rst b/docs/nodes.rst index 9ef296e..d93ad75 100644 --- a/docs/nodes.rst +++ b/docs/nodes.rst @@ -2,7 +2,7 @@ .. :Project: pglast -- DO NOT EDIT: generated automatically .. :Author: Lele Gaifax .. :License: GNU General Public License version 3 or later -.. :Copyright: © 2017-2023 Lele Gaifax +.. :Copyright: © 2017-2024 Lele Gaifax .. ==================================================================== diff --git a/docs/pg_am.rst b/docs/pg_am.rst index d0040db..7a015a3 100644 --- a/docs/pg_am.rst +++ b/docs/pg_am.rst @@ -2,7 +2,7 @@ .. :Project: pglast -- DO NOT EDIT: generated automatically .. :Author: Lele Gaifax .. :License: GNU General Public License version 3 or later -.. :Copyright: © 2017-2023 Lele Gaifax +.. :Copyright: © 2017-2024 Lele Gaifax .. ==================================================================== diff --git a/docs/pg_attribute.rst b/docs/pg_attribute.rst index 7bda7d0..440798f 100644 --- a/docs/pg_attribute.rst +++ b/docs/pg_attribute.rst @@ -2,7 +2,7 @@ .. :Project: pglast -- DO NOT EDIT: generated automatically .. :Author: Lele Gaifax .. :License: GNU General Public License version 3 or later -.. :Copyright: © 2017-2023 Lele Gaifax +.. :Copyright: © 2017-2024 Lele Gaifax .. ================================================================================== diff --git a/docs/pg_class.rst b/docs/pg_class.rst index c97f95d..896ec3c 100644 --- a/docs/pg_class.rst +++ b/docs/pg_class.rst @@ -2,7 +2,7 @@ .. :Project: pglast -- DO NOT EDIT: generated automatically .. :Author: Lele Gaifax .. :License: GNU General Public License version 3 or later -.. :Copyright: © 2017-2023 Lele Gaifax +.. :Copyright: © 2017-2024 Lele Gaifax .. ========================================================================== diff --git a/docs/pg_trigger.rst b/docs/pg_trigger.rst index 244c1b7..1e64ed3 100644 --- a/docs/pg_trigger.rst +++ b/docs/pg_trigger.rst @@ -2,7 +2,7 @@ .. :Project: pglast -- DO NOT EDIT: generated automatically .. :Author: Lele Gaifax .. :License: GNU General Public License version 3 or later -.. :Copyright: © 2017-2023 Lele Gaifax +.. :Copyright: © 2017-2024 Lele Gaifax .. ============================================================================== diff --git a/docs/primnodes.rst b/docs/primnodes.rst index 1d34393..a6e7f0d 100644 --- a/docs/primnodes.rst +++ b/docs/primnodes.rst @@ -2,7 +2,7 @@ .. :Project: pglast -- DO NOT EDIT: generated automatically .. :Author: Lele Gaifax .. :License: GNU General Public License version 3 or later -.. :Copyright: © 2017-2023 Lele Gaifax +.. :Copyright: © 2017-2024 Lele Gaifax .. ============================================================================ diff --git a/docs/xml.rst b/docs/xml.rst index d00a1ca..7303043 100644 --- a/docs/xml.rst +++ b/docs/xml.rst @@ -2,7 +2,7 @@ .. :Project: pglast -- DO NOT EDIT: generated automatically .. :Author: Lele Gaifax .. :License: GNU General Public License version 3 or later -.. :Copyright: © 2017-2023 Lele Gaifax +.. :Copyright: © 2017-2024 Lele Gaifax .. ================================================================ diff --git a/pglast/ast.py b/pglast/ast.py index 448b925..2a1e41c 100644 --- a/pglast/ast.py +++ b/pglast/ast.py @@ -2,7 +2,7 @@ # :Project: pglast -- DO NOT EDIT: automatically extracted from struct_defs.json @ 15-4.2.4-0-gdb39825 # :Author: Lele Gaifax # :License: GNU General Public License version 3 or later -# :Copyright: © 2021-2023 Lele Gaifax +# :Copyright: © 2021-2024 Lele Gaifax # from collections import namedtuple diff --git a/pglast/ast.pyx b/pglast/ast.pyx index daf7808..7cbe3b4 100644 --- a/pglast/ast.pyx +++ b/pglast/ast.pyx @@ -2,7 +2,7 @@ # :Project: pglast -- DO NOT EDIT: automatically extracted from struct_defs.json @ 15-4.2.4-0-gdb39825 # :Author: Lele Gaifax # :License: GNU General Public License version 3 or later -# :Copyright: © 2021-2023 Lele Gaifax +# :Copyright: © 2021-2024 Lele Gaifax # #cython: language_level=3 diff --git a/pglast/enums/lockdefs.py b/pglast/enums/lockdefs.py index 0af777f..1257fc2 100644 --- a/pglast/enums/lockdefs.py +++ b/pglast/enums/lockdefs.py @@ -2,7 +2,7 @@ # :Project: pglast -- DO NOT EDIT: automatically extracted from lockdefs.h @ 15-4.2.4-0-gdb39825 # :Author: Lele Gaifax # :License: GNU General Public License version 3 or later -# :Copyright: © 2017-2023 Lele Gaifax +# :Copyright: © 2017-2024 Lele Gaifax # from enum import Enum, IntEnum, IntFlag, auto diff --git a/pglast/enums/lockoptions.py b/pglast/enums/lockoptions.py index 641b37b..7d7e6af 100644 --- a/pglast/enums/lockoptions.py +++ b/pglast/enums/lockoptions.py @@ -2,7 +2,7 @@ # :Project: pglast -- DO NOT EDIT: automatically extracted from lockoptions.h @ 15-4.2.4-0-gdb39825 # :Author: Lele Gaifax # :License: GNU General Public License version 3 or later -# :Copyright: © 2017-2023 Lele Gaifax +# :Copyright: © 2017-2024 Lele Gaifax # from enum import Enum, IntEnum, IntFlag, auto diff --git a/pglast/enums/nodes.py b/pglast/enums/nodes.py index 6242419..a49a373 100644 --- a/pglast/enums/nodes.py +++ b/pglast/enums/nodes.py @@ -2,7 +2,7 @@ # :Project: pglast -- DO NOT EDIT: automatically extracted from nodes.h @ 15-4.2.4-0-gdb39825 # :Author: Lele Gaifax # :License: GNU General Public License version 3 or later -# :Copyright: © 2017-2023 Lele Gaifax +# :Copyright: © 2017-2024 Lele Gaifax # from enum import Enum, IntEnum, IntFlag, auto diff --git a/pglast/enums/pg_am.py b/pglast/enums/pg_am.py index 3e7bb40..538e6d3 100644 --- a/pglast/enums/pg_am.py +++ b/pglast/enums/pg_am.py @@ -2,7 +2,7 @@ # :Project: pglast -- DO NOT EDIT: automatically extracted from pg_am.h @ 15-4.2.4-0-gdb39825 # :Author: Lele Gaifax # :License: GNU General Public License version 3 or later -# :Copyright: © 2017-2023 Lele Gaifax +# :Copyright: © 2017-2024 Lele Gaifax # from enum import Enum, IntEnum, IntFlag, auto diff --git a/pglast/enums/pg_attribute.py b/pglast/enums/pg_attribute.py index 5df1f0b..d5ed2ee 100644 --- a/pglast/enums/pg_attribute.py +++ b/pglast/enums/pg_attribute.py @@ -2,7 +2,7 @@ # :Project: pglast -- DO NOT EDIT: automatically extracted from pg_attribute.h @ 15-4.2.4-0-gdb39825 # :Author: Lele Gaifax # :License: GNU General Public License version 3 or later -# :Copyright: © 2017-2023 Lele Gaifax +# :Copyright: © 2017-2024 Lele Gaifax # from enum import Enum, IntEnum, IntFlag, auto diff --git a/pglast/enums/pg_class.py b/pglast/enums/pg_class.py index 880714a..22aa8dc 100644 --- a/pglast/enums/pg_class.py +++ b/pglast/enums/pg_class.py @@ -2,7 +2,7 @@ # :Project: pglast -- DO NOT EDIT: automatically extracted from pg_class.h @ 15-4.2.4-0-gdb39825 # :Author: Lele Gaifax # :License: GNU General Public License version 3 or later -# :Copyright: © 2017-2023 Lele Gaifax +# :Copyright: © 2017-2024 Lele Gaifax # from enum import Enum, IntEnum, IntFlag, auto diff --git a/pglast/enums/pg_trigger.py b/pglast/enums/pg_trigger.py index 94f8594..07aa427 100644 --- a/pglast/enums/pg_trigger.py +++ b/pglast/enums/pg_trigger.py @@ -2,7 +2,7 @@ # :Project: pglast -- DO NOT EDIT: automatically extracted from pg_trigger.h @ 15-4.2.4-0-gdb39825 # :Author: Lele Gaifax # :License: GNU General Public License version 3 or later -# :Copyright: © 2017-2023 Lele Gaifax +# :Copyright: © 2017-2024 Lele Gaifax # from enum import Enum, IntEnum, IntFlag, auto diff --git a/pglast/enums/primnodes.py b/pglast/enums/primnodes.py index bcc27f4..9cbcc22 100644 --- a/pglast/enums/primnodes.py +++ b/pglast/enums/primnodes.py @@ -2,7 +2,7 @@ # :Project: pglast -- DO NOT EDIT: automatically extracted from primnodes.h @ 15-4.2.4-0-gdb39825 # :Author: Lele Gaifax # :License: GNU General Public License version 3 or later -# :Copyright: © 2017-2023 Lele Gaifax +# :Copyright: © 2017-2024 Lele Gaifax # from enum import Enum, IntEnum, IntFlag, auto diff --git a/pglast/enums/xml.py b/pglast/enums/xml.py index 93c90d1..aa06482 100644 --- a/pglast/enums/xml.py +++ b/pglast/enums/xml.py @@ -2,7 +2,7 @@ # :Project: pglast -- DO NOT EDIT: automatically extracted from xml.h @ 15-4.2.4-0-gdb39825 # :Author: Lele Gaifax # :License: GNU General Public License version 3 or later -# :Copyright: © 2017-2023 Lele Gaifax +# :Copyright: © 2017-2024 Lele Gaifax # from enum import Enum, IntEnum, IntFlag, auto diff --git a/pglast/structs.pxd b/pglast/structs.pxd index 610e0f8..a6859e0 100644 --- a/pglast/structs.pxd +++ b/pglast/structs.pxd @@ -2,7 +2,7 @@ # :Project: pglast -- DO NOT EDIT: automatically extracted from struct_defs.json @ 15-4.2.4-0-gdb39825 # :Author: Lele Gaifax # :License: GNU General Public License version 3 or later -# :Copyright: © 2021-2023 Lele Gaifax +# :Copyright: © 2021-2024 Lele Gaifax # #cython: language_level=3