jupyterlab-contrib / jupyterlab_code_formatter

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

Error message with `styler` formatter: "Formatter styler not found!" #259

Closed firasm closed 2 years ago

firasm commented 2 years ago

Checklist prior to opening an issue

Describe the bug I'm trying to use the styler R formatter, but I keep getting a message Formatter styler not found! even though I've installed it through install.packages('styler') and I can successfully import it in an R jupyter notebook.

Diagnostic commands Please attach the output of the following commands (please format them properly)

Output of `pip freeze` ``` ▶ pip freeze aiohttp==3.7.4.post0 alabaster==0.7.12 altair==4.2.0 altair-data-server==0.4.1 altair-saver==0.5.0 altair-viewer==0.4.0 ansi2html==1.6.0 anyio==3.5.0 appnope==0.1.2 argon2-cffi==21.3.0 argon2-cffi-bindings==21.2.0 asttokens==2.0.5 async-generator==1.10 async-timeout==3.0.1 attrs==21.4.0 Babel==2.9.1 backcall==0.2.0 beautifulsoup4==4.10.0 black==22.1.0 bleach==4.1.0 bokeh==2.4.2 branca==0.4.2 Brotli==1.0.9 bz2file==0.98 certifi==2021.10.8 cffi==1.15.0 chardet==4.0.0 charset-normalizer==2.0.12 chevron==0.14.0 click==8.0.4 cloudpickle==2.0.0 colorama==0.4.4 commonmark==0.9.1 configparser==5.2.0 coverage==6.3.2 coveralls==3.3.1 cryptography==36.0.1 cycler==0.11.0 dash==2.2.0 dash-bootstrap-components==1.0.3 dash-core-components==2.0.0 dash-html-components==2.0.0 dash-table==5.0.0 datascience==0.17.0 debugpy==1.5.1 decorator==5.1.1 defusedxml==0.7.1 discord.py==1.7.3 docopt==0.6.2 docutils==0.16 doit==0.34.2 entrypoints==0.4 et-xmlfile==1.1.0 executing==0.8.3 fastjsonschema==2.15.3 flake8==3.9.2 flake8-quotes==3.3.0 Flask==2.0.3 Flask-Compress==1.11 folium==0.12.1.post1 fonttools==4.29.1 gevent==21.12.0 ghp-import==2.0.2 gitdb==4.0.9 GitPython==3.1.27 greenlet==1.1.2 grip==4.6.1 h11==0.13.0 html2text==2020.1.16 idna==3.3 imagesize==1.3.0 importlib-metadata==4.11.2 iniconfig==1.1.1 ipykernel==6.9.1 ipython==8.1.1 ipython-genutils==0.2.0 ipywidgets==7.6.5 itsdangerous==2.1.0 jedi==0.18.1 Jinja2==3.0.3 joblib==1.1.0 json5==0.9.6 jsonschema==3.2.0 jupyter==1.0.0 jupyter-book==0.12.2 jupyter-cache==0.4.3 jupyter-client==7.1.2 jupyter-console==6.4.2 jupyter-core==4.9.2 jupyter-server==1.17.0 jupyter-server-mathjax==0.2.5 jupyter-sphinx==0.3.2 jupyterlab==3.4.0 jupyterlab-code-formatter==1.4.11 jupyterlab-markup==1.0.1 jupyterlab-pygments==0.1.2 jupyterlab-server==2.10.3 jupyterlab-widgets==1.0.2 jupyterlite==0.1.0b2 jupyterlite-sphinx @ git+https://github.com/jupyterlite/jupyterlite-sphinx.git@60aeb587697bedd3709ead9369657dfc50b8a67b jupytext==1.11.5 kiwisolver==1.3.2 lab==7.0 latexcodec==2.0.1 lazy_loader==0.1rc2 linkify-it-py==1.0.3 lxml==4.6.3 MacFSEvents==0.8.1 Markdown==3.3.6 markdown-it-py==1.1.0 MarkupSafe==2.1.0 matplotlib==3.4.3 matplotlib-inline==0.1.3 mccabe==0.6.1 mdformat==0.7.13 mdit-py-plugins==0.2.8 mergedeep==1.3.4 mistune==0.8.4 mkdocs==1.3.0 mkdocs-material==7.2.6 mkdocs-material-extensions==1.0.3 mpmath==1.2.1 multidict==6.0.2 multipledispatch==0.6.0 mypy-extensions==0.4.3 myst-nb==0.13.2 myst-parser==0.15.2 natsort==8.1.0 nbclassic==0.3.6 nbclient==0.5.12 nbconvert==6.5.0 nbdime==3.1.1 nbformat==5.4.0 nbsphinx==0.8.8 nest-asyncio==1.5.4 networkx==2.6.2 nltk==3.6.2 notebook==6.4.8 notebook-shim==0.1.0 numpy==1.21.2 openpyxl==3.0.7 outcome==1.1.0 packaging==21.3 pandas==1.4.2 pandas-flavor==0.3.0 pandocfilters==1.5.0 parso==0.8.3 path-and-address==2.0.1 pathspec==0.9.0 patsy==0.5.2 pexpect==4.8.0 pickleshare==0.7.5 Pillow==9.0.1 -e git+ssh://git@github.com/phaustin/pl_eoas.git@16ab83f07798acba0357b3230d94c54effd76d2e#egg=pl_eoas platformdirs==2.5.1 plotly==5.6.0 pluggy==1.0.0 portpicker==1.5.0 problem-bank-helpers==0.1.10 problem-bank-scripts==0.2.13 prometheus-client==0.13.1 prompt-toolkit==3.0.28 psutil==5.9.0 ptyprocess==0.7.0 PuLP==2.5.0 pure-eval==0.2.2 py==1.11.0 pybtex==0.24.0 pybtex-docutils==1.0.1 pycodestyle==2.7.0 pycparser==2.21 pycryptodome==3.10.1 pydash==5.1.0 pydata-sphinx-theme==0.7.2 pyflakes==2.3.1 Pygments==2.10.0 pygraphviz==1.9 pyjanitor==0.22.0 pymdown-extensions==9.3 pyOpenSSL==22.0.0 pyparsing==3.0.7 pyquaternion==0.9.9 pyrsistent==0.18.1 PySocks==1.7.1 pytest==6.2.5 python-dateutil==2.8.2 pytz==2021.3 PyYAML==5.4.1 pyyaml_env_tag==0.1 pyzmq==22.3.0 qtconsole==5.2.2 QtPy==2.0.1 recommonmark==0.7.1 regex==2021.8.28 requests==2.27.1 scikit-learn==0.24.2 scipy==1.8.0 seaborn==0.11.2 selenium==4.1.2 Send2Trash==1.8.0 sigfig==1.3.0 simplejson==3.17.6 six==1.16.0 sklearn==0.0 smmap==5.0.0 sniffio==1.2.0 snowballstemmer==2.2.0 sortedcontainers==2.4.0 soupsieve==2.3.1 Sphinx==4.5.0 sphinx-book-theme==0.1.10 sphinx-comments==0.0.3 sphinx-copybutton==0.5.0 sphinx-external-toc==0.2.4 sphinx-jupyterbook-latex==0.4.6 sphinx-markdown-builder==0.5.4 sphinx-multitoc-numbering==0.1.3 sphinx-panels==0.6.0 sphinx-thebe==0.1.1 sphinx-togglebutton==0.3.0 sphinxcontrib-applehelp==1.0.2 sphinxcontrib-bibtex==2.4.1 sphinxcontrib-devhelp==1.0.2 sphinxcontrib-htmlhelp==2.0.0 sphinxcontrib-jsmath==1.0.1 sphinxcontrib-qthelp==1.0.3 sphinxcontrib-serializinghtml==1.1.5 SQLAlchemy==1.4.32 stack-data==0.2.0 statsmodels==0.13.1 sympy==1.8 tenacity==8.0.1 terminado==0.13.2 testpath==0.6.0 text-unidecode==1.3 threadpoolctl==3.1.0 tinycss2==1.1.1 toml==0.10.2 tomli==2.0.1 toolz==0.11.2 tornado==6.1 tqdm==4.64.0 traitlets==5.1.1 trio==0.20.0 trio-websocket==0.9.2 txt2tags==3.7 typing_extensions==4.1.1 tzlocal==2.1 uc-micro-py==1.0.1 unify==0.5 untokenize==0.1.1 urllib3==1.26.8 vega-datasets==0.9.0 watchdog==2.1.7 wcwidth==0.2.5 webencodings==0.5.1 websocket-client==1.3.1 Werkzeug==2.0.3 widgetsnbextension==3.5.2 wsgi-oauth2==0.2.2 wsproto==1.1.0 xarray==2022.3.0 xlrd==2.0.1 yapf==0.32.0 yarl==1.7.2 zipp==3.7.0 zope.event==4.5.0 zope.interface==5.4.0 ```
▶ jupyter labextension list  
JupyterLab v3.4.0
/Users/firasm/.pyenv/versions/3.10.2/share/jupyter/labextensions
        jupyterlab-jupytext v1.3.4 enabled OK (python, jupytext)
        nbdime-jupyterlab v2.1.1 enabled OK
        jupyterlab-plotly v5.6.0 enabled OK
        @agoose77/jupyterlab-markup v1.0.1 enabled OK (python, jupyterlab_markup)
        @ryantam626/jupyterlab_code_formatter v1.4.11 enabled OK (python, jupyterlab-code-formatter)
        @jupyter-widgets/jupyterlab-manager v3.0.1 enabled OK (python, jupyterlab_widgets)

Other labextensions (built into JupyterLab)
   app dir: /Users/firasm/.pyenv/versions/3.10.2/share/jupyter/lab
▶ jupyter serverextension list
config dir: /Users/firasm/.jupyter
    jupyter_nbextensions_configurator  enabled 
    - Validating...
Error loading server extension jupyter_nbextensions_configurator
      X is jupyter_nbextensions_configurator importable?
    nteract_on_jupyter  enabled 
    - Validating...
Error loading server extension nteract_on_jupyter
      X is nteract_on_jupyter importable?
    jupyterlab_code_formatter  enabled 
    - Validating...
      jupyterlab_code_formatter 1.4.11 OK
config dir: /Users/firasm/.pyenv/versions/3.10.2/etc/jupyter
    jupyterlab  enabled 
    - Validating...
      jupyterlab 3.4.0 OK
    jupyterlab_code_formatter  enabled 
    - Validating...
      jupyterlab_code_formatter 1.4.11 OK
    jupytext  enabled 
    - Validating...
      jupytext 1.11.5 OK
    nbdime  enabled 
    - Validating...
      nbdime 3.1.1 OK
config dir: /usr/local/etc/jupyter
    jupyterlab  enabled 
    - Validating...
      jupyterlab 3.4.0 OK
    jupytext  enabled 
    - Validating...
      jupytext 1.11.5 OK
    nbdime  enabled 
    - Validating...
      nbdime 3.1.1 OK
    nteract_on_jupyter  enabled 
    - Validating...
Error loading server extension nteract_on_jupyter
      X is nteract_on_jupyter importable?

Additional context

Autoformatting in Python notebooks works as expected!

Here are my full user prefs on the config file:

{
    "formatOnSave": true,
    "preferences": {
        "default_formatter": {
            "python": "black",
            "r": "styler"
        }
    },
    "black": {
        "line_length": 88,
        "string_normalization": true
    },
    "yapf": {
        "style_config": "google"
    },
    "autopep8": {},
    "isort": {
        "multi_line_output": 3,
        "include_trailing_comma": true,
        "force_grid_wrap": 0,
        "use_parentheses": true,
        "line_length": 88
    },
    "styler": {},
    "formatR": {
        "indent": 2,
        "arrow": true,
        "wrap": true,
        "width_cutoff": 150
    },
    "suppressFormatterErrors": false,

}
ryantam626 commented 2 years ago

Hello!

In the environment where you start jupyter lab, run the following command to check if styler can be imported in the jupyter server python -c "import rpy2.robjects.packages as rpackages; print(rpackages.importr('styler'))"

If there is any error there, then we have correctly diagnosed the problem, we just need to make R and styler available in the jupyter server.

firasm commented 2 years ago

Hi!

Excellent sleuthing! Running that command did give me an error:

▶ python -c "import rpy2.robjects.packages as rpackages; print(rpackages.importr('styler'))"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'rpy2'

But it looks like I was missing a dependency rpy2, which I've now installed using

pip install rpy2

and things are now working perfectly!

Closing the issue since this fixes my problem.