swyddfa / esbonio

A language server for working with Sphinx projects.
https://docs.esbon.io/
131 stars 21 forks source link

Fail to render preview #886

Closed scotgopal closed 2 weeks ago

scotgopal commented 1 month ago

Expected behavior

When the render button (see image below) is clicked or if Ctrl+Shift+V keyboard combination, the rendered view of the .rst file should open to the side.

Esbonio version: v0.11.0

image

Actual behavior

Nothing happens.

Log output

Running Sphinx v8.0.2
loading translations [en]...
done
[esbonio.lsp] Traceback (most recent call last):
  File "/home/scotrraajgopal/setuptools/venv/lib/python3.10/site-packages/sphinx/registry.py", line 448, in load_extension
    mod = import_module(extname)
  File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 992, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 992, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1004, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'jaraco'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/scotrraajgopal/setuptools/venv/lib/python3.10/site-packages/esbonio/lsp/sphinx/__init__.py", line 149, in _initialize_sphinx
    return self.create_sphinx_app(self.user_config)  # type: ignore
  File "/home/scotrraajgopal/setuptools/venv/lib/python3.10/site-packages/esbonio/lsp/sphinx/__init__.py", line 343, in create_sphinx_app
    app = Sphinx(**self.sphinx_args)
  File "/home/scotrraajgopal/setuptools/venv/lib/python3.10/site-packages/sphinx/application.py", line 253, in __init__
    self.setup_extension(extension)
  File "/home/scotrraajgopal/setuptools/venv/lib/python3.10/site-packages/sphinx/application.py", line 429, in setup_extension
    self.registry.load_extension(self, extname)
  File "/home/scotrraajgopal/setuptools/venv/lib/python3.10/site-packages/sphinx/registry.py", line 451, in load_extension
    raise ExtensionError(__('Could not import extension %s') % extname,
sphinx.errors.ExtensionError: Could not import extension jaraco.packaging.sphinx (exception: No module named 'jaraco')

(Optional) Settings from conf.py

No response

alcarney commented 1 month ago

Could not import extension jaraco.packaging.sphinx (exception: No module named 'jaraco')

It looks like Esbonio is not using the right environment for your project.

In order to work correctly, Esbonio needs to use the same Python environment you use when building your docs outside of VSCode. Have you tried using the Python: Select Interpter and/or setting the esbonio.server.pythonPath option to select a different environment?

scotgopal commented 1 month ago

I can confirm that during the installation of the extension, Esbonio installed itself in my virtualenv.

image

I have used Python: Select Interpreter to ensure the correct selection of interpreter for this workspace and also have set the following in my workspace's settings.json

{
    "esbonio.server.pythonPath": "/home/scotrraajgopal/setuptools/venv/bin/python"
}

I then reloaded VSCode, but still no changes.

scotgopal commented 1 month ago

I took things into my own hands and started pip installing the following packages into my virtualenv as they emerge as an ImportError in esbonio's output in VSCode:-

  1. jaraco.packaging
  2. rst.linker
  3. sphinx-inline-tabs
  4. sphinxcontrib-towncrier
  5. jaraco.tidelift

Now I'm facing the following error:-

Running Sphinx v8.0.2
loading translations [en]...
done
[esbonio.lsp] Traceback (most recent call last):
  File "/home/scotrraajgopal/setuptools/venv/lib/python3.10/site-packages/sphinx/events.py", line 100, in emit
    results.append(listener.handler(self.app, *args))
  File "/home/scotrraajgopal/setuptools/venv/lib/python3.10/site-packages/jaraco/packaging/sphinx.py", line 115, in load_config_from_setup
    meta = _load_metadata_from_wheel() or jp_metadata.load(root)
  File "/home/scotrraajgopal/setuptools/venv/lib/python3.10/site-packages/jaraco/packaging/metadata.py", line 15, in load
    return util.project_wheel_metadata(source_dir, isolated, **kwargs)
  File "/home/scotrraajgopal/setuptools/venv/lib/python3.10/site-packages/build/util.py", line 49, in project_wheel_metadata
    env.install(builder.get_requires_for_build('wheel'))
  File "/home/scotrraajgopal/setuptools/venv/lib/python3.10/site-packages/build/_builder.py", line 219, in get_requires_for_build
    with self._handle_backend(hook_name):
  File "/usr/lib/python3.10/contextlib.py", line 153, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/home/scotrraajgopal/setuptools/venv/lib/python3.10/site-packages/build/_builder.py", line 339, in _handle_backend
    raise BuildBackendException(
build._exceptions.BuildBackendException: Backend 'setuptools.build_meta' is not available.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/scotrraajgopal/setuptools/venv/lib/python3.10/site-packages/esbonio/lsp/sphinx/__init__.py", line 149, in _initialize_sphinx
    return self.create_sphinx_app(self.user_config)  # type: ignore
  File "/home/scotrraajgopal/setuptools/venv/lib/python3.10/site-packages/esbonio/lsp/sphinx/__init__.py", line 343, in create_sphinx_app
    app = Sphinx(**self.sphinx_args)
  File "/home/scotrraajgopal/setuptools/venv/lib/python3.10/site-packages/sphinx/application.py", line 277, in __init__
    self.events.emit('config-inited', self.config)
  File "/home/scotrraajgopal/setuptools/venv/lib/python3.10/site-packages/sphinx/events.py", line 111, in emit
    raise ExtensionError(
sphinx.errors.ExtensionError: Handler <function load_config_from_setup at 0x7f9a01f177f0> for event 'config-inited' threw an exception (exception: Backend 'setuptools.build_meta' is not available.)

For context, I'm trying to view the RSTs from setuptools repo v59.8.0

I have setuptools v65.5.0 installed in the virtualenv.

alcarney commented 1 month ago

It looks like you are still running into errors specific to the setuptools docs (which unfortunately I cannot help that much with).

I have setuptools v65.5.0 installed in the virtualenv.

I'm certainly not a setuptools expert, but there is a chance that is conflicting with the version of setuptools you're trying to build the docs for.

Looking at their developer guide they use tox to build the docs

$ tox -e docs

It might be worth giving that a go, tox will create it's own isolated envrionment - probably in a path like /home/.../setuptools/.tox/docs which you can then tell Esbonio to use.


It might also be worth trying the pre-release version of Esbonio (v0.95.1), it will remove the requirement of having to install the esbonio Python package into the docs environment tox creates. If you do try it, just note the configuration is slightly different, instead of

// v0.11.0
{
    "esbonio.server.pythonPath": "/home/scotrraajgopal/setuptools/venv/bin/python"
}

You would need

// v0.95.1
{
    "esbonio.sphinx.pythonCommand": ["/home/scotrraajgopal/setuptools/venv/bin/python"]
}
scotgopal commented 1 month ago

Thank you for your kind support @alcarney . I have already tried tox -e docs on v59.8.0 tag, but there seems to be an error, plus I'm only interested with viewing one of the .rst in their docs. Hence, I looked for an extension and came across esbonio.

I have tried to use the pre-release version and updated the settings.json, but even then, I face the same issues as the release version.

I then checked-out setuptools's main branch and created a new venv. On this branch, I have no errors running tox -e docs. But after re-installing esbonio Release Version, I am slightly dissapointed that it too doesn't work.

As a final resort, I am simply copy-pasting the content I want to read in an online rst viewer.

Maybe I'd have a better chance to debug this once I better understand how Sphinx works.

Pls do close this issue if this case doesn't need any more attention.

alcarney commented 2 weeks ago

No worries! Sorry to hear you couldn't get it working, feel free to open another issue if you need help in the future :)