From a9427d9aff77fd6fcd8ab8d13fc2a87eb16cc2b9 Mon Sep 17 00:00:00 2001 From: Adam Greenhall Date: Fri, 11 Sep 2015 16:51:06 -0700 Subject: Start work on Aligned-reindent --- sqlparse/formatter.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'sqlparse/formatter.py') diff --git a/sqlparse/formatter.py b/sqlparse/formatter.py index 7441313..5af8743 100644 --- a/sqlparse/formatter.py +++ b/sqlparse/formatter.py @@ -55,6 +55,13 @@ def validate_options(options): elif reindent: options['strip_whitespace'] = True + reindent_aligned = options.get('reindent_aligned', False) + if reindent_aligned not in [True, False]: + raise SQLParseError('Invalid value for reindent_aligned: %r' + % reindent) + elif reindent_aligned: + options['strip_whitespace'] = True + indent_tabs = options.get('indent_tabs', False) if indent_tabs not in [True, False]: raise SQLParseError('Invalid value for indent_tabs: %r' % indent_tabs) @@ -130,6 +137,11 @@ def build_filter_stack(stack, options): width=options['indent_width'], wrap_after=options['wrap_after'])) + if options.get('reindent_aligned', False): + stack.enable_grouping() + stack.stmtprocess.append( + filters.AlignedIndentFilter(char=options['indent_char'])) + if options.get('right_margin'): stack.enable_grouping() stack.stmtprocess.append( -- cgit v1.2.1 From 2928a7c8f1192b8376795368825c2cf2dae243c3 Mon Sep 17 00:00:00 2001 From: Adam Greenhall Date: Sat, 12 Sep 2015 14:49:47 -0700 Subject: Add filter `Spaces around Operators` --- sqlparse/formatter.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'sqlparse/formatter.py') diff --git a/sqlparse/formatter.py b/sqlparse/formatter.py index 5af8743..0fa563c 100644 --- a/sqlparse/formatter.py +++ b/sqlparse/formatter.py @@ -30,6 +30,11 @@ def validate_options(options): raise SQLParseError('Invalid value for strip_comments: %r' % strip_comments) + use_space_around_operators = options.get('use_space_around_operators', False) + if use_space_around_operators not in [True, False]: + raise SQLParseError('Invalid value for use_space_around_operators: %r' + % use_space_around_operators) + strip_ws = options.get('strip_whitespace', False) if strip_ws not in [True, False]: raise SQLParseError('Invalid value for strip_whitespace: %r' @@ -121,6 +126,10 @@ def build_filter_stack(stack, options): stack.preprocess.append(filters.TruncateStringFilter( width=options['truncate_strings'], char=options['truncate_char'])) + if options.get('use_space_around_operators', False): + stack.enable_grouping() + stack.stmtprocess.append(filters.SpacesAroundOperatorsFilter()) + # After grouping if options.get('strip_comments'): stack.enable_grouping() -- cgit v1.2.1 From a7c7d9586208516de372cb01203b48a53f7095fb Mon Sep 17 00:00:00 2001 From: Victor Uriarte Date: Sat, 4 Jun 2016 21:57:43 -0700 Subject: Format `pr` to pass flake8 and update functions used --- sqlparse/formatter.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'sqlparse/formatter.py') diff --git a/sqlparse/formatter.py b/sqlparse/formatter.py index 0fa563c..069109b 100644 --- a/sqlparse/formatter.py +++ b/sqlparse/formatter.py @@ -30,10 +30,10 @@ def validate_options(options): raise SQLParseError('Invalid value for strip_comments: %r' % strip_comments) - use_space_around_operators = options.get('use_space_around_operators', False) - if use_space_around_operators not in [True, False]: + space_around_operators = options.get('use_space_around_operators', False) + if space_around_operators not in [True, False]: raise SQLParseError('Invalid value for use_space_around_operators: %r' - % use_space_around_operators) + % space_around_operators) strip_ws = options.get('strip_whitespace', False) if strip_ws not in [True, False]: -- cgit v1.2.1