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

Allow customization of mypy executable path #96

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ Configuration
- Type
- Description
- Default
* - ``executable``
- ``pylsp.plugins.pylsp_mypy.executable``
- ``string``
- **Set a custom mypy executable location**. If not set, it will find from the current shell's ``PATH``.
* - ``live_mode``
- ``pylsp.plugins.pylsp_mypy.live_mode``
- ``boolean``
Expand Down
11 changes: 7 additions & 4 deletions pylsp_mypy/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,15 +301,18 @@ def get_diagnostics(
exit_status = 0

if not dmypy:
executable = settings.get("executable", None)
if executable is None:
executable = shutil.which("mypy")
args.extend(["--incremental", "--follow-imports", settings.get("follow-imports", "silent")])
args = apply_overrides(args, overrides)

if shutil.which("mypy"):
# mypy exists on path
# -> use mypy on path
if executable is not None:
# mypy exists on the configured location or path
# -> use mypy there
log.info("executing mypy args = %s on path", args)
completed_process = subprocess.run(
["mypy", *args], capture_output=True, **windows_flag, encoding="utf-8"
[executable, *args], capture_output=True, **windows_flag, encoding="utf-8"
)
report = completed_process.stdout
errors = completed_process.stderr
Expand Down