ryantam626 / jupyterlab_black Goto Github PK
View Code? Open in Web Editor NEWA JupyterLab extension to apply Black formatter to code within codecell.
License: MIT License
A JupyterLab extension to apply Black formatter to code within codecell.
License: MIT License
Hi, I'm running the following command:
jupyter labextension install @ryantam626/jupyterlab_black
On a conda python2.7 environment after having run pip install jupyterlab
.
Getting the following result:
(myenv_py27) root@fc865b1b006a:~/Metis12# jupyter labextension install @ryantam626/jupyterlab_black
> /root/anaconda2/envs/myenv_py27/bin/npm pack @ryantam626/jupyterlab_black
npm notice
npm notice package: @ryantam626/[email protected]
npm notice === Tarball Contents ===
npm notice 1.2kB package.json
npm notice 879B CHANGELOG.md
npm notice 1.1kB LICENSE
npm notice 3.3kB README.md
npm notice 231B lib/index.d.ts
npm notice 4.0kB lib/index.js
npm notice 640B schema/settings.json
npm notice 0 style/index.css
npm notice === Tarball Details ===
npm notice name: @ryantam626/jupyterlab_black
npm notice version: 0.2.3
npm notice filename: ryantam626-jupyterlab_black-0.2.3.tgz
npm notice package size: 4.5 kB
npm notice unpacked size: 11.4 kB
npm notice shasum: bc722963db91ae0bde3a63032d116a599983343e
npm notice integrity: sha512-oLL3s4mKROjH6[...]WRZG4lukw7m/A==
npm notice total files: 8
npm notice
ryantam626-jupyterlab_black-0.2.3.tgz
> node /root/anaconda2/envs/myenv_py27/lib/python2.7/site-packages/jupyterlab/staging/yarn.js install
yarn install v1.6.0
(node:8824) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
info No lockfile found.
[1/4] Resolving packages...
warning @jupyterlab/csvviewer-extension > @jupyterlab/apputils > react-dom > fbjs > [email protected]: core-js@<2.6.6 is no longer maintained. Please, upgrade to core-js@3 or at least to actual version of core-js@2.
⠁@ryantam626/jupyterlab_black@file:../extensions/ryantam626-jupyterlab_black-0.2.3.tgz
And that little dot on the left of the last line just keeps spinning - the installation never finishes.
Any ideas what might be happening?
Many thanks
Thanks for making this package available ! But when I tried to install the extension, the following error ensued:
Conflicting Dependencies:
JupyterLab Extension Package
>=0.17.2 <0.18.0 >=0.16.0 <0.17.0 @jupyterlab/application
>=0.17.2 <0.18.0 >=0.16.4 <0.17.0 @jupyterlab/apputils
>=0.17.2 <0.18.0 >=0.16.3 <0.17.0 @jupyterlab/notebook
>=0.17.2 <0.18.0 >=0.16.3 <0.17.0 @jupyterlab/terminal
By going this route, we can just format code in the server, without using subprocess which is IMO hacky as heck.
Py36+ notebook server doesn't impede with python 2 kernels, so that's good enough for me 🤷♂️
I've got the following errors trying to rebuild the extension after upgrading to latest jupyterlab:
An error occured.
ValueError: This extension does not yet support the current version of JupyterLab.
Conflicting Dependencies:
JupyterLab Extension Package
>=1.0.5 <2.0.0 >=0.16.0 <0.20.0@jupyterlab/application
>=1.0.5 <2.0.0 >=0.16.0 <0.20.0@jupyterlab/apputils
>=1.0.5 <2.0.0 >=0.16.0 <0.20.0@jupyterlab/notebook
Current version:
notebook==6.0.1
jupyter==1.0.0
jupyter-client==5.3.1
jupyter-console==6.0.0
jupyter-core==4.4.0
jupyter-server==0.1.1
jupyterlab==1.0.9
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
I'm using jupyterlab_black v0.1.4
, and I'm seeing a strange behavior where code cells are overwritten by what should be executed in a terminal.
I've made a screencast video (as a large GIF) to demonstrate the problem here:
https://github.com/edrogersamfam/jupyterlab_black/blob/bug/terminal_in_codecell/jupyterlab_black_bug_demo.gif
Long story short, attempting to use the Black formatter on a code cell inevitably overwrites the cell with
from black import format_str
with open("/tmp/jupyterlab_black_working.py", "r") as file_:
unformatted = file_.read()
formatted = format_str(unformatted, line_length=110)
with open("/tmp/jupyterlab_black_working.py", "w") as file_:
file_.write(
""
+ formatted
)
�[1mreformatted -�[0m
�[1mAll done! ✨ 🍰 ✨�[0m
�[1m1 file reformatted�[0m.�[0m
Software | Reported Version |
---|---|
Linux | Linux ip-172-32-1-52 4.15.0-1009-aws #9-Ubuntu SMP Wed May 16 15:22:54 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux |
Ubuntu | DISTRIB_DESCRIPTION="Ubuntu 18.04.1 LTS" |
Python | Python 3.6.5 |
pip | pip 18.0 from /home/ubuntu/jupyterlab/lib/python3.6/site-packages/pip (python 3.6) |
jupyter | 4.4.0 |
black | black, version 18.6b4 |
JupyterLab | JupyterLab v0.33.6 |
@ryantam626/jupyterlab_black | @ryantam626/jupyterlab_black v0.1.4 |
Other JupyterLab extensions: | nbdime-jupyterlab v0.4.0 |
After creating and activating a virtualenv, I install extensions for both jupyter notebook and jupyter lab:
python3 -m pip install -U pip
python3 -m pip install --upgrade jupyter_contrib_nbextensions
python3 -m pip install --upgrade jupyter_nbextensions_configurator
python3 -m pip install -U autopep8 nbdime
python3 -m pip install -U jupyterlab black jupyterlab-git jupyterlab_latex
jupyter contrib nbextension install --sys-prefix
jupyter nbextensions_configurator enable --sys-prefix
jupyter nbextension enable toc2/main --user
jupyter nbextension enable code_prettify/autopep8 --user
nbdime extensions --enable --sys-prefix
jupyter labextension install --no-build @ryantam626/jupyterlab_black
jupyter lab build
pip freeze
:appdirs==1.4.3
attrs==18.1.0
autopep8==1.3.5
backcall==0.1.0
black==18.6b4
bleach==2.1.3
certifi==2018.4.16
chardet==3.0.4
click==6.7
colorama==0.3.9
decorator==4.3.0
entrypoints==0.2.3
gitdb2==2.0.4
GitPython==2.1.11
html5lib==1.0.1
idna==2.7
ipykernel==4.8.2
ipython==6.5.0
ipython-genutils==0.2.0
jedi==0.12.1
Jinja2==2.10
jsonschema==2.6.0
jupyter-client==5.2.3
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.33.6
jupyterlab-git==0.1.2
jupyterlab-latex==0.3.1
jupyterlab-launcher==0.11.2
lxml==4.2.4
MarkupSafe==1.0
mistune==0.8.3
nbconvert==5.3.1
nbdime==1.0.2
nbformat==4.4.0
notebook==5.6.0
pandocfilters==1.4.2
parso==0.3.1
pexpect==4.6.0
pickleshare==0.7.4
prometheus-client==0.3.1
prompt-toolkit==1.0.15
psutil==5.4.6
ptyprocess==0.6.0
pycodestyle==2.4.0
Pygments==2.2.0
python-dateutil==2.7.3
PyYAML==3.13
pyzmq==17.1.0
requests==2.19.1
Send2Trash==1.5.0
simplegeneric==0.8.1
six==1.11.0
smmap2==2.0.4
terminado==0.8.1
testpath==0.3.1
toml==0.9.4
tornado==5.1
traitlets==4.3.2
urllib3==1.23
wcwidth==0.1.7
webencodings==0.5.1
I'm really excited to see this extension, and would love to help in any way I can. Thanks for making it.
Is it possible to run the lint when executing the cell or switching to another?
I'm using the 0.2.0 version of jupyterlab-black with python 3.6.5, jupyter lab 0.33.12 within a virtual environment. The jupyter lab runs on an ubuntu 18.04 server and I access to it via my chrome 68, windows 10 laptop.
I installed the extension following the instruction in the readme. But no matter I use the keyboard shortcut or the command in the commands panel, the cell won't format and there will be a line output to the server console.
[W 11:06:18.477 LabApp] 404 POST /jupyterlab_black/format?1534561578476 (192.168.28.224) 2.98ms referer=http://super.lab:8889/lab?
Where the 192.168.28.224
is the IP address of my laptop, http://super.lab:8889/lab?
is the address I access the jupyter lab, and this domain is resolved locally by the same server itself.
jupyter labextension install @ryantam626/jupyterlab_black
pip install https://github.com/ryantam626/jupyterlab_black/archive/master.zip
jupyter serverextension enable --py jupyterlab_black
pip install black
blackPythonBin
set to the path of python of the current virtual environmentPublish notebook server plugin to PyPI, but wait till #5 is done.
Hi and thanks for writing this useful plugin.
I tried installing it and everything in the installation process goes fine.
But when I try to run the formatter I get the following error:
[E 15:04:01.432 LabApp] Uncaught exception POST /jupyterlab_black/format?1543068241426 (::1)
HTTPServerRequest(protocol='http', host='localhost:8888', method='POST', uri='/jupyterlab_black/format?1543068241426', version='HTTP/1.1', remote_ip='::1')
Traceback (most recent call last):
File "/home/myusername/.virtualenvs/notebooks/lib/python3.6/site-packages/tornado/web.py", line 1590, in _execute
result = method(*self.path_args, **self.path_kwargs)
File "/home/myusername/.virtualenvs/notebooks/lib/python3.6/site-packages/jupyterlab_black/handlers.py", line 33, in post
python = data["python"]
KeyError: 'python'
When I add a `print(data) in the line before, I get the following output:
{'code': 'the_python_code_in_the_cell', 'lineLength': 110}
It seems like there should be another attribute that points to the python executable (?).
I am using jupyter (lab) in an virtual env and also have that env configured as the jupyter kernel.
Do you have an idea what could be causing this?
Hi I couldn't seem to get your project working. But I am just trying to uninstall it since it is completely breaking my Juypter Lab. I am not well versed in notebook extensions so could tell me a very quick fix to just delete it?
The formatter doesn't work on Windows.
It would probably work if it used tempfile from the standard lib instead of relying on "/tmp/" always being present.
I get the following when running the formatter:
HTTPServerRequest(protocol='http', host='localhost:8888', method='POST', uri='/jupyterlab_black/format?1536823981888', version='HTTP/1.1', remote_ip='::1')
Traceback (most recent call last):
File "C:\Users\mel\anaconda3\envs\ipython\lib\site-packages\tornado\web.py", line 1590, in _execute
result = method(*self.path_args, **self.path_kwargs)
File "C:\Users\mel\anaconda3\envs\ipython\lib\site-packages\jupyterlab_black\handlers.py", line 36, in post
with open("/tmp/jupyrerlab_black_worker.py", "w") as file_:
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/jupyrerlab_black_worker.py'
[W 09:33:01.904 LabApp] Unhandled error
[E 09:33:01.905 LabApp] {
"Host": "localhost:8888",
"Connection": "keep-alive",
"Content-Length": "270",
"Authorization": "token 4a71058a2add832e29638427cff8a9dcad6c020bf62eb394",
"Origin": "http://localhost:8888",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36",
"Content-Type": "application/json",
"Accept": "*/*",
"Referer": "http://localhost:8888/lab",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "da-DK,da;q=0.9,en-DK;q=0.8,en;q=0.7,en-US;q=0.6",
"Cookie": "_xsrf=2|79b9938f|7c699e97e3b5bdee56707a51dd633955|1536130147; username-localhost-8889=\"2|1:0|10:1536301346|23:username-localhost-8889|44:YmNkMDQ1ZDNlZWFmNGE2MTk5MGI4MmY5NmI5NjUyNzQ=|6ac5ca7d28af0515e042887b5ed5b320620ee49e3a22b0c7048f02dd88213105\"; username-localhost-8888=\"2|1:0|10:1536823980|23:username-localhost-8888|44:MmIwYWQzOGQ2Mzk5NGJkMjg1NTM1ZDU4NDhkMmNjMTk=|e7a7ab793d0b1809c108c3304bfa5ce6f319bd1ec0b9943ca6202858486e04a4\""
}
[E 09:33:01.911 LabApp] 500 POST /jupyterlab_black/format?1536823981888 (::1) 13.00ms referer=http://localhost:8888/lab
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.