Linting and formatting Python code in Google Colab.
Project description
colablinter
Overview
colablinter is an IPython magic command extension designed specifically for Jupyter and Google Colab notebooks.
It integrates the high-speed linter ruff and import sorter isort to perform code quality checks, fix issues, and enforce formatting standards.
It allows developers to lint and format code on a cell-by-cell basis or check the entire notebook with simple commands.
Magic cell Commands
| Command | Type | Role | Description |
|---|---|---|---|
%%cl_fix |
Cell Magic | Quality Check | Fixes and Formats the current cell's code. |
%%cl_report |
Cell Magic | Quality Report | Displays a linting report for the current cell. |
%cl_autofix |
Line Magic | Auto Format | Activates or deactivates automatic code fixing and formatting before every cell execution. |
%cl_report |
Line Magic | Quality Check | Displays a linting report for the entire saved notebook (requires Google Drive mount). |
After executing a magic command, the original code of the cell is executed (if applicable to the command).
Installation
Requires Python 3.12 or newer.
pip install colablinter
Usage
The extension must be explicitly loaded in the notebook session before use.
%load_ext colablinter
-
Fix and Format cell (
%%cl_fix)%%cl_fixcorrects code and runs the formatter. The cell executes the original code.%%cl_format import sys import os def calculate_long_sum(a,b,c,d,e,f): return (a+b+c)*(d+e+f) # messy
Replaced code:
import os import sys from datetime import datetime def calculate_long_sum(a, b, c, d, e, f): return (a + b + c) * (d + e + f) # messy
-
Check cell quality (
%%cl_report)Use
%%cl_reportto see linting reports for the code below the command.%%cl_check def invalid_code(x): return x + y # 'y' is not defined
Output examples:
---- Code Quality & Style Check Report ---- F821 Undefined name `y` --> notebook_cell.py:3:16 | 2 | def invalid_code(x): 3 | return x + y # 'y' is not defined | ^ | Found 1 error. -------------------------------------------
Note: After the report is displayed, the code in the cell executes as normal. If errors exist (like F821), execution will fail.
-
Check entire notebook (
%cl_report)Use line magic
%cl_reportto check across the entire saved notebook file (requires the notebook to be saved to Google Drive and mounted).%cl_report
-
Activate/Deactivate Auto Format (
%cl_autofix) The%cl_autofixline magic allows you to automatically format code before every code cell is executed.To Activate Auto Formatting:
%cl_autofix on # off when you want to deactivate
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file colablinter-0.1.0.tar.gz.
File metadata
- Download URL: colablinter-0.1.0.tar.gz
- Upload date:
- Size: 8.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1ad0e002a0589f69edac2c063b1fca2f59d1b2b4593a1c66eba932fab4fb90aa
|
|
| MD5 |
7d698f09be22814d45b9b408781e2ab5
|
|
| BLAKE2b-256 |
5e1c910b28cd15f3d5839f227402a717757131b9abda0f7ec4621abc58d4fb6b
|
File details
Details for the file colablinter-0.1.0-py3-none-any.whl.
File metadata
- Download URL: colablinter-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2f01283c44db47bf9004acf971f9abfb1f00df03ec00805e57749d81f1792601
|
|
| MD5 |
8514d4ef509a34e431156030c2d58ae7
|
|
| BLAKE2b-256 |
21f68b4c9aa6b3e035ef0f6fd18fc7044092413160bb3dacfc81ec72a481e607
|