Git Product home page Git Product logo

ryantam626 / jupyterlab_code_formatter Goto Github PK

View Code? Open in Web Editor NEW
829.0 9.0 55.0 15.33 MB

A JupyterLab plugin to facilitate invocation of code formatters.

Home Page: https://jupyterlab-code-formatter.readthedocs.io/

License: MIT License

Python 57.67% TypeScript 29.82% Jupyter Notebook 6.70% Shell 0.85% Dockerfile 3.37% JavaScript 1.38% CSS 0.22%
jupyterlab-extension jupyterlab-extensions yapf black code-formatter autopep8 python r

jupyterlab_code_formatter's Introduction

Extension status GitHub Action Status Binder pypi-version

A JupyterLab plugin to facilitate invocation of code formatters.


Documentation: Hosted on ReadTheDocs


Demo


Quick Start

I recommend you going to the documentation site, but this should work too.

  1. Install the package
pip install jupyterlab-code-formatter
  1. Install some supported formatters (isort+black are default for Python)
# NOTE: Install black and isort,
#       JL code formatter is configured to invoke isort and black by default
pip install black isort
  1. Restart JupyterLab

This plugin includes a server plugin, restart JupyterLab if you have followed the above steps while it's running.

  1. Configure plugin

To configure which/how formatters are invoked, see configuration.


Getting help

If you don't use Discord then feel free to open a GitHub issue, do note I am a bit slower in responding in GitHub.


Your Support

I could really use your support in giving me a star on GitHub, recommending features or fixing bugs.


Contributors

This extension was originally developed and maintained by @ryantam626. Massive thanks to the below list of people who made past contributions to the project!

License

This project is licensed under the terms of the MIT LICENSE .

jupyterlab_code_formatter's People

Contributors

akashlakhera avatar dependabot[bot] avatar dev-wei avatar devstein avatar dfm avatar dialvarezs avatar fcollonval avatar felix-cw avatar gnestor avatar graelo avatar ianhi avatar jtpio avatar kanchishimono avatar krassowski avatar lucatrv avatar mcrutch avatar mzakariacern avatar paw-lu avatar rbedi avatar reza1615 avatar rgaiacs avatar ryantam626 avatar sarunasazna avatar shreve avatar simamumu avatar thoralf-gutierrez avatar timlod avatar umangs94 avatar utkarshgupta137 avatar xhochy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jupyterlab_code_formatter's Issues

Icon for Format All in Toolbar

In my commit I never choose an icon for the toolbar because there isn't a natural one. I think we should use one as the toolbar text takes up too much space. I am opening this issue to pick one.

What about:
image (ref)

image
(ref)

Getting 404 in most recent version of jupyterlab

Thanks for the great extension, but I'm having issues getting it to work on the latest version of jupyter lab (1.1.4) on macOS. I'm using the black code formatter with python (everything is installed in the same conda environment). I know that black works, because 1) pip can find it with pip list | grep black and 2) formatting code in my editor (VSCode) with black works just fine.

I see the the format notebook button at the top of my notebook in jupyterlab, and right-clicking on a cell shows the format cell option the dialog, but there are no commands listed in the command palette. Also in the server terminal I keep getting 404 POST /jupyterlab_code_formatter/format?1571308405340 (::1) 1.51ms referer=http://localhost:8888/lab if I ever try to select either format option.

Any recommendations?

isort support

It would be great if support for isort could be added at some point.

(Also, thanks for creating this plugin; it's super useful!)

Add a "string" option to the styler schema for math_token_spacing and reindention

According to the documentation, both math_token spacing and reindention can take a string input if the string is "tidyverse_math_token_spacing()" or " tidyverse_reindention()" respectively.

could the schema have the following?

"styler": {
    "properties": {
        "scope": {
            "type": "string"
        },
        "strict": {
            "type": "boolean"
        },
        "indent_by": {
            "type": "number"
        },
        "start_comments_with_one_space": {
            "type": "boolean"
        },
        "math_token_spacing": {
            "type": "object" or "string"
        },
        "reindention": {
            "type": "object" or "string"
        }
    },
    "additionalProperties": false,
    "type": "object"
}

Pluggable custom formatters

For now the different formatters run in process by importing the Python modules directly. For example:

https://github.com/ryantam626/jupyterlab_code_formatter/blob/ca74872e842ac20e4c9086eb8d008243942e824c/jupyterlab_code_formatter/formatters.py#L75-L78

It would be interesting if we could have them also be pluggable using the notebook server config:

c.JupyterLabCodeFormatter.extra_formatters = {
     "custom": CustomFormatter(),
}

That could be also useful for #24, so users could provide their own formatters if they are not available by default.

R formatting does not work

I tried both conda and pip install. The extension is updated to 0.4. But the R formatter doesn't appear in command.

"This extension does not yet support the current version of JupyterLab."

I've just updated to Version 0.35.0 of JupyterLab on MacOS.

ValueError: This extension does not yet support the current version of JupyterLab.
Conflicting Dependencies:
JupyterLab Extension Package

=0.19.1 <0.20.0 >=0.17.0 <0.19.0 @jupyterlab/application
=0.19.1 <0.20.0 >=0.17.0 <0.19.0 @jupyterlab/notebook

add pep8 setting

Hi,
I want to add this setting in advance setting but it shows syntax error and wouldn't save. what should I do? would you please add some setting example in the README.md

[pep8]
ignore = E226,E302,E41
max-line-length = 160

Release 0.7.1?

Hi,

The new icon added in the last merged PR looks great:

image

Are there any plans to release a new version that would ship the new icon?

Thanks!

conda installer

You might consider to add the instructions for conda installation:

conda install -c conda-forge black
jupyter labextension install @ryantam626/jupyterlab_code_formatter
conda install -c conda-forge jupyterlab_code_formatter
jupyter serverextension enable --py jupyterlab_code_formatter

Additional styler options

If you check of the CRAN documentation for styler, it defaults to tidyverse_style which starts on page 14

there are two more options that are available

example:
indent_by = 2,
start_comments_with_one_space = FALSE

could we have the following in the schema?

    "styler": {
        "properties": {
            "scope": {
                "type": "string"
            },
            "strict": {
                "type": "boolean"
            },
            "indent_by": {
                "type": "number"
            },
            "start_comments_with_one_space": {
                "type": "boolean"
            },
            "math_token_spacing": {
                "type": "object"
            },
            "reindention": {
                "type": "object"
            }
        },
        "additionalProperties": false,
        "type": "object"
    }

Error writing grammar tables

I get an error upon launching Jupyter Lab with this extension enabled:

[I 10:37:25.686 LabApp] Node v10.8.0

[I 10:37:26.075 LabApp] Build is up to date
Generating grammar tables from C:\Users\%USERNAME%\Anaconda3\lib\site-packages\blib2to3\Grammar.txt
Writing grammar tables to C:\Users\%USERNAME%\AppData\Local\black\black\Cache\18.9b0\Grammar3.7.1.final.0.pickle
Writing failed: [Errno 2] No such file or directory: 'C:\\Users\\%USERNAME%\\AppData\\Local\\black\\black\\Cache\\18.9b0\\Grammar3.7.1.final.0.pickle'
Generating grammar tables from C:\Users\%USERNAME%\Anaconda3\lib\site-packages\blib2to3\PatternGrammar.txt
Writing grammar tables to C:\Users\%USERNAME%\AppData\Local\black\black\Cache\18.9b0\PatternGrammar3.7.1.final.0.pickle
Writing failed: [Errno 2] No such file or directory: 'C:\\Users\\%USERNAME%\\AppData\\Local\\black\\black\\Cache\\18.9b0\\PatternGrammar3.7.1.final.0.pickle'

After manually creating the folder C:\\Users\\%USERNAME%\\AppData\\Local\\black\\black\\Cache\\18.9b0 and relaunching Jupyter lab the error disappears (even though the folder seems to stay empty).

Silent error for JupyterLab 0.35.4.

I have a problem to use this extension on JupyterLab 0.35.4.

It seems to have no problem with the installation and I can also see it in my setting.

screen shot 2018-12-27 at 11 46 47 am

However, it doesn't show up in my commands:

screen shot 2018-12-27 at 11 47 52 am

How to debug?

I also did

jupyter labextension check @ryantam626/jupyterlab_code_formatter

It has no problem

@ryantam626/jupyterlab_code_formatter: enabled

styler options for scope

In the best article on styler:
I see there are many more available options that could be passed.

The current available options inside jupyterlab code formatter for styler are

  1. scope = boolean
  2. strict = boolean

According to the docs though styler has several options and scope has more than just 2 options

  1. scope = ("spaces", "indentation", "line-breaks", "tokens")
  2. strict = boolean
  3. math_indentation = list(...)
  4. reindentation = list(...)

Would it be possible to add these additional options?

format options not shown in jupyterlab

The extension is enabled (see below) but for some reason I don't see any format commands available (see screenshot). Any idea what might be going on?

image

jovyan@d3a5e2f1ecd1:~$ jupyter labextension list
JupyterLab v0.35.4
Known labextensions:
   app dir: /usr/local/share/jupyter/lab
        @jupyter-widgets/jupyterlab-manager v0.38.1  enabled  OK
        @jupyterlab/git v0.5.0  enabled  OK
        @ryantam626/jupyterlab_code_formatter v0.1.5  enabled  OK
        jupyterlab-server-proxy v0.1.0-beta2  enabled  OK
Python 3.6.7 (default, Oct 22 2018, 11:32:17)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import black
>>> black.__version__
'18.9b0'

format_str() got an unexpected keyword argument 'line_length'

Just installed with the Black formatter. Using anaconda with Python 3.7 as a base environment. When I hit the "Apply Black Formatter" button, nothing happens, and I see this in the terminal window:

[E 21:34:52.006 LabApp] Uncaught exception POST /jupyterlab_code_formatter/format?1552613692000 (127.0.0.1)
    HTTPServerRequest(protocol='http', host='localhost:8888', method='POST', uri='/jupyterlab_code_formatter/format?1552613692000', version='HTTP/1.1', remote_ip='127.0.0.1')
    Traceback (most recent call last):
      File "/home/matt/anaconda3/lib/python3.7/site-packages/tornado/web.py", line 1697, in _execute
        result = method(*self.path_args, **self.path_kwargs)
      File "/home/matt/anaconda3/lib/python3.7/site-packages/jupyterlab_code_formatter/handlers.py", line 66, in post
        data["code"], **(data["options"] or {})
      File "/home/matt/anaconda3/lib/python3.7/site-packages/jupyterlab_code_formatter/formatters.py", line 36, in format_code
        return format_str(code, **options)[:-1]
    TypeError: format_str() got an unexpected keyword argument 'line_length'
[W 21:34:52.007 LabApp] Unhandled error
[E 21:34:52.008 LabApp] {
      "Host": "localhost:8888",
      "Connection": "keep-alive",
      "Content-Length": "95",
      "Authorization": "token 46089f9488d32aa5e5443396608c78d57921a545d95d4540",
      "Origin": "http://localhost:8888",
      "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.75 Safari/537.36",
      "Dnt": "1",
      "Content-Type": "application/json",
      "Accept": "*/*",
      "Referer": "http://localhost:8888/lab",
      "Accept-Encoding": "gzip, deflate, br",
      "Accept-Language": "en-US,en;q=0.9",
      "Cookie": "username-localhost-9990=\"2|1:0|10:1551064122|23:username-localhost-9990|44:MjQ2YzBlMjczYTdjNDUzMWE0NzIwM2ZkMTdiMGEyMTM=|d2e4285f794b2259e27c87a7758bab7be1f40ce0c613d8bc8a645b2aa06a48ea\"; _xsrf=2|8cc9511d|04ae6d8f70ec186122e19d1d6c5a524d|1552336278; username-localhost-8888=\"2|1:0|10:1552613687|23:username-localhost-8888|44:Nzk5YzUyNTU0MjBlNDBjNzk5MmVlY2Y1MWEwYzYyY2M=|518486b2e7d4ba6f961a09e6abe1458810e6142666057474823c7d9a1ef0c833\
""
    }
[E 21:34:52.009 LabApp] 500 POST /jupyterlab_code_formatter/format?1552613692000 (127.0.0.1) 3.34ms referer=http://localhost:8888/lab```

Code formatters for other languages

It would be interesting to make this extension able to format code written in other languages than Python, by:

  • showing the right formatter to the user based on the file type (related to #4)
  • running the formatters in a subprocess if they are not usable via Python imports directly

Exception: Passing list, expecting str

Hi, this extension fails on exception
with latest JupyterLab 1.14 and latest black 19.3b0.

Exception is exactly printed into console in happens in:

  • file formatters.py
  • class BlackFormatter
  • function: format_code(...)
  • line: code = re.sub("^%", "#%#", code, flags=re.M)

It fails on input argument $code (that is of type list), but should be string

Compatibility with jupyterlab-1.0.0alpha

I'm trying to install latest version of jupyterlab_code_formatter (0.2.1)
Installation fails after executing
jupyter labextension install @ryantam626/jupyterlab_code_formatter.

There is a dependencies conflict:

Conflicting Dependencies:
JupyterLab              Extension              Package
>=1.0.0-alpha.6 <2.0.0  >=0.17.0 <0.20.0       @jupyterlab/application
>=1.0.0-alpha.7 <2.0.0  >=0.17.0 <0.20.0       @jupyterlab/notebook
>=1.0.0-alpha.6 <2.0.0  >=0.17.0 <0.20.0       @jupyterlab/fileeditor

My jupyterlab version is
>jupyter lab --version 1.0.0a3

Internal error 500 upon applying formatter

As the title says, every time I try to apply the code formatter, nothing happens, but looking at the chrome console, I see internal server error 500. The full output is:

Formatting something!
VM3243:formatted:43 Formatting a notebook cell
POST http://localhost:8890/jupyterlab_code_formatter/format?1557762833602 500 (Internal Server Error)
(anonymous) @ VM3243:formatted:43
handleRequest @ serverconnection.js:192
makeRequest @ serverconnection.js:75
request @ index.js:13
maybeFormatCodecell @ index.js:85
execute @ index.js:106
push.5TpB.CommandRegistry.execute @ index.js:351
push.eIPM.CommandPalette._execute @ commandpalette.js:411
push.eIPM.CommandPalette._evtClick @ commandpalette.js:324
push.eIPM.CommandPalette.handleEvent @ commandpalette.js:205
index.js:95 Something went wrong :(
(anonymous) @ index.js:95
Promise.catch (async)
maybeFormatCodecell @ index.js:92
execute @ index.js:106
push.5TpB.CommandRegistry.execute @ index.js:351
push.eIPM.CommandPalette._execute @ commandpalette.js:411
push.eIPM.CommandPalette._evtClick @ commandpalette.js:324
push.eIPM.CommandPalette.handleEvent @ commandpalette.js:205

I'm fairly new to Jupyterlab, but the formatter worked perfectly just a few hours ago.

format does not work

setup as readme, and format button shown in jupyterlab, However it does not work

env:

图片

formatR breaks after upgrading from 0.5.0 and 0.6.0

I just upgraded both the jupyter labextension package and conda package from version 0.5.0 to 0.6.0 and it seems to have broken formatR. FormatR no longer appears as an option among the other python formatters in the edit menu. Styler never appeared in the lsit before but formatR did even though both are installed.

Screen Shot 2019-10-22 at 10 14 12 PM

I have disabled and renabled the extension, gone through the exact install procedure twice, and still no detection of formatR, despite it being an installed package in my R installation.

how to use extra styler options?

Reference used: https://www.tidyverse.org/articles/2017/12/styler-1.0.0/

scope option is a string, fix schema;
Support math_token_spacing by transforming to R list, add to schema;
Support reindention by transforming to R list, add to schema;
Fixes: #63

After updating to the new 0.7.0 version, the new scope option seems to work.

However, I'm trying to figure out how to use the math_token_spacing and reindentation options without much luck.

I see in the schema that they are supposed to be objects though, which I think means I would have to define a class to use them.

How it's input in R:

math_token_spacing = list(one = c("'+'", "'-'"), zero = c("'/'", "'*'", "'^'"))

reindention = list(regex_pattern = "^###", indention = 0, comments_only = TRUE)

Given that the code formatter options file has the below format, how to I get the options above into the "???" portions shown below?

"styler": {
    "scope": "token",
    "strict": false,
    "math_token_spacing": ???,
    "reindentation": ???
},

Ability to format active cell broken in latest version

The following shortcut worked fine on 0.1.6, but is now broken on 0.1.8:

{"jupyterlab_code_formatter:black":{
    "command": "jupyterlab_code_formatter:black",
    "keys": ["F"],
    "selector": ".jp-Notebook:focus"
}}

Error is with line 64, checking if the widget content is not null.

format and format_all don't work

In the jupyterlab code formatter settings you should be able to add hotkeys for format and format_all.

Screen Shot 2019-10-22 at 11 14 30 PM

I added these hotkeys into the settings and they don't seem to work for the Python3 or R notebooks. I note these hotkeys work when I change "format" or "format_all" to "formatR" or "styler".

Format notebook button in notebook:

Screen Shot 2019-10-22 at 11 02 12 PM

Pressing the button inside a Python 3 notebook works as expected as uses default python formatter.

Pressing the button inside a R notebook does nothing

Summary:

  1. the format and format_all don't activate when assigned to hotkeys
  2. "Format Notebook" button in R notebooks does not activate default R formatter
  3. the context menu (right-click inside notebook) only shows "Format Cell" inside Python # notebook and is not in the menu inside R notebooks.

Can't get keyboard shortcut working

I'm able to get the extension to work when I click "Apply Black Formatter" from the Command Palette menu. But I can't get the keyboard shortcut to work. The Command Palette also scrolls back to the top with each use of "Apply Black Formatter," which means that a keyboard shortcut would be really valuable.

Any thoughts?

My setup:

Software Reported Version
Linux kernel release 4.4.0-1065-aws
Ubuntu Ubuntu 18.04.1 LTS
Python Python 3.6.6 :: Anaconda, Inc.
pip pip 18.0 from /home/dsw/miniconda3/lib/python3.6/site-packages/pip (python 3.6)
node v8.11.4
npm 6.4.0
jupyter 4.4.0
black black, version 18.6b4
JupyterLab 0.34.0
@ryantam626/jupyterlab_code_formatter @ryantam626/jupyterlab_code_formatter v0.1.2,enabled,OK
Browser Google Chrome Version 68.0.3440.106 (Official Build) (64-bit)

Excerpt from pip freeze:

$ pip freeze | grep 'jupyter'
jupyter==1.0.0
jupyter-client==5.2.3
jupyter-console==5.2.0
jupyter-contrib-core==0.3.3
jupyter-contrib-nbextensions==0.5.0
jupyter-core==4.4.0
jupyter-highlight-selected-word==0.2.0
jupyter-latex-envs==1.4.4
jupyter-nbextensions-configurator==0.4.0
jupyterlab==0.34.0
jupyterlab-code-formatter==0.1.0
jupyterlab-git==0.2.0
jupyterlab-latex==0.4.0
jupyterlab-launcher==0.13.1

Screenshot of JupyterLab

Compatability error with black 19.10b0

This line performs string comparison, and so reverts to the old API for black 19.10b0
https://github.com/ryantam626/jupyterlab_code_formatter/blob/a32e56ac9ce3943b46e4a9fc794dfb19450432f3/jupyterlab_code_formatter/formatters.py#L41

One solution is to use the packaging module, which is used by setuptools (but it might be vendorised and therefore we should add as a dependency).

This would be added to the module header

from packaging import version

VERSION_BLACK_LEGACY = version.parse("19.3b0")

and the format_code function body

        if version.parse(black.__version__) >= VERSION_BLACK_LEGACY:
            code = black.format_str(code, mode=black.FileMode(**options))[:-1]

error writing grammar tables

I get an error upon launching Jupyter Lab with this extension enabled:

Generating grammar tables from /usr/local/software/jureca/Stages/Devel-2019a/software/Jupyter/2019a-rc19-gcccoremkl-8.3.0-2019.3.199-Python-3.6.8/lib/python3.6/site-packages/blib2to3/Grammar.txt
Writing grammar tables to /p/project/cjsc/goebbert1/.cache/black/19.10b0/Grammar3.6.8.final.0.pickle
Writing failed: [Errno 2] No such file or directory: '/p/project/cjsc/goebbert1/.cache/black/19.10b0/tmpxebasypj'
Generating grammar tables from /usr/local/software/jureca/Stages/Devel-2019a/software/Jupyter/2019a-rc19-gcccoremkl-8.3.0-2019.3.199-Python-3.6.8/lib/python3.6/site-packages/blib2to3/PatternGrammar.txt
Writing grammar tables to /p/project/cjsc/goebbert1/.cache/black/19.10b0/PatternGrammar3.6.8.final.0.pickle
Writing failed: [Errno 2] No such file or directory: '/p/project/cjsc/goebbert1/.cache/black/19.10b0/tmp0pihfitq'

This error appears with black 19.10b0 on CentOS 7.6.

Does not work if jupyter lab started under different user

Hi,
problem is, that this plugin does not work, if jupyter lab is ran under another user
(another user = other user than original one, from which jupyterlab was installed)

If jupyterlab is ran under different user, then whole Jupyterlab works correctly, but this plugin fails to work and prints HTTP 404 errors for each formatting request.

Probable reason is that different user has different home-folder and probably this plugin
(or black module itself) is dependent on some files/configs in the user folder.

(Common motivation to start jupyterlab under different user is to have access to ODBC connections of that user (and authenticate to different DBs)

format option is not in commad pallet and not shown at all

Regarding this issue, I have the same problem, but my jupyter serverextension list is ok and I have installed jupyter_lab_formatter

So what may it be a problem?

λ jupyter serverextension list
config dir: C:\Users\metya\.jupyter
    jupyter_tensorboard enabled
    - Validating...
      jupyter_tensorboard 0.1.8 ok
    nbresuse enabled
    - Validating...
      nbresuse  ok
    jupyterlab_git enabled
    - Validating...
      jupyterlab_git  ok
    jupyterlab_code_formatter enabled
    - Validating...
      jupyterlab_code_formatter  ok
config dir: C:\ProgramData\Anaconda3\etc\jupyter
    jupyterlab enabled
    - Validating...
      jupyterlab 0.35.4 ok
    jupyterlab_github enabled
    - Validating...
      jupyterlab_github 0.7.0 ok
    nbresuse enabled
    - Validating...
      nbresuse  ok
    nbextensions disabled
    - Validating...
Error loading server extension nbextensions
      X is nbextensions importable?
λ jupyter labextension list
JupyterLab v0.35.4
Known labextensions:
   app dir: C:\ProgramData\Anaconda3\share\jupyter\lab
        @deathbeds/jupyterlab_graphviz v0.1.1 enabled  ok
        @ijmbarr/jupyterlab_spellchecker v0.1.4 enabled  ok
        @jupyter-widgets/jupyterlab-manager v0.38.1 enabled  ok
        @jupyterlab/celltags v0.1.4 enabled  ok
        @jupyterlab/geojson-extension v0.18.1 enabled  ok
        @jupyterlab/git v0.4.2 enabled  ok
        @jupyterlab/github v0.10.0 enabled  ok
        @jupyterlab/google-drive v0.16.0 enabled  ok
        @jupyterlab/katex-extension v0.20.0 enabled  ok
        @jupyterlab/latex v0.6.1 enabled  ok
        @jupyterlab/plotly-extension v0.18.1 enabled  ok
        @jupyterlab/statusbar v0.5.0 enabled  ok
        @jupyterlab/toc v0.6.0 enabled  ok
        @krassowski/jupyterlab_go_to_definition v0.1.6 enabled  ok
        @lckr/jupyterlab_variableinspector v0.1.0 enabled  ok
        @mflevine/jupyterlab_html v0.1.4 enabled  ok
        @ryantam626/jupyterlab_code_formatter v0.2.0 enabled  ok
        jupyter-gmaps v0.8.2 enabled  ok
        jupyterlab-chart-editor v1.0.0 enabled  ok
        jupyterlab-jupytext v0.1.0-dev enabled  ok
        jupyterlab_bokeh v0.6.3 enabled  ok
        jupyterlab_nbmetadata v0.1.0 enabled  ok
        jupyterlab_tensorboard v0.1.5 enabled  ok

Compatibility with black 19.3b0

The following error gets thrown when one use the latest version of black. Looks like format_str API changed in black.

[E 12:05:57.351 LabApp] Uncaught exception POST /jupyterlab_code_formatter/format?1558454757345 (::1)
    HTTPServerRequest(protocol='http', host='localhost:8888', method='POST', uri='/jupyterlab_code_formatter/format?1558454757345', version='HTTP/1.1', remote_ip='::1')
    Traceback (most recent call last):
      File "/anaconda3/envs/py36/lib/python3.6/site-packages/tornado/web.py", line 1590, in _execute
        result = method(*self.path_args, **self.path_kwargs)
      File "/anaconda3/envs/py36/lib/python3.6/site-packages/jupyterlab_code_formatter/handlers.py", line 66, in post
        data["code"], **(data["options"] or {})
      File "/anaconda3/envs/py36/lib/python3.6/site-packages/jupyterlab_code_formatter/formatters.py", line 36, in format_code
        return format_str(code, **options)[:-1]
    TypeError: format_str() got an unexpected keyword argument 'line_length'

The following install statement fixes the error
pip install black==18.9b

Allow custom yapf formatting options

Currently the schema for the yapf configuration allows only one of the predefined styles.

Yapf supports custom styles by passing a custom string. From the documentation:

It's also possible to do the same on the command line with a dictionary. For example:
--style='{based_on_style: chromium, indent_width: 4}'

The schema for the yapf formatter should specify that style_config is a string, removing the list of allowed entry

I've changed it in my local configuration and it works correctly with something like
"{based_on_style: google, column_limit: 150}"

Disable commands when no formatter supported

Commands stay enabled for every file type / document currently open, which can be confusing.

Example with json files:

image

The idea would be disable them when they can't be used.

format cammand not shown in jupyterlab

format cammand not shown in jupyterlab started by jupyterhub:
image
but available in setting:
image

my env:

  • jupyterhub: 1.0.0
  • jupyterlab: 1.0.4
  • jupyterlab_code_formatter: 0.1.0 (0.3.0 also tried)
  • autopep8: 1.4.4
  • @ryantam626/jupyterlab_code_formatter: v0.3.0

Could you give me some tips in this case?
Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.