Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Ultimator14 opened this issue Apr 13, 2023 · 2 comments · Fixed by #371
Closed

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

Ultimator14 opened this issue Apr 13, 2023 · 2 comments · Fixed by #371
Milestone

Comments

@Ultimator14
Copy link
Contributor

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

@mxkrsv
Copy link

mxkrsv commented Apr 23, 2023

Same here, neovim log:

[ERROR][2023-04-23 14:41:10] .../vim/lsp/rpc.lua:734	"rpc"	"pylsp"	"stderr"	"2023-04-23 14:41:10,325 MSK - WARNING - pylsp.config.config - Failed to load hook pylsp_lint: [Errno 2] No such file or directory: ''\nTraceback (most recent call last):\n  File \"/nix/store/mdmff1mbn88k2nqkjnwk64fzn6ij2672-python3.10-python-lsp-server-1.7.2/lib/python3.10/site-packages/pylsp/config/config.py\", line 33, in _hookexec\n    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)\n  File \"/nix/store/73qfz3nks3pv4msd5vz23hcl7k1v96vw-python3.10-pluggy-1.0.0/lib/python3.10/site-packages/pluggy/_manager.py\", line 327, in traced_hookexec\n    return outcome.get_result()\n  File \"/nix/store/73qfz3nks3pv4msd5vz23hcl7k1v96vw-python3.10-pluggy-1.0.0/lib/python3.10/site-packages/pluggy/_result.py\", line 60, in get_result\n    raise ex[1].with_traceback(ex[2])\n  File \"/nix/store/73qfz3nks3pv4msd5vz23hcl7k1v96vw-python3.10-pluggy-1.0.0/lib/python3.10/site-packages/pluggy/_result.py\", line 33, in from_call\n    result = func()\n  File \"/nix/store/73qfz3nks3pv4msd5vz23hcl7k1v96vw-python3.10-pluggy-1.0.0/lib/python3.10/site-packages/pluggy/_manager.py\", line 324, in <lambda>\n    lambda: oldcall(hook_name, hook_impls, kwargs, firstresult)\n  File \"/nix/store/73qfz3nks3pv4msd5vz23hcl7k1v96vw-python3.10-pluggy-1.0.0/lib/python3.10/site-packages/pluggy/_callers.py\", line 60, in _multicall\n    return outcome.get_result()\n  File \"/nix/store/73qfz3nks3pv4msd5vz23hcl7k1v96vw-python3.10-pluggy-1.0.0/lib/python3.10/site-packages/pluggy/_result.py\", line 60, in get_result\n    raise ex[1].with_traceback(ex[2])\n  File \"/nix/store/73qfz3nks3pv4msd5vz23hcl7k1v96vw-python3.10-pluggy-1.0.0/lib/python3.10/site-packages/pluggy/_callers.py\", line 39, in _multicall\n    res = hook_impl.function(*args)\n  File \"/nix/store/mdmff1mbn88k2nqkjnwk64fzn6ij2672-python3.10-python-lsp-server-1.7.2/lib/python3.10/site-packages/pylsp/plugins/pylint_lint.py\", line 220, in pylsp_lint\n    return PylintLinter.lint(document, is_saved, flags=flags)\n  File \"/nix/store/mdmff1mbn88k2nqkjnwk64fzn6ij2672-python3.10-python-lsp-server-1.7.2/lib/python3.10/site-packages/pylsp/plugins/pylint_lint.py\", line 98, in lint\n    with Popen(cmd, stdout=PIPE, stderr=PIPE,\n  File \"/nix/store/fdqpyj613dr0v1l1lrzqhzay7sk4xg87-python3-3.10.10/lib/python3.10/subprocess.py\", line 971, in __init__\n    self._execute_child(args, executable, preexec_fn, close_fds,\n  File \"/nix/store/fdqpyj613dr0v1l1lrzqhzay7sk4xg87-python3-3.10.10/lib/python3.10/subprocess.py\", line 1847, in _execute_child\n    raise child_exception_type(errno_num, err_msg, err_filename)\nFileNotFoundError: [Errno 2] No such file or directory: ''\n"

@ccordoba12
Copy link
Member

Hey @Ultimator14, thanks for reporting this problem and finding a solution for it! Would you like to submit a pull request with your fix?

@ccordoba12 ccordoba12 added this to the v1.7.3 milestone Apr 24, 2023
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue May 21, 2023
## Version 1.7.3 (2023/05/15)

### Issues Closed

* [Issue 369](python-lsp/python-lsp-server#369) - Failed to load hook pylsp_lint: [Errno 2] No such file or directory: '' ([PR 371](python-lsp/python-lsp-server#371) by [@Ultimator14](https://github.com/Ultimator14))

In this release 1 issue was closed.

### Pull Requests Merged

* [PR 377](python-lsp/python-lsp-server#377) - Update yapf requirement to 0.33+, by [@bnavigator](https://github.com/bnavigator)
* [PR 371](python-lsp/python-lsp-server#371) - Fix empty cwd value for pylint, by [@Ultimator14](https://github.com/Ultimator14) ([369](python-lsp/python-lsp-server#369))
* [PR 364](python-lsp/python-lsp-server#364) - Add Arch Linux installation command to Readme, by [@GNVageesh](https://github.com/GNVageesh)

In this release 3 pull requests were closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants