Skip to content

Commit e4fff8e

Browse files
committed
Added the set_setting internal function
1 parent 89ebcae commit e4fff8e

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
lines changed

preql/core/display.py

+9-11
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@
1313
from .interp_common import call_builtin_func, cast_to_python_int, cast_to_python
1414
from .state import get_display
1515

16-
from preql.settings import color_theme
16+
from preql.settings import color_theme, Display as DisplaySettings
17+
18+
1719

1820

19-
TABLE_PREVIEW_SIZE = 16
20-
LIST_PREVIEW_SIZE = 128
21-
MAX_AUTO_COUNT = 10000
2221

2322
@dp_type
2423
def pql_repr(t: T.function, value):
@@ -116,8 +115,6 @@ def _html_table(name, count_str, rows, offset, has_more, colors):
116115
return '%s<table class="preql_table">%s%s</table>' % (header, ths, '\n'.join(trs)) + style
117116

118117

119-
from preql.settings import color_theme
120-
121118
def _rich_table(name, count_str, rows, offset, has_more, colors=True, show_footer=False):
122119
header = 'table '
123120
if name:
@@ -176,15 +173,16 @@ def _view_table(table, size, offset):
176173

177174
def table_inline_repr(self):
178175
offset = 0
179-
table_name, rows, = _view_table(self, TABLE_PREVIEW_SIZE, offset)
176+
table_name, rows, = _view_table(self, DisplaySettings.TABLE_PREVIEW_SIZE_SHELL, offset)
180177
return '[%s]' % ', '.join(repr(r) for r in rows)
181178

182179

183180

184181
def table_repr(self, offset=0):
182+
max_count = DisplaySettings.MAX_AUTO_COUNT
185183

186-
count = cast_to_python_int(call_builtin_func('count', [table_limit(self, MAX_AUTO_COUNT)]))
187-
if count == MAX_AUTO_COUNT:
184+
count = cast_to_python_int(call_builtin_func('count', [table_limit(self, max_count)]))
185+
if count == max_count:
188186
count_str = f'>={count}'
189187
else:
190188
count_str = f'={count}'
@@ -197,12 +195,12 @@ def table_repr(self, offset=0):
197195

198196
# TODO load into preql and repr, instead of casting to python
199197
table_f = _rich_table
200-
preview = TABLE_PREVIEW_SIZE
198+
preview = DisplaySettings.TABLE_PREVIEW_SIZE_SHELL
201199
colors = True
202200
display = get_display()
203201

204202
if display.format == 'html':
205-
preview = TABLE_PREVIEW_SIZE * 10
203+
preview = DisplaySettings.TABLE_PREVIEW_SIZE_HTML
206204
table_f = _html_table
207205
elif display.format == 'text':
208206
colors = False

preql/core/pql_functions.py

+10
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,15 @@ def pql_breakpoint():
207207
breakpoint()
208208
return objects.null
209209

210+
def pql_set_setting(name: T.string, value: T.any):
211+
name = cast_to_python_string(name)
212+
value = cast_to_python(value)
213+
214+
from preql.settings import Display
215+
setattr(Display, name, value)
216+
return objects.null
217+
218+
210219
def pql_debug():
211220
"""Breaks the execution of the interpreter, and enters into a debug
212221
session using the REPL environment.
@@ -1091,6 +1100,7 @@ def f(datetime):
10911100
'serve_rest': pql_serve_rest,
10921101
'force_eval': pql_force_eval,
10931102
'fmt': pql_fmt,
1103+
'set_setting': pql_set_setting,
10941104
})
10951105

10961106
_joins = {

preql/settings.py

+6
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424

2525
update_color_theme = {}
2626

27+
class Display:
28+
TABLE_PREVIEW_SIZE_SHELL = 16
29+
TABLE_PREVIEW_SIZE_HTML = 64
30+
LIST_PREVIEW_SIZE = 128
31+
MAX_AUTO_COUNT = 10000
32+
2733
try:
2834
from .local_settings import *
2935
except ImportError:

0 commit comments

Comments
 (0)