jupyterlab-contrib / jupyterlab_code_formatter

A JupyterLab plugin to facilitate invocation of code formatters.
https://jupyterlab-code-formatter.readthedocs.io/
MIT License
854 stars 55 forks source link

format cammand not shown in jupyterlab #43

Closed potoo0 closed 5 years ago

potoo0 commented 5 years ago

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

my env:

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

ryantam626 commented 5 years ago

Can you show me output of

  1. pip freeze
  2. jupyter labextension list
  3. jupyter serverextension list Please?
kayibal commented 5 years ago

I'm experiencing the same issue

jovyan@f277e4e50d88:~$ pip freeze
aiohttp==3.5.4
alembic==1.0.11
appdirs==1.4.3
asn1crypto==0.24.0
async-generator==1.10
async-timeout==3.0.1
attrs==19.1.0
backcall==0.1.0
black==19.3b0
bleach==3.1.0
blinker==1.4
blosc==1.8.1
bokeh==1.3.1
boto3==1.9.199
botocore==1.12.199
certifi==2019.6.16
certipy==0.1.3
cffi==1.12.3
chardet==3.0.4
Click==7.0
cloudpickle==1.2.1
conda==4.7.10
conda-package-handling==1.3.11
cryptography==2.7
cytoolz==0.10.0
dask==2.0.0
dask-labextension==1.0.0
decorator==4.4.0
defusedxml==0.5.0
distributed==2.2.0
docutils==0.14
entrypoints==0.3
fsspec==0.4.0
graphviz==0.11.1
heapdict==1.0.0
idna==2.8
ipykernel==5.1.1
ipython==7.7.0
ipython-genutils==0.2.0
ipywidgets==7.5.1
isort==4.3.21
jedi==0.14.1
Jinja2==2.10.1
jmespath==0.9.4
json5==0.8.5
jsonschema==3.0.1
jupyter-client==5.3.1
jupyter-core==4.4.0
jupyter-server-proxy==1.1.0
jupyterhub==1.0.0
jupyterlab==1.0.4
jupyterlab-server==1.0.0
libarchive-c==2.8
locket==0.2.0
Mako==1.0.10
MarkupSafe==1.1.1
mistune==0.8.4
msgpack==0.6.1
multidict==4.5.2
nbconvert==5.5.0
nbformat==4.4.0
notebook==6.0.0
numpy==1.16.2
oauthlib==3.0.1
olefile==0.46
packaging==19.0
pamela==1.0.0
pandas==0.23.4
pandocfilters==1.4.2
parso==0.5.1
partd==1.0.0
pexpect==4.7.0
pickleshare==0.7.5
Pillow==6.1.0
prometheus-client==0.7.1
prompt-toolkit==2.0.9
psutil==5.6.3
ptyprocess==0.6.0
pycosat==0.6.3
pycparser==2.19
pycurl==7.43.0.2
Pygments==2.4.2
PyJWT==1.7.1
pyOpenSSL==19.0.0
pyparsing==2.4.2
pyrsistent==0.15.3
PySocks==1.7.0
python-dateutil==2.8.0
python-editor==1.0.4
pytz==2019.2
PyYAML==5.1.2
pyzmq==18.0.2
requests==2.22.0
ruamel-yaml==0.15.71
s3fs==0.3.1
s3transfer==0.2.1
scipy==1.3.0
Send2Trash==1.5.0
simpervisor==0.3
six==1.12.0
sortedcontainers==2.1.0
-e git+https://github.com/datarevenue-berlin/sparsity.git@816afaedcfb57a4875ba840b76435ae467d25896#egg=sparsity
SQLAlchemy==1.3.6
tblib==1.4.0
terminado==0.8.2
testpath==0.4.2
toml==0.10.0
toolz==0.10.0
tornado==6.0.3
tqdm==4.32.2
traitlets==4.3.2
urllib3==1.25.3
wcwidth==0.1.7
webencodings==0.5.1
widgetsnbextension==3.5.1
yarl==1.3.0
zict==1.0.0
jovyan@f277e4e50d88:~$ jupyter labextension list
JupyterLab v1.0.4
Known labextensions:
   app dir: /opt/conda/share/jupyter/lab
        @jupyter-widgets/jupyterlab-manager v1.0.1  enabled  OK
        @krassowski/jupyterlab_go_to_definition v0.6.1  enabled  OK
        @oriolmirosa/jupyterlab_materialdarker v0.4.1  enabled  OK
        @ryantam626/jupyterlab_code_formatter v0.3.0  enabled  OK
        dask-labextension v1.0.0  enabled  OK
        jupyterlab-drawio v0.6.0  enabled  OK
jovyan@f277e4e50d88:~$ jupyter serverextension list
config dir: /opt/conda/etc/jupyter
    dask_labextension  enabled 
    - Validating...
      dask_labextension 1.0.0 OK
    jupyter_server_proxy  enabled 
    - Validating...
      jupyter_server_proxy  OK
    jupyterlab  enabled 
    - Validating...
      jupyterlab 1.0.4 OK
ryantam626 commented 5 years ago

Seems to be missing

pip install jupyterlab_code_formatter
jupyter serverextension enable --py jupyterlab_code_formatter
kayibal commented 5 years ago

Ok seems like I hadn't installed the serverextension.

kayibal commented 5 years ago

Thx!

potoo0 commented 5 years ago

Can you show me output of

  1. pip freeze
  2. jupyter labextension list
  3. jupyter serverextension list Please?
  1. pip freeze | grep jupyter:
    jupyter==1.0.0
    jupyter-client==5.3.1
    jupyter-console==6.0.0
    jupyter-core==4.5.0
    jupyterhub==1.0.0
    jupyterlab==1.0.4
    jupyterlab-code-formatter==0.1.0
    jupyterlab-server==1.0.0

    pip freeze | grep format: jupyterlab-code-formatter==0.1.0 nbformat==4.4.0

    `pip freeze | grep pep`:

    autopep8==1.4.4

  2. jupyter labextension list:
    JupyterLab v1.0.4
    Known labextensions:
    app dir: /usr/local/share/jupyter/lab
        @jupyterlab/hub-extension v1.0.2  enabled  OK
        @jupyterlab/toc v1.0.1  enabled  OK
        @krassowski/jupyterlab_go_to_definition v0.6.1  enabled  OK
        @ryantam626/jupyterlab_code_formatter v0.3.0  enabled  OK
        jupyterlab_bokeh v1.0.0  enabled  OK
  3. jupyter serverextension list:
    config dir: /root/.jupyter
    jupyterlab_code_formatter  enabled
    - Validating...
      jupyterlab_code_formatter  OK
    config dir: /usr/local/etc/jupyter
    jupyterlab  enabled
    - Validating...
      jupyterlab 1.0.4 OK
    jupyterlab_code_formatter  enabled
    - Validating...
      jupyterlab_code_formatter  OK
ryantam626 commented 5 years ago

It's better to have jupyterlab-code-formatter==0.3.0 installed (though it still probably should have worked in theory..)

I would try to upgrade it (pip install -U jupyterlab-code-formatter) then restart jupyter and try the url http://localhost:8888/jupyterlab_code_formatter/formatters (might need to change 8888 to something else) and see if there is anything.

I would also remove your jupyter installation installed with the root user.. That might be interfering with things (and also quite unsafe).

potoo0 commented 5 years ago

OK, thanks.

TLMichael commented 5 years ago

Hi @potoo0 , I would like to know if you resolve this problem? I have the same problem in my jupyterlab.

potoo0 commented 5 years ago

Hi, @TLMichael . When I encountered this problem, I tried downgrade and upgrade jupyterlab-code-formatter, but things didn't turn. One day I tried downgrade and upgrade again, problem solved, I still didn't understand how it works.

vnijs commented 5 years ago

Can this be reopened? I'm having the same issue. I'm trying to set this up in a docker container for my students to down- and upgrading isn't really an option.

ryantam626 commented 5 years ago

Of course! How does your dockerfile look like? Also would be great if you could attach output of the following commands in the docker container:

  1. pip freeze | grep 'jupyterlab\|rpy'
  2. jupyter labextension list
  3. jupyter serverextension list
vnijs commented 5 years ago

Thank you @ryantam626! FYI this extension used to work just fine before upgrading to the latest versions of jupyterlab and related packages.

Here is the relevant part of my Docker file. requirements-base.txt includes jupyterlab_code_formatter.

# install python packages
COPY requirements-base.txt /home/${NB_USER}/requirements.txt
RUN pip3 install -r /home/${NB_USER}/requirements.txt \
  && rm /home/${NB_USER}/requirements.txt \
  && python3 -m bash_kernel.install

ENV APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=DontWarn
RUN curl -sL https://deb.nodesource.com/setup_10.x | bash \
  && apt-get install -y nodejs \
  && npm install -g npm

RUN jupyter labextension install @jupyter-widgets/jupyterlab-manager@1.0 \
  jupyterlab-jupytext \
  @ryantam626/jupyterlab_code_formatter \
  && jupyter serverextension enable --py jupyterlab_code_formatter --system

Below the results of searching for "format"

image

Below the output from the commands you suggested.

jovyan@mini ~ pip3 freeze | grep 'jupyterlab\|rpy'
jupyterlab==1.1.2
jupyterlab-code-formatter==0.5.0
jupyterlab-server==1.0.6
rpy2==3.1.0
jovyan@mini ~ jupyter labextension list
JupyterLab v1.1.2
Known labextensions:
   app dir: /usr/local/share/jupyter/lab
        @jupyter-widgets/jupyterlab-manager v1.0.2  enabled  OK
        @ryantam626/jupyterlab_code_formatter v0.5.0  enabled  OK
        jupyterlab-jupytext v1.0.2  enabled  OK
        jupyterlab-server-proxy v2.0.0  enabled  OK*

   local extensions:
        jupyterlab-server-proxy: /tmp/jupyter-server-proxy/jupyterlab-server-proxy
jovyan@mini ~ jupyter serverextension list
config dir: /usr/etc/jupyter
    jupyter_server_proxy  enabled 
    - Validating...
      jupyter_server_proxy  OK
config dir: /usr/local/etc/jupyter
    jupyter_server_proxy  enabled 
    - Validating...
      jupyter_server_proxy  OK
    jupyterlab  enabled 
    - Validating...
      jupyterlab 1.1.2 OK
    jupytext  enabled 
    - Validating...
      jupytext 1.2.3 OK
    jupyterlab_code_formatter  enabled 
    - Validating...
      jupyterlab_code_formatter  OK
ryantam626 commented 5 years ago

@vnijs actually is your Dockerfile publicly avaliable? I will probably debug faster with that :sweat_smile: since I can't see anything obviously wrong (assuming you did install one of the formatters)

EDIT: Actually I think I know why, the absence of R formatters and presence of rpy2 is crashing the call to query avaliable formatters. Fix incoming.

ryantam626 commented 5 years ago

Also for general knowledge, I realised that the command doesn't show up if you don't have a Python notebook/script opened, this is not properly documented in the README, will do so in a bit. This seems to have been the root cause for issue raised by OP.

ryantam626 commented 5 years ago

@vnijs Could you please try version 0.5.1 and see if it works?

vnijs commented 5 years ago

I haven't used this with R in JupyterLab. I mostly use Rstudio for R code but I do also have the styler package install (but not through conda). All docker materials are linked below in case that helps. I did also try with a Python notebook open but that didn't seem to make a difference.

https://github.com/radiant-rstats/docker/tree/master/rsm-msba

FYI 0.5.1 wasn't available yet. I'll try again in a 30min and report back

ryantam626 commented 5 years ago

Alright, thanks :+1:

With 0.5.0, due to the bug, the plugin won't work unless you have both styler and formatR installed :sweat_smile:

vnijs commented 5 years ago

Everything seems to be working with 0.5.1 @ryantam626. Thanks for the quick fix!

ryantam626 commented 5 years ago

Excellent! :tada:

DonovanAD commented 4 years ago

Hello, I am also experiencing some issues with this extension. I do have the button in the toolbar, but as you can see I do not have it on the left when I search for it. Can you

Screenshot 2020-06-29 at 20 52 07

Screenshot 2020-06-29 at 20 47 44

pip freeze:

absl-py==0.9.0
alabaster==0.7.12
anaconda-client==1.7.2
anaconda-navigator==1.9.12
anaconda-project==0.8.3
appdirs==1.4.3
applaunchservices==0.2.1
appnope==0.1.0
appscript==1.0.1
argh==0.26.2
asn1crypto==1.3.0
astor==0.8.0
astroid==2.3.3
astropy==4.0.1.post1
atomicwrites==1.3.0
attrs==19.3.0
autopep8==1.5
Babel==2.8.0
backcall==0.1.0
backports.functools-lru-cache==1.6.1
backports.os==0.1.1
backports.shutil-get-terminal-size==1.0.0
backports.tempfile==1.0
backports.weakref==1.0.post1
beautifulsoup4==4.8.2
bitarray==1.2.1
bkcharts==0.2
black==19.10b0
bleach==3.1.4
bokeh==2.0.1
boto==2.49.0
Bottleneck==1.3.2
cachetools==4.0.0
certifi==2020.6.20
cffi==1.14.0
chardet==3.0.4
click==7.1.1
cloudpickle==1.3.0
clyent==1.2.2
colorama==0.4.3
conda==4.8.3
conda-build==3.18.11
conda-package-handling==1.6.0
conda-verify==3.4.2
contextlib2==0.6.0.post1
cryptography==2.8
cycler==0.10.0
Cython==0.29.15
cytoolz==0.10.1
dask==2.14.0
decorator==4.4.2
defusedxml==0.6.0
diff-match-patch==20181111
distributed==2.14.0
docutils==0.16
entrypoints==0.3
et-xmlfile==1.0.1
fastcache==1.1.0
fastparquet==0.3.3
fastscript==0.1.4
filelock==3.0.12
flake8==3.7.9
Flask==1.1.1
fsspec==0.7.1
future==0.18.2
gast==0.2.2
gevent==1.4.0
glob2==0.7
gmpy2==2.0.8
google-auth==1.13.1
google-auth-oauthlib==0.4.1
google-pasta==0.2.0
greenlet==0.4.15
grpcio==1.24.3
h5py==2.10.0
HeapDict==1.0.1
hmmlearn==0.2.3
html5lib==1.0.1
hypothesis==5.8.3
idna==2.9
# Editable install with no version control (ieee==0.0.1)
-e /Users/donovanaguilardo/Documents
imageio==2.8.0
imagesize==1.2.0
importlib-metadata==1.5.0
intervaltree==3.0.2
ipykernel==5.1.4
ipython==7.13.0
ipython-genutils==0.2.0
ipywidgets==7.5.1
isort==4.3.21
itsdangerous==1.1.0
jdcal==1.4.1
jedi==0.15.2
Jinja2==2.11.1
joblib==0.14.1
json5==0.9.4
jsonschema==3.2.0
jupyter==1.0.0
jupyter-client==6.1.2
jupyter-console==6.1.0
jupyter-contrib-core==0.3.3
jupyter-contrib-nbextensions==0.5.1
jupyter-core==4.6.3
jupyter-highlight-selected-word==0.2.0
jupyter-latex-envs==1.4.4
jupyter-nbextensions-configurator==0.4.1
jupyterlab==1.2.6
jupyterlab-code-formatter==1.3.1
jupyterlab-server==1.1.0
Keras-Applications==1.0.8
Keras-Preprocessing==1.1.0
keyring==21.1.1
kiwisolver==1.1.0
lazy-object-proxy==1.4.3
libarchive-c==2.8
lief==0.9.0
llvmlite==0.31.0
locket==0.2.0
lxml==4.5.0
Markdown==3.1.1
MarkupSafe==1.1.1
matplotlib==3.1.3
mccabe==0.6.1
mistune==0.8.4
mkl-fft==1.0.15
mkl-random==1.1.0
mkl-service==2.3.0
mock==4.0.1
more-itertools==8.2.0
mpmath==1.1.0
msgpack==1.0.0
multipledispatch==0.6.0
mypy-extensions==0.4.3
navigator-updater==0.2.1
nbconvert==5.6.1
nbdev==0.2.18
nbformat==5.0.4
nbstripout==0.3.7
networkx==2.4
nltk==3.4.5
nose==1.3.7
notebook==6.0.3
numba==0.48.0
numexpr==2.7.1
numpy==1.18.1
numpydoc==0.9.2
oauthlib==3.1.0
olefile==0.46
openpyxl==3.0.3
opt-einsum==3.2.0
packaging==20.3
pandas==1.0.3
pandocfilters==1.4.2
parso==0.5.2
partd==1.1.0
path==13.1.0
pathlib2==2.3.5
pathspec==0.7.0
pathtools==0.1.2
patsy==0.5.1
pep8==1.7.1
pexpect==4.8.0
pickleshare==0.7.5
Pillow==5.4.1
pkginfo==1.5.0.1
pluggy==0.13.1
ply==3.11
prometheus-client==0.7.1
prompt-toolkit==3.0.4
protobuf==3.8.0
psutil==5.7.0
ptyprocess==0.6.0
py==1.8.1
pyarrow==0.15.1
pyasn1==0.4.8
pyasn1-modules==0.2.8
pycodestyle==2.6.0
pycosat==0.6.3
pycparser==2.20
pycrypto==2.6.1
pycurl==7.43.0.5
pydocstyle==4.0.1
pyflakes==2.1.1
Pygments==2.6.1
pylint==2.4.4
PyMuPDF==1.17.0
pyodbc===4.0.0-unsupported
Pyomo==5.6.8
pyOpenSSL==19.1.0
pyparsing==2.4.6
pyrsistent==0.16.0
PySocks==1.7.1
pytest==5.4.1
pytest-arraydiff==0.3
pytest-astropy==0.8.0
pytest-astropy-header==0.1.2
pytest-doctestplus==0.5.0
pytest-openfiles==0.4.0
pytest-remotedata==0.3.2
python-dateutil==2.8.1
python-jsonrpc-server==0.3.4
python-language-server==0.31.9
pytz==2019.3
PyUtilib==5.7.3
PyWavelets==1.1.1
PyYAML==5.3.1
pyzmq==18.1.1
QDarkStyle==2.8
QtAwesome==0.7.0
qtconsole==4.7.2
QtPy==1.9.0
regex==2020.6.8
requests==2.23.0
requests-oauthlib==1.3.0
rope==0.16.0
rpy2==3.3.4
rsa==4.0
Rtree==0.9.3
ruamel-yaml==0.15.87
scikit-image==0.16.2
scikit-learn==0.22.1
scipy==1.4.1
seaborn==0.10.0
Send2Trash==1.5.0
simplegeneric==0.8.1
singledispatch==3.4.0.3
six==1.14.0
snowballstemmer==2.0.0
sortedcollections==1.1.2
sortedcontainers==2.1.0
soupsieve==2.0
Sphinx==2.4.4
sphinxcontrib-applehelp==1.0.2
sphinxcontrib-devhelp==1.0.2
sphinxcontrib-htmlhelp==1.0.3
sphinxcontrib-jsmath==1.0.1
sphinxcontrib-qthelp==1.0.3
sphinxcontrib-serializinghtml==1.1.4
sphinxcontrib-websupport==1.2.1
spyder==4.1.2
spyder-kernels==1.9.0
SQLAlchemy==1.3.15
statsmodels==0.11.0
sympy==1.5.1
tables==3.5.1
tb-nightly==1.15.0a20190806
tblib==1.6.0
tensorboard==2.1.1
tensorflow==2.1.0
tensorflow-estimator==2.1.0
tensorflow-probability==0.9.0
termcolor==1.1.0
terminado==0.8.3
testpath==0.4.4
tf-estimator-nightly==1.14.0.dev2019080601
thrift==0.11.0
toml==0.10.1
toolz==0.10.0
torch==1.4.0
tornado==6.0.4
tqdm==4.44.1
traitlets==4.3.3
typed-ast==1.4.1
typing-extensions==3.7.4.1
tzlocal==2.1
ujson==1.35
unicodecsv==0.14.1
uritools==3.0.0
urllib3==1.25.8
watchdog==0.10.2
wcwidth==0.1.9
webencodings==0.5.1
Werkzeug==1.0.1
wget==3.2
widgetsnbextension==3.5.1
wrapt==1.12.1
wurlitzer==2.0.0
xlrd==1.2.0
XlsxWriter==1.2.8
xlwings==0.18.0
xlwt==1.3.0
xmltodict==0.12.0
yapf==0.28.0
zict==2.0.0
zipp==2.2.0

jupyter labextension list:

JupyterLab v1.2.6
Known labextensions:
   app dir: /Users/donovanaguilardo/anaconda3/share/jupyter/lab
        @jupyter-widgets/jupyterlab-manager v1.1.0  enabled  OK
        @jupyterlab/toc v2.0.0  enabled  OK
        @ryantam626/jupyterlab_code_formatter v1.1.0  enabled  OK

jupyter serverextension list:

JupyterLab v1.2.6
Known labextensions:
   app dir: /Users/donovanaguilardo/anaconda3/share/jupyter/lab
        @jupyter-widgets/jupyterlab-manager v1.1.0  enabled  OK
        @jupyterlab/toc v2.0.0  enabled  OK
        @ryantam626/jupyterlab_code_formatter v1.1.0  enabled  OK
(base) donovanaguilardo@Donovans-Mini ~ % jupyter serverextension list
config dir: /Users/donovanaguilardo/.jupyter
    jupyter_nbextensions_configurator  enabled 
    - Validating...
      jupyter_nbextensions_configurator 0.4.1 OK
    jupyterlab_code_formatter  enabled 
    - Validating...
      jupyterlab_code_formatter  OK
config dir: /Users/donovanaguilardo/anaconda3/etc/jupyter
    jupyterlab  enabled 
    - Validating...
      jupyterlab 1.2.6 OK
    jupyter_nbextensions_configurator  enabled 
    - Validating...
      jupyter_nbextensions_configurator 0.4.1 OK
    nb_conda disabled
    - Validating...
Error loading server extension nb_conda
      X is nb_conda importable?
    jupyterlab_code_formatter  enabled 
    - Validating...
      jupyterlab_code_formatter  OK
ryantam626 commented 4 years ago

Hi @DonovanAD You have version mismatch, follow this and see if it works https://github.com/ryantam626/jupyterlab_code_formatter/issues/119 Open a new issue if it still doesn't work after that :+1:

DonovanAD commented 4 years ago

Thanks @ryantam626 that solved my issue!

yotkadata commented 1 year ago

Just a note in case others have the same problem: I installed the plugin and everything seemed fine, but it didn't show up. My error was that I installed the plugin in my conda environment that I usually use for Jupyter Lab. I hadn't realized that the plugin had to be installed in the base environment from which I also start Jupyter Lab. Solved the problem for me.