Python
gspot checks Python code with Ruff, which lints and formats it, with basedpyright for types, with pydoclint for docstrings, and with deptry for dependencies:
| Check | Stage | Level | What it does |
|---|---|---|---|
python/ruff |
commit |
basic |
Lints every Python file with the Ruff rules for the level, security rules included. |
python/ruff-format |
commit |
basic |
Checks the layout of every Python file against the Ruff formatter. |
python/basedpyright |
push |
basic |
Type checks the project. At level all, it also requires annotations. |
python/pydoclint |
commit |
basic |
Checks that each docstring names the arguments, return value, and exceptions of its function. At level all, a one-line docstring names the arguments too. |
python/deptry |
push |
basic |
Compares the imports of the project with the dependencies it declares: missing, unused, and transitive ones. |
python/vulture |
push |
all |
Finds functions, classes, methods, attributes, and properties that no Python file of the scope uses, and code that never runs. |
python/function-size |
commit |
all |
Checks the code line count of each Python function against limits.python.max_function_lines. |
python/pip-installs |
commit |
all |
Checks that pyproject.toml lists every dependency, with no hand-kept requirements file and no pip install. |
python/placeholder-docstrings |
commit |
all |
Finds docstrings that hold a placeholder word, repeat the name of their function or class, or start a class docstring with Class that, Class for, or A class. |
To limit which module may import which, see Import rules. For pytest, see Tests.
Before you start
Section titled “Before you start”In a repository without a package.json, install gspot with mise, as the Quickstart shows.
basedpyright and pytest read the .venv of the project, so manage the project with uv, and run uv sync before
gspot init and again after each new clone.
If you add uv.lock after gspot init, run gspot install so that basedpyright finds .venv. gspot runs Ruff and its
other Python tools on its own Python, so they work whatever Python version your project uses.
Quotes
Section titled “Quotes”Ruff formats Python strings with double quotes. To keep single quotes, run gspot set format.quotes single, which applies
to every language.
Modules from outside the project
Section titled “Modules from outside the project”List the modules that a host application provides in python.externals, as
Modules that the host provides shows. List extra source
folders in python.import_folders, and basedpyright and structure/import-rules then find the modules in them.
When the host application is outside the repository, add a .pth file that names the host folder to the site-packages
folder of .venv. Python and basedpyright read the folder paths in a .pth file, as they do for an editable install:
echo "<host-folder>" > .venv/lib/<python-folder>/site-packages/host.pth<host-folder> is the absolute path of the host application, and <python-folder> is the Python folder of the
environment, such as python3.12.
Unused code and long functions
Section titled “Unused code and long functions”At level all, python/vulture finds functions, classes, and attributes that no file of the scope uses, and code that
never runs. It cannot tell the public API of a library from unused code, so level basic does not run it. A framework
can call a definition by its name, which vulture does not see, so ignore the file that holds such a definition, with a
reason:
gspot ignore python/vulture --paths nodes.py --reason "ComfyUI calls the execute method of each node."At level all, python/function-size allows each function 60 lines. To change the limit, set
limits.python.max_function_lines with a reason.
Docstring style
Section titled “Docstring style”pydoclint takes its docstring style from the first source that sets one, and otherwise uses the NumPy style:
- A
[tool.pydoclint]style inpyproject.toml. - The pydocstyle convention in the Ruff options of the project.
python.docstring_convention, when it equalsgoogleornumpy.- Google or NumPy sections that gspot finds in your docstrings.