Skip to content

Commit

Permalink
Increase robustness
Browse files Browse the repository at this point in the history
  • Loading branch information
evhub committed Jun 7, 2024
1 parent d6e527d commit 1d682b7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
8 changes: 7 additions & 1 deletion coconut/command/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,13 @@ def run_type_checking(self, paths=(), code=None):
if code is not None:
logger.warn("--pyright only works on files, not code snippets or at the interpreter")
if paths:
from pyright import main
try:
from pyright import main
except ImportError:
raise CoconutException(
"coconut --pyright requires Pyright",
extra="run '{python} -m pip install coconut[pyright]' to fix".format(python=sys.executable),
)
args = ["--project", config_file, "--pythonversion", self.type_checking_version] + list(paths)
main(args)

Expand Down
2 changes: 1 addition & 1 deletion coconut/command/mypy.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from mypy.api import run
except ImportError:
raise CoconutException(
"--mypy flag requires MyPy library",
"coconut --mypy requires MyPy",
extra="run '{python} -m pip install coconut[mypy]' to fix".format(python=sys.executable),
)

Expand Down
5 changes: 4 additions & 1 deletion coconut/command/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,10 @@ def update_pyright_config(python_version=None):
update_existing = os.path.exists(pyright_config_file)
with univ_open(pyright_config_file, "r+" if update_existing else "w") as config_file:
if update_existing:
config = readfile(config_file, in_json=True)
try:
config = readfile(config_file, in_json=True)
except ValueError:
raise CoconutException("invalid JSON syntax in " + repr(pyright_config_file))
else:
config = extra_pyright_args.copy()
config["extraPaths"] = [install_stubs()]
Expand Down

0 comments on commit 1d682b7

Please sign in to comment.