diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e12a24fa4..d76adea7e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -39,6 +39,7 @@ jobs: - uses: actions/setup-python@v6 with: python-version: '3.14' + - uses: SublimeText/UnitTesting/actions/setup@v1 - run: pip3 install tox --user - run: echo "$HOME/.local/bin" >> $GITHUB_PATH - run: tox diff --git a/pyproject.toml b/pyproject.toml index c7789a0a6..ebcdb1e92 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,8 +16,8 @@ deps = [ "orjson==3.11.4", ] commands = [ - ["pyright", "plugin", "stubs"], - ["ruff", "check"], + ["python", "scripts/run_with_modified_python_path.py", "python314", "pyright", "plugin", "stubs"], + ["python", "scripts/run_with_modified_python_path.py", "python314", "ruff", "check"], ] [tool.ruff] @@ -45,9 +45,10 @@ order-by-type = false required-imports = ["from __future__ import annotations"] [tool.ruff.lint.per-file-ignores] +"plugin/core/protocol.py" = ["UP006", "UP007"] "plugin/core/typing.py" = ["F401"] "protocol/__init__.py" = ["D400", "D415"] -"plugin/core/protocol.py" = ["UP006", "UP007"] +"scripts/*.py" = ["INP001"] [tool.ruff.lint] # Enable preview rules. diff --git a/scripts/run_with_modified_python_path.py b/scripts/run_with_modified_python_path.py new file mode 100644 index 000000000..059f8526b --- /dev/null +++ b/scripts/run_with_modified_python_path.py @@ -0,0 +1,40 @@ +""" +Wrapper script for setting the PYTHONPATH env var to Sublime's Lib/pythonXY directory. + +This is used for tools like pyright and ruff that can then discover third-party libraries. +See the pyproject.toml file for usage of this script. + +The first argument to this script should be the python directory name inside of Sublime's Lib/ directory. +For instance, it can be "python38" or "python314". + +The rest of the arguments are passed unmodified to subprocess.call. +""" + +from __future__ import annotations + +from pathlib import Path +import os +import platform +import subprocess +import sys + +if platform.system() == "Windows": + config_root = Path.home() / "AppData" / "Roaming" +elif platform.system() == "Darwin": + config_root = Path.home() / "Library" / "Application Support" +else: + config_root = Path.home() / ".config" + +for dirname in ("sublime-text-3", "sublime-text"): + candidate = config_root / dirname + if candidate.is_dir(): + sublime_dir = candidate + break +else: + raise RuntimeError(f"Could not find either 'sublime-text-3' or 'sublime-text' under {config_root}") + +lib_dir = sublime_dir / "Lib" / sys.argv[1] +env = os.environ.copy() +env["PYTHONPATH"] = str(lib_dir) +print("modified PYTHONPATH:", env["PYTHONPATH"]) +raise SystemExit(subprocess.call(sys.argv[2:], env=env))