colablinter 0.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- colablinter-0.0.1/LICENSE +21 -0
- colablinter-0.0.1/PKG-INFO +101 -0
- colablinter-0.0.1/README.md +82 -0
- colablinter-0.0.1/pyproject.toml +29 -0
- colablinter-0.0.1/setup.cfg +4 -0
- colablinter-0.0.1/src/colablinter/__init__.py +10 -0
- colablinter-0.0.1/src/colablinter/magics.py +81 -0
- colablinter-0.0.1/src/colablinter.egg-info/PKG-INFO +101 -0
- colablinter-0.0.1/src/colablinter.egg-info/SOURCES.txt +10 -0
- colablinter-0.0.1/src/colablinter.egg-info/dependency_links.txt +1 -0
- colablinter-0.0.1/src/colablinter.egg-info/requires.txt +3 -0
- colablinter-0.0.1/src/colablinter.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 RektPunk
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: colablinter
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Linting and formatting Python code in Google Colab.
|
|
5
|
+
Author-email: RektPunk <rektpunk@gmail.com>
|
|
6
|
+
Project-URL: repository, https://github.com/RektPunk/colablinter
|
|
7
|
+
Keywords: jupyter,colab,ipython,magic,ruff,isort,linter
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Classifier: Framework :: IPython
|
|
12
|
+
Requires-Python: >=3.12
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Requires-Dist: ipython>=7.34.0
|
|
16
|
+
Requires-Dist: isort>=7.0.0
|
|
17
|
+
Requires-Dist: ruff>=0.14.8
|
|
18
|
+
Dynamic: license-file
|
|
19
|
+
|
|
20
|
+
# colablinter
|
|
21
|
+
|
|
22
|
+
[](https://pypi.org/project/colablinter/)
|
|
23
|
+
[](https://opensource.org/licenses/MIT)
|
|
24
|
+
|
|
25
|
+
## Overview
|
|
26
|
+
|
|
27
|
+
**`colablinter`** is an **IPython magic command extension** for Jupyter and Google Colab environments.
|
|
28
|
+
|
|
29
|
+
It integrates the high-speed linter **`ruff`** and import sorter **`isort`** to perform cell-by-cell code quality and formatting checks.
|
|
30
|
+
|
|
31
|
+
## Magic Commands
|
|
32
|
+
|
|
33
|
+
| Command | Role | Description |
|
|
34
|
+
| :--- | :--- | :--- |
|
|
35
|
+
| **`%%check`** | **Quality Check** | Displays a linting report. |
|
|
36
|
+
| **`%%format`** | **Format, Sort** | Displays a formatting preview (**for copy/paste**) |
|
|
37
|
+
|
|
38
|
+
After executing a magic command, the **original code** of the cell is executed (if applicable to the command).
|
|
39
|
+
|
|
40
|
+
## Installation
|
|
41
|
+
|
|
42
|
+
Requires Python 3.12 or newer.
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
pip install colablinter
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Usage
|
|
49
|
+
The extension must be explicitly loaded in the notebook session before use.
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
%load_ext colablinter
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
1. Check Code Quality
|
|
56
|
+
|
|
57
|
+
Use `%%check` to see linting reports.
|
|
58
|
+
```python
|
|
59
|
+
%%check
|
|
60
|
+
|
|
61
|
+
def invalid_code(x):
|
|
62
|
+
return x + y # 'y' is not defined
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Output examples:
|
|
66
|
+
```bash
|
|
67
|
+
--- Code Quality & Style Check Report ---
|
|
68
|
+
F821 Undefined name `y`
|
|
69
|
+
--> notebook_cell.py:4:16
|
|
70
|
+
|
|
|
71
|
+
2 | def invalid_code(x):
|
|
72
|
+
3 | return x + y # 'y' is not defined
|
|
73
|
+
| ^
|
|
74
|
+
|
|
|
75
|
+
|
|
76
|
+
Found 1 error.
|
|
77
|
+
-------------------------------------------
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
2. Format code preview
|
|
81
|
+
|
|
82
|
+
`%%format` will display the formatted code, but the cell executes the original code.
|
|
83
|
+
```python
|
|
84
|
+
%%format
|
|
85
|
+
import sys
|
|
86
|
+
import os
|
|
87
|
+
def calculate_long_sum(a,b,c,d,e,f):
|
|
88
|
+
return (a+b+c)*(d+e+f) # messy
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Output examples:
|
|
92
|
+
```python
|
|
93
|
+
# Formatted Code
|
|
94
|
+
import os
|
|
95
|
+
import sys
|
|
96
|
+
from datetime import datetime
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def calculate_long_sum(a, b, c, d, e, f):
|
|
100
|
+
return (a + b + c) * (d + e + f) # messy
|
|
101
|
+
```
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# colablinter
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/colablinter/)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
|
|
6
|
+
## Overview
|
|
7
|
+
|
|
8
|
+
**`colablinter`** is an **IPython magic command extension** for Jupyter and Google Colab environments.
|
|
9
|
+
|
|
10
|
+
It integrates the high-speed linter **`ruff`** and import sorter **`isort`** to perform cell-by-cell code quality and formatting checks.
|
|
11
|
+
|
|
12
|
+
## Magic Commands
|
|
13
|
+
|
|
14
|
+
| Command | Role | Description |
|
|
15
|
+
| :--- | :--- | :--- |
|
|
16
|
+
| **`%%check`** | **Quality Check** | Displays a linting report. |
|
|
17
|
+
| **`%%format`** | **Format, Sort** | Displays a formatting preview (**for copy/paste**) |
|
|
18
|
+
|
|
19
|
+
After executing a magic command, the **original code** of the cell is executed (if applicable to the command).
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
Requires Python 3.12 or newer.
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install colablinter
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Usage
|
|
30
|
+
The extension must be explicitly loaded in the notebook session before use.
|
|
31
|
+
|
|
32
|
+
```python
|
|
33
|
+
%load_ext colablinter
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
1. Check Code Quality
|
|
37
|
+
|
|
38
|
+
Use `%%check` to see linting reports.
|
|
39
|
+
```python
|
|
40
|
+
%%check
|
|
41
|
+
|
|
42
|
+
def invalid_code(x):
|
|
43
|
+
return x + y # 'y' is not defined
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Output examples:
|
|
47
|
+
```bash
|
|
48
|
+
--- Code Quality & Style Check Report ---
|
|
49
|
+
F821 Undefined name `y`
|
|
50
|
+
--> notebook_cell.py:4:16
|
|
51
|
+
|
|
|
52
|
+
2 | def invalid_code(x):
|
|
53
|
+
3 | return x + y # 'y' is not defined
|
|
54
|
+
| ^
|
|
55
|
+
|
|
|
56
|
+
|
|
57
|
+
Found 1 error.
|
|
58
|
+
-------------------------------------------
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
2. Format code preview
|
|
62
|
+
|
|
63
|
+
`%%format` will display the formatted code, but the cell executes the original code.
|
|
64
|
+
```python
|
|
65
|
+
%%format
|
|
66
|
+
import sys
|
|
67
|
+
import os
|
|
68
|
+
def calculate_long_sum(a,b,c,d,e,f):
|
|
69
|
+
return (a+b+c)*(d+e+f) # messy
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Output examples:
|
|
73
|
+
```python
|
|
74
|
+
# Formatted Code
|
|
75
|
+
import os
|
|
76
|
+
import sys
|
|
77
|
+
from datetime import datetime
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def calculate_long_sum(a, b, c, d, e, f):
|
|
81
|
+
return (a + b + c) * (d + e + f) # messy
|
|
82
|
+
```
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "colablinter"
|
|
3
|
+
version = "0.0.1"
|
|
4
|
+
description = "Linting and formatting Python code in Google Colab."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
authors = [
|
|
7
|
+
{name = "RektPunk", email = "rektpunk@gmail.com"},
|
|
8
|
+
]
|
|
9
|
+
keywords = ["jupyter", "colab", "ipython", "magic", "ruff", "isort", "linter"]
|
|
10
|
+
classifiers = [
|
|
11
|
+
"Programming Language :: Python :: 3",
|
|
12
|
+
"License :: OSI Approved :: MIT License",
|
|
13
|
+
"Operating System :: OS Independent",
|
|
14
|
+
"Framework :: IPython",
|
|
15
|
+
]
|
|
16
|
+
requires-python = ">=3.12"
|
|
17
|
+
dependencies = [
|
|
18
|
+
"ipython>=7.34.0",
|
|
19
|
+
"isort>=7.0.0",
|
|
20
|
+
"ruff>=0.14.8",
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
[project.urls]
|
|
24
|
+
repository = "https://github.com/RektPunk/colablinter"
|
|
25
|
+
|
|
26
|
+
[dependency-groups]
|
|
27
|
+
dev = [
|
|
28
|
+
"pre-commit>=4.5.0",
|
|
29
|
+
]
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
try:
|
|
2
|
+
from .magics import LintMagics
|
|
3
|
+
|
|
4
|
+
def load_ipython_extension(ipython):
|
|
5
|
+
ipython.register_magics(LintMagics)
|
|
6
|
+
print("[ColabLinter:INFO] %%format, %%check commands registered.")
|
|
7
|
+
|
|
8
|
+
except Exception as e:
|
|
9
|
+
print(f"[ColabLinter:ERROR] Initialization failed: {e}")
|
|
10
|
+
pass
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import subprocess
|
|
2
|
+
import sys
|
|
3
|
+
|
|
4
|
+
from IPython.core.magic import Magics, line_cell_magic, magics_class
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def _execute_command(command: str, input_data: str) -> str | None:
|
|
8
|
+
try:
|
|
9
|
+
result = subprocess.run(
|
|
10
|
+
command,
|
|
11
|
+
input=input_data,
|
|
12
|
+
shell=True,
|
|
13
|
+
capture_output=True,
|
|
14
|
+
text=True,
|
|
15
|
+
encoding="utf-8",
|
|
16
|
+
check=False,
|
|
17
|
+
)
|
|
18
|
+
if result.stderr:
|
|
19
|
+
print(
|
|
20
|
+
f"[ColabLinter: Subprocess Warning/Error]: {result.stderr.strip()}",
|
|
21
|
+
file=sys.stderr,
|
|
22
|
+
)
|
|
23
|
+
return result.stdout.strip()
|
|
24
|
+
except Exception as e:
|
|
25
|
+
print(f"[ColabLinter:ERROR] Error running command: {e}")
|
|
26
|
+
return
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@magics_class
|
|
30
|
+
class LintMagics(Magics):
|
|
31
|
+
_FILE_NAME = "notebook_cell.py"
|
|
32
|
+
|
|
33
|
+
@line_cell_magic
|
|
34
|
+
def check(self, line: str, cell: str | None = None) -> str | None:
|
|
35
|
+
if not cell or not cell.strip():
|
|
36
|
+
return
|
|
37
|
+
self.__check(cell)
|
|
38
|
+
self.__execute(cell)
|
|
39
|
+
|
|
40
|
+
@line_cell_magic
|
|
41
|
+
def format(self, line: str, cell: str | None = None) -> str | None:
|
|
42
|
+
if not cell or not cell.strip():
|
|
43
|
+
return
|
|
44
|
+
self.__format(cell)
|
|
45
|
+
self.__execute(cell)
|
|
46
|
+
|
|
47
|
+
def __check(self, cell: str) -> None:
|
|
48
|
+
print("---- Code Quality & Style Check Report ----")
|
|
49
|
+
if report := _execute_command(
|
|
50
|
+
f"ruff check --stdin-filename={self._FILE_NAME}", input_data=cell
|
|
51
|
+
):
|
|
52
|
+
print(report)
|
|
53
|
+
else:
|
|
54
|
+
print("[ColabLinter:INFO] No issues found. Code is clean.")
|
|
55
|
+
print("-------------------------------------------")
|
|
56
|
+
|
|
57
|
+
def __execute(self, cell: str) -> None:
|
|
58
|
+
try:
|
|
59
|
+
self.shell.run_cell(cell, silent=False, store_history=True)
|
|
60
|
+
except Exception as e:
|
|
61
|
+
print(f"[ColabLinter:ERROR] Code execution failed: {e}")
|
|
62
|
+
|
|
63
|
+
def __format(self, cell: str) -> None:
|
|
64
|
+
_formatted_code: str | None = _execute_command(
|
|
65
|
+
f"ruff format --stdin-filename={self._FILE_NAME}", input_data=cell
|
|
66
|
+
)
|
|
67
|
+
if _formatted_code is None:
|
|
68
|
+
print("[ColabLinter:ERROR] Formatting failed.")
|
|
69
|
+
return
|
|
70
|
+
|
|
71
|
+
formatted_code: str | None = _execute_command(
|
|
72
|
+
"isort --profile=black -", input_data=_formatted_code
|
|
73
|
+
)
|
|
74
|
+
code_to_print = (
|
|
75
|
+
formatted_code if formatted_code is not None else _formatted_code
|
|
76
|
+
)
|
|
77
|
+
if cell.strip() != code_to_print.strip():
|
|
78
|
+
print("# Formatted Code")
|
|
79
|
+
print(formatted_code.strip())
|
|
80
|
+
else:
|
|
81
|
+
print("[ColabLinter:INFO] Code already formatted. No changes needed.")
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: colablinter
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Linting and formatting Python code in Google Colab.
|
|
5
|
+
Author-email: RektPunk <rektpunk@gmail.com>
|
|
6
|
+
Project-URL: repository, https://github.com/RektPunk/colablinter
|
|
7
|
+
Keywords: jupyter,colab,ipython,magic,ruff,isort,linter
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Classifier: Framework :: IPython
|
|
12
|
+
Requires-Python: >=3.12
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Requires-Dist: ipython>=7.34.0
|
|
16
|
+
Requires-Dist: isort>=7.0.0
|
|
17
|
+
Requires-Dist: ruff>=0.14.8
|
|
18
|
+
Dynamic: license-file
|
|
19
|
+
|
|
20
|
+
# colablinter
|
|
21
|
+
|
|
22
|
+
[](https://pypi.org/project/colablinter/)
|
|
23
|
+
[](https://opensource.org/licenses/MIT)
|
|
24
|
+
|
|
25
|
+
## Overview
|
|
26
|
+
|
|
27
|
+
**`colablinter`** is an **IPython magic command extension** for Jupyter and Google Colab environments.
|
|
28
|
+
|
|
29
|
+
It integrates the high-speed linter **`ruff`** and import sorter **`isort`** to perform cell-by-cell code quality and formatting checks.
|
|
30
|
+
|
|
31
|
+
## Magic Commands
|
|
32
|
+
|
|
33
|
+
| Command | Role | Description |
|
|
34
|
+
| :--- | :--- | :--- |
|
|
35
|
+
| **`%%check`** | **Quality Check** | Displays a linting report. |
|
|
36
|
+
| **`%%format`** | **Format, Sort** | Displays a formatting preview (**for copy/paste**) |
|
|
37
|
+
|
|
38
|
+
After executing a magic command, the **original code** of the cell is executed (if applicable to the command).
|
|
39
|
+
|
|
40
|
+
## Installation
|
|
41
|
+
|
|
42
|
+
Requires Python 3.12 or newer.
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
pip install colablinter
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Usage
|
|
49
|
+
The extension must be explicitly loaded in the notebook session before use.
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
%load_ext colablinter
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
1. Check Code Quality
|
|
56
|
+
|
|
57
|
+
Use `%%check` to see linting reports.
|
|
58
|
+
```python
|
|
59
|
+
%%check
|
|
60
|
+
|
|
61
|
+
def invalid_code(x):
|
|
62
|
+
return x + y # 'y' is not defined
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Output examples:
|
|
66
|
+
```bash
|
|
67
|
+
--- Code Quality & Style Check Report ---
|
|
68
|
+
F821 Undefined name `y`
|
|
69
|
+
--> notebook_cell.py:4:16
|
|
70
|
+
|
|
|
71
|
+
2 | def invalid_code(x):
|
|
72
|
+
3 | return x + y # 'y' is not defined
|
|
73
|
+
| ^
|
|
74
|
+
|
|
|
75
|
+
|
|
76
|
+
Found 1 error.
|
|
77
|
+
-------------------------------------------
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
2. Format code preview
|
|
81
|
+
|
|
82
|
+
`%%format` will display the formatted code, but the cell executes the original code.
|
|
83
|
+
```python
|
|
84
|
+
%%format
|
|
85
|
+
import sys
|
|
86
|
+
import os
|
|
87
|
+
def calculate_long_sum(a,b,c,d,e,f):
|
|
88
|
+
return (a+b+c)*(d+e+f) # messy
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Output examples:
|
|
92
|
+
```python
|
|
93
|
+
# Formatted Code
|
|
94
|
+
import os
|
|
95
|
+
import sys
|
|
96
|
+
from datetime import datetime
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def calculate_long_sum(a, b, c, d, e, f):
|
|
100
|
+
return (a + b + c) * (d + e + f) # messy
|
|
101
|
+
```
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/colablinter/__init__.py
|
|
5
|
+
src/colablinter/magics.py
|
|
6
|
+
src/colablinter.egg-info/PKG-INFO
|
|
7
|
+
src/colablinter.egg-info/SOURCES.txt
|
|
8
|
+
src/colablinter.egg-info/dependency_links.txt
|
|
9
|
+
src/colablinter.egg-info/requires.txt
|
|
10
|
+
src/colablinter.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
colablinter
|