This utility converts Sublime Text .sublime-project
files configured for LSP-pyright
to use LSP-basedpyright
. basedpyright
extends the functionality of pyright
by providing enhanced support for Python projects in Sublime Text.
- Automatically converts
LSP-pyright
settings toLSP-basedpyright
settings. - Extracts and maps
LSP-pyright
configurations (e.g.,venvPath
,pythonPath
) to the appropriateLSP-basedpyright
settings. - Processes multiple project files in bulk using standard Linux commands like
find
.
- Python 3.8+
json5
library (pip install json5
)
- Clone the repository:
git clone https://github.com/yourusername/pyright-to-basedpyright.git cd pyright-to-basedpyright
- Install the required Python library:
pip install json5
Run the script with the path to a .sublime-project
file:
python convert_pyright_to_basedpyright.py <path_to_sublime_project>
For example:
python convert_pyright_to_basedpyright.py ~/Projects/myproject.sublime-project
You can use find
to process all .sublime-project
files under a specific directory. Replace <PROJECTS_DIR>
with the directory path containing your Sublime Text projects:
find <PROJECTS_DIR> -name '*.sublime-project' -exec python3 convert_pyright_to_basedpyright.py "{}" \;
For example:
find ~/Projects -name '*.sublime-project' -exec python3 convert_pyright_to_basedpyright.py "{}" \;
- Reads the
.sublime-project
file usingjson5
for permissive parsing. - Extracts existing
LSP-pyright
settings. - Converts the settings to the
LSP-basedpyright
format. - Saves the updated
.sublime-project
file.
{
"settings": {
"LSP": {
"LSP-pyright": {
"settings": {
"python.venvPath": "/path/to/venv",
"python.pythonPath": "/path/to/venv/bin/python",
"python.analysis.extraPaths": ["src"],
"python.analysis.typeCheckingMode": "strict"
}
}
}
}
}
{
"settings": {
"LSP": {
"LSP-basedpyright": {
"settings": {
"venvStrategies": ["env_var_virtual_env"],
"venv": "venv",
"venvPath": "/path/to/venv",
"python.pythonPath": "/path/to/venv/bin/python",
"basedpyright.analysis.extraPaths": ["src"],
"basedpyright.analysis.typeCheckingMode": "strict",
"basedpyright.analysis.reportOptionalSubscript": "error"
}
}
}
}
}
- The script assumes
LSP-pyright
settings are located undersettings.LSP.LSP-pyright
. If your project file structure differs, the script might not work as intended. - Ensure you back up your project files before running the script in batch mode.
This project is licensed under the MIT License. See the LICENSE
file for details.
- Author: Andrea Alberti
- GitHub Profile: alberti42
- Donations:
Feel free to contribute to the development of this plugin or report any issues in the GitHub repository.