From fe4232bc389d3157582698fd17da5a8957ca48d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Bercher?= Date: Sat, 8 Jul 2017 22:44:22 +0200 Subject: [PATCH 1/3] [code_prettify] added support for IPython magics, cf #1018 --- code_prettify.js | 12 +++++++++--- code_prettify.yaml | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/code_prettify.js b/code_prettify.js index fb32cc6..dadc2c7 100644 --- a/code_prettify.js +++ b/code_prettify.js @@ -25,9 +25,15 @@ define(function(require, exports, module) { cfg.kernel_config_map = { // map of parameters for supported kernels "python": { - "library": "import json\nimport yapf.yapflib.yapf_api", - "prefix": "print(json.dumps(yapf.yapflib.yapf_api.FormatCode(u", - "postfix": ")[0]))" + "library": ["import json", + "def yapf_reformat(cell_text):", + " import yapf.yapflib.yapf_api", + " import re", + " cell_text = re.sub('^%', '#%#', cell_text, flags=re.M)", + " reformated_text = yapf.yapflib.yapf_api.FormatCode(cell_text)[0]", + " return re.sub('^#%#', '%', reformated_text, flags=re.M)"].join("\n"), + "prefix": "print(json.dumps(yapf_reformat(u", + "postfix": ")))" }, "r": { "library": "library(formatR)\nlibrary(jsonlite)", diff --git a/code_prettify.yaml b/code_prettify.yaml index 31acbfa..b608014 100644 --- a/code_prettify.yaml +++ b/code_prettify.yaml @@ -55,7 +55,7 @@ Parameters: default: | { "python": { - "library": "import json\nimport yapf.yapflib.yapf_api", + "library": "import json\ndef yapf_reformat(cell_text):\n import yapf.yapflib.yapf_api\n import re\n cell_text = re.sub('^%', '#%#', cell_text, flags=re.M)\n reformated_text = yapf.yapflib.yapf_api.FormatCode(cell_text)[0]\n return re.sub('^#%#', '%', reformated_text, flags=re.M)", "prefix": "print(json.dumps(yapf.yapflib.yapf_api.FormatCode(u", "postfix": ")[0]))" }, From 5c6cf6f887ea7282f09f59ecd92ee9e3d03bda96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Bercher?= Date: Fri, 14 Jul 2017 16:00:00 +0200 Subject: [PATCH 2/3] [code_prettify, autopep8, 2to3] Updated yaml with 5.x compatibility --- 2to3.yaml | 2 +- autopep8.yaml | 2 +- code_prettify.yaml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/2to3.yaml b/2to3.yaml index da827e8..a8ce1c0 100644 --- a/2to3.yaml +++ b/2to3.yaml @@ -3,7 +3,7 @@ Name: 2to3 Converter Description: Converts python2 code in a notebook's code cell to python3 code Link: README_2to3.md Main: 2to3.js -Compatibility: Jupyter (4.x) +Compatibility: Jupyter 4.x, 5.x Parameters: - name: 2to3.add_toolbar_button diff --git a/autopep8.yaml b/autopep8.yaml index 62d0827..b7912ee 100644 --- a/autopep8.yaml +++ b/autopep8.yaml @@ -3,7 +3,7 @@ Name: Autopep8 Description: Use kernel-specific code to reformat/prettify the contents of code cells Link: README_autopep8.md Main: autopep8.js -Compatibility: Jupyter (4.x) +Compatibility: Jupyter 4.x, 5.x Parameters: - name: autopep8.add_toolbar_button diff --git a/code_prettify.yaml b/code_prettify.yaml index b608014..ffedc9c 100644 --- a/code_prettify.yaml +++ b/code_prettify.yaml @@ -3,7 +3,7 @@ Name: Code prettify Description: Use kernel-specific code to reformat/prettify the contents of code cells Link: README_code_prettify.md Main: code_prettify.js -Compatibility: Jupyter (4.x) +Compatibility: Jupyter 4.x, 5.x Parameters: - name: code_prettify.add_toolbar_button From 8f00fb139f72aa2a7a5991e23f78e3b8786970ef Mon Sep 17 00:00:00 2001 From: Josh Barnes Date: Thu, 5 Oct 2017 13:17:55 +0100 Subject: [PATCH 3/3] use textarea input type for easier editing in configurator --- 2to3.yaml | 4 ++-- autopep8.yaml | 4 ++-- code_prettify.yaml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/2to3.yaml b/2to3.yaml index a8ce1c0..66d4c06 100644 --- a/2to3.yaml +++ b/2to3.yaml @@ -46,10 +46,10 @@ Parameters: - name: 2to3.kernel_config_map_json description: | kernel_config_map_json: - json object defining library calls required to load the kernel-specific + json defining library calls required to load the kernel-specific converting modules, and the prefix & postfix for the json-format string required to make the converting call. - input_type: json_object + input_type: textarea default: | { "python": { diff --git a/autopep8.yaml b/autopep8.yaml index b7912ee..99e0853 100644 --- a/autopep8.yaml +++ b/autopep8.yaml @@ -48,10 +48,10 @@ Parameters: - name: autopep8.kernel_config_map_json description: | - json object defining library calls required to load the kernel-specific + json defining library calls required to load the kernel-specific prettifying modules, and the prefix & postfix for the json-format string required to make the prettifying call. - input_type: json_object + input_type: textarea default: | { "python": { diff --git a/code_prettify.yaml b/code_prettify.yaml index ffedc9c..2f5d44b 100644 --- a/code_prettify.yaml +++ b/code_prettify.yaml @@ -48,10 +48,10 @@ Parameters: - name: code_prettify.kernel_config_map_json description: | - json object defining library calls required to load the kernel-specific + json defining library calls required to load the kernel-specific prettifying modules, and the prefix & postfix for the json-format string required to make the prettifying call. - input_type: json_object + input_type: textarea default: | { "python": {