Skip to content
Draft
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
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 4 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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.
Expand Down
40 changes: 40 additions & 0 deletions scripts/run_with_modified_python_path.py
Original file line number Diff line number Diff line change
@@ -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))