Skip to content

Commit b48c539

Browse files
set default yapf parameters to use yafp style
Add lines to `kernel_exec_on_cell` cfg that mimic [yapf command line behavior](https://github.com/google/yapf/blob/f672d7b1073c29054cfcc9c32f344c948e8cf1bf/yapf/__init__.py#L142) for loading global and local styles.
1 parent 03109e4 commit b48c539

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/jupyter_contrib_nbextensions/nbextensions/code_prettify/code_prettify.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,12 @@ define(['./kernel_exec_on_cell'], function(kernel_exec_on_cell) {
2626
"library": ["import json",
2727
"def yapf_reformat(cell_text):",
2828
" import yapf.yapflib.yapf_api",
29+
" from yapf import file_resources",
30+
" import os",
2931
" import re",
32+
" style_config = file_resources.GetDefaultStyleForDir(os.getcwd())",
3033
" cell_text = re.sub('^%', '#%#', cell_text, flags=re.M)",
31-
" reformated_text = yapf.yapflib.yapf_api.FormatCode(cell_text)[0]",
34+
" reformated_text = yapf.yapflib.yapf_api.FormatCode(cell_text, style_config=style_config)[0]",
3235
" return re.sub('^#%#', '%', reformated_text, flags=re.M)"].join("\n"),
3336
"prefix": "print(json.dumps(yapf_reformat(u",
3437
"postfix": ")))"

0 commit comments

Comments
 (0)