sqlnbfmt 0.1.5__tar.gz → 0.1.7__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {sqlnbfmt-0.1.5/sqlnbfmt.egg-info → sqlnbfmt-0.1.7}/PKG-INFO +1 -1
- {sqlnbfmt-0.1.5 → sqlnbfmt-0.1.7}/pyproject.toml +1 -1
- {sqlnbfmt-0.1.5 → sqlnbfmt-0.1.7}/sqlnbfmt/formatter.py +27 -23
- {sqlnbfmt-0.1.5 → sqlnbfmt-0.1.7/sqlnbfmt.egg-info}/PKG-INFO +1 -1
- {sqlnbfmt-0.1.5 → sqlnbfmt-0.1.7}/LICENSE +0 -0
- {sqlnbfmt-0.1.5 → sqlnbfmt-0.1.7}/README.md +0 -0
- {sqlnbfmt-0.1.5 → sqlnbfmt-0.1.7}/setup.cfg +0 -0
- {sqlnbfmt-0.1.5 → sqlnbfmt-0.1.7}/sqlnbfmt/__init__.py +0 -0
- {sqlnbfmt-0.1.5 → sqlnbfmt-0.1.7}/sqlnbfmt.egg-info/SOURCES.txt +0 -0
- {sqlnbfmt-0.1.5 → sqlnbfmt-0.1.7}/sqlnbfmt.egg-info/dependency_links.txt +0 -0
- {sqlnbfmt-0.1.5 → sqlnbfmt-0.1.7}/sqlnbfmt.egg-info/entry_points.txt +0 -0
- {sqlnbfmt-0.1.5 → sqlnbfmt-0.1.7}/sqlnbfmt.egg-info/requires.txt +0 -0
- {sqlnbfmt-0.1.5 → sqlnbfmt-0.1.7}/sqlnbfmt.egg-info/top_level.txt +0 -0
- {sqlnbfmt-0.1.5 → sqlnbfmt-0.1.7}/tests/test_formatter.py +0 -0
|
@@ -246,17 +246,18 @@ class SQLStringFormatter(ast.NodeTransformer):
|
|
|
246
246
|
if in_function and '\n' in formatted_sql:
|
|
247
247
|
# Apply Black-style indentation for function arguments
|
|
248
248
|
lines = formatted_sql.split('\n')
|
|
249
|
-
|
|
249
|
+
# Indent all lines including the first SQL line
|
|
250
|
+
indented_lines = [
|
|
250
251
|
" " * 4 + line if line.strip() else line
|
|
251
|
-
for line in lines
|
|
252
|
-
]
|
|
252
|
+
for line in lines
|
|
253
|
+
]
|
|
253
254
|
formatted_sql = '\n'.join(indented_lines)
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
formatted_str = f'"""\n{formatted_sql}\n"""'
|
|
255
|
+
|
|
256
|
+
# Reconstruct the string with appropriate quotes
|
|
257
|
+
formatted_str = f'"""\n{formatted_sql}\n{" " * 4}"""'
|
|
258
258
|
else:
|
|
259
|
-
|
|
259
|
+
# Ensure newlines are added around the formatted SQL
|
|
260
|
+
formatted_str = f'"""\n{formatted_sql}\n"""'
|
|
260
261
|
|
|
261
262
|
formatted_node = ast.parse(formatted_str).body[0].value
|
|
262
263
|
return formatted_node
|
|
@@ -279,9 +280,8 @@ class SQLStringFormatter(ast.NodeTransformer):
|
|
|
279
280
|
|
|
280
281
|
if placeholders:
|
|
281
282
|
for placeholder in placeholders.keys():
|
|
282
|
-
if not placeholder:
|
|
283
|
+
if not placeholder:
|
|
283
284
|
continue
|
|
284
|
-
# Remove quotes around placeholders in formatted SQL
|
|
285
285
|
formatted_sql = formatted_sql.replace(f"'{placeholder}'", placeholder)
|
|
286
286
|
formatted_sql = formatted_sql.replace(f'"{placeholder}"', placeholder)
|
|
287
287
|
|
|
@@ -290,10 +290,11 @@ class SQLStringFormatter(ast.NodeTransformer):
|
|
|
290
290
|
# Apply Black-style indentation for function arguments
|
|
291
291
|
if in_function and '\n' in formatted_sql:
|
|
292
292
|
lines = formatted_sql.split('\n')
|
|
293
|
-
|
|
293
|
+
# Indent all lines including the first SQL line
|
|
294
|
+
indented_lines = [
|
|
294
295
|
" " * 4 + line if line.strip() else line
|
|
295
|
-
for line in lines
|
|
296
|
-
]
|
|
296
|
+
for line in lines
|
|
297
|
+
]
|
|
297
298
|
formatted_sql = '\n'.join(indented_lines)
|
|
298
299
|
|
|
299
300
|
# Reconstruct the f-string
|
|
@@ -307,7 +308,6 @@ class SQLStringFormatter(ast.NodeTransformer):
|
|
|
307
308
|
match = pattern.search(formatted_sql, idx)
|
|
308
309
|
if match:
|
|
309
310
|
if match.start() > idx:
|
|
310
|
-
# Add preceding text as Constant
|
|
311
311
|
new_values.append(ast.Constant(value=formatted_sql[idx:match.start()]))
|
|
312
312
|
placeholder = match.group()
|
|
313
313
|
expr_str = placeholders[placeholder].strip()
|
|
@@ -323,23 +323,27 @@ class SQLStringFormatter(ast.NodeTransformer):
|
|
|
323
323
|
))
|
|
324
324
|
idx = match.end()
|
|
325
325
|
else:
|
|
326
|
-
# Add the rest of the string as Constant
|
|
327
326
|
new_values.append(ast.Constant(value=formatted_sql[idx:]))
|
|
328
327
|
break
|
|
329
328
|
|
|
330
329
|
new_node = ast.JoinedStr(values=new_values)
|
|
331
|
-
# Wrap the f-string with adjusted triple quotes
|
|
332
330
|
if '\n' in formatted_sql:
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
331
|
+
if in_function:
|
|
332
|
+
formatted_fstring = ast.JoinedStr(values=[
|
|
333
|
+
ast.Constant(value='\n'),
|
|
334
|
+
*new_node.values,
|
|
335
|
+
ast.Constant(value=f'\n{" " * 4}')
|
|
336
|
+
])
|
|
337
|
+
else:
|
|
338
|
+
formatted_fstring = ast.JoinedStr(values=[
|
|
339
|
+
ast.Constant(value='\n'),
|
|
340
|
+
*new_node.values,
|
|
341
|
+
ast.Constant(value='\n')
|
|
342
|
+
])
|
|
339
343
|
else:
|
|
340
|
-
# Single-line f-string
|
|
341
344
|
formatted_fstring = new_node
|
|
342
345
|
return formatted_fstring
|
|
346
|
+
|
|
343
347
|
return None
|
|
344
348
|
except SQLFormattingError as e:
|
|
345
349
|
self.logger.warning(f"SQL formatting skipped: {e}")
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|