Skip to content

Failed to load hook pylsp_lint: [Errno 2] No such file or directory: '' #369

Closed
@Ultimator14

Description

@Ultimator14

When opening a standalone file (that does not have a project root), pylint crashes and no diagnostics are displayed.

Traceback (most recent call last):
  File "/usr/lib/python3.11/site-packages/pylsp/config/config.py", line 33, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/pluggy/_manager.py", line 327, in traced_hookexec
    return outcome.get_result()
           ^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/pluggy/_result.py", line 60, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/usr/lib/python3.11/site-packages/pluggy/_result.py", line 33, in from_call
    result = func()
             ^^^^^^
  File "/usr/lib/python3.11/site-packages/pluggy/_manager.py", line 324, in <lambda>
    lambda: oldcall(hook_name, hook_impls, kwargs, firstresult)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/pluggy/_callers.py", line 60, in _multicall
    return outcome.get_result()
           ^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/pluggy/_result.py", line 60, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/usr/lib/python3.11/site-packages/pluggy/_callers.py", line 39, in _multicall
    res = hook_impl.function(*args)
          ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/pylsp/plugins/pylint_lint.py", line 220, in pylsp_lint
    return PylintLinter.lint(document, is_saved, flags=flags)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/pylsp/plugins/pylint_lint.py", line 98, in lint
    with Popen(cmd, stdout=PIPE, stderr=PIPE,
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/subprocess.py", line 1024, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib/python3.11/subprocess.py", line 1917, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: ''

The failing code is

with Popen(cmd, stdout=PIPE, stderr=PIPE,
                   cwd=document._workspace.root_path, universal_newlines=True) as process:

with document._workspace.root_path being an empty string. The problem is that the Popen cwd argument is always set, regardless of the root_path. To make this work, the value should be set to the directory of the file if no root path exists.
This works for me

if not (cwd := document._workspace.root_path):
    cwd = os.path.dirname(__file__)

with Popen(cmd, stdout=PIPE, stderr=PIPE,
                   cwd=cwd, universal_newlines=True) as process:

Pylsp version: 1.7.2
Editor: Neovim: 0.8.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions