gui.editor.find_code(which=shutil.which, platform=None, exists=os.path.exists)
The code command of VS Code, or None when VS Code is not installed.
code on the PATH wins. Otherwise the places of CODE_LOCATIONS are tried for the platform.
Parameters
| which |
Callable[[str], str | None] |
Looks up an executable on the PATH; replaceable for tests. |
shutil.which |
| platform |
str | None |
The platform name. Defaults to sys.platform. |
None |
| exists |
Callable[[str], bool] |
Tells whether a path exists; replaceable for tests. |
os.path.exists |
Returns
|
str | None |
str | None: "code" when it is on the PATH, else the absolute path of the command, else None. |
Examples
from spotregen.gui.editor import find_code
print(find_code(lambda name: "/usr/local/bin/code", "darwin"))
print(find_code(lambda name: None, "darwin", lambda path: "Applications" in path))
print(find_code(lambda name: None, "linux", lambda path: False))
code
/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code
None