inspectlab 0.1.0__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.
@@ -0,0 +1,287 @@
1
+ Metadata-Version: 2.4
2
+ Name: inspectlab
3
+ Version: 0.1.0
4
+ Summary: A CLI tool for inspecting Python source code using AST
5
+ Requires-Python: >=3.10
6
+ Description-Content-Type: text/markdown
7
+ Requires-Dist: typer
8
+
9
+ <p align="center">
10
+ <img src="logo.png" alt="InspectLab Logo" width="220">
11
+ </p>
12
+
13
+ # InspectLab
14
+
15
+ InspectLab is a lightweight Python CLI for inspecting Python source code directly from the terminal.
16
+
17
+ It uses Python's built-in `ast` module to analyze source files without executing them. InspectLab can quickly show functions, classes, imports, and the full AST structure of a file.
18
+
19
+ ## Features
20
+
21
+ * Inspect functions and async functions
22
+ * Detect generators and return/yield expressions
23
+ * Inspect classes, inheritance, metaclasses, and methods
24
+ * Show imports and aliases
25
+ * Show arguments and type annotations
26
+ * Show decorators and docstrings
27
+ * Show source line ranges
28
+ * Print the complete Python AST
29
+
30
+ ## Why InspectLab?
31
+
32
+ InspectLab is useful when you want a fast structural overview of a Python file without opening it manually or running its code.
33
+
34
+ ### Advantages
35
+
36
+ * **Safe static inspection** — analyzes source code without executing the target file.
37
+ * **Fast CLI workflow** — inspect a file with one command.
38
+ * **No parser setup** — built on Python's standard `ast` module.
39
+ * **Useful for debugging and review** — quickly understand unfamiliar Python code.
40
+ * **Detailed output** — includes annotations, decorators, docstrings, return values, line numbers, and more.
41
+
42
+ ## Installation
43
+
44
+ Install InspectLab from PyPI:
45
+
46
+ ```bash
47
+ pip install inspectlab
48
+ ```
49
+
50
+ Then verify that the CLI is available:
51
+
52
+ ```bash
53
+ inspectlab --help
54
+ ```
55
+
56
+ > InspectLab relies on modern Python AST features such as `ast.unparse`, so Python 3.9 or newer is recommended.
57
+
58
+ ## Basic Usage
59
+
60
+ InspectLab provides four commands:
61
+
62
+ ```bash
63
+ inspectlab functions FILE
64
+ inspectlab classes FILE
65
+ inspectlab imports FILE
66
+ inspectlab tree FILE
67
+ ```
68
+
69
+ `FILE` is the Python filename you want to inspect.
70
+
71
+ InspectLab searches for that filename recursively from your current working directory.
72
+
73
+ Example:
74
+
75
+ ```bash
76
+ inspectlab functions app.py
77
+ ```
78
+
79
+ ---
80
+
81
+ ## 1. `functions`
82
+
83
+ Inspect all functions found in a Python file.
84
+
85
+ ### Usage
86
+
87
+ ```bash
88
+ inspectlab functions FILE
89
+ ```
90
+
91
+ Example:
92
+
93
+ ```bash
94
+ inspectlab functions app.py
95
+ ```
96
+
97
+ ### What it outputs
98
+
99
+ For each function, InspectLab shows:
100
+
101
+ * Function name
102
+ * Function type
103
+ * Arguments and argument kinds
104
+ * Argument type annotations
105
+ * Return and yield expressions
106
+ * Return type annotation
107
+ * Decorators
108
+ * Docstring
109
+ * Start and end line numbers
110
+
111
+ It recognizes normal functions, async functions, generators, and async generators.
112
+
113
+ Example output:
114
+
115
+ ```text
116
+ Name: add
117
+ Type: Function with Return
118
+ Arguments:
119
+ - a: int [Normal]
120
+ - b: int [Normal]
121
+ Returns: [{'Return': 'a + b'}]
122
+ Return Data Type: int
123
+ Decorators: []
124
+ Docstring: Add two integers.
125
+ Lines: {'Start': 9, 'End': 11}
126
+ ```
127
+
128
+ ---
129
+
130
+ ## 2. `classes`
131
+
132
+ Inspect classes and their methods.
133
+
134
+ ### Usage
135
+
136
+ ```bash
137
+ inspectlab classes FILE
138
+ ```
139
+
140
+ Example:
141
+
142
+ ```bash
143
+ inspectlab classes models.py
144
+ ```
145
+
146
+ ### What it outputs
147
+
148
+ For each class, InspectLab shows:
149
+
150
+ * Class name
151
+ * Inherited classes
152
+ * Metaclass
153
+ * Class decorators
154
+ * Docstring
155
+ * Start and end line numbers
156
+ * Methods defined directly inside the class
157
+ * Detailed function information for each method
158
+
159
+ Example output:
160
+
161
+ ```text
162
+ Class: Admin
163
+ Inherits: User
164
+ Metaclass: None
165
+ Decorators: None
166
+ Docstring: Represents an administrator.
167
+ Lines: 54 - 65
168
+ Methods:
169
+ Name: validate
170
+ Type: Function with Return
171
+ Arguments:
172
+ - value: int [Normal]
173
+ Returns: [{'Return': 'value > 0'}]
174
+ Return Data Type: bool
175
+ Decorators: ['staticmethod']
176
+ Docstring: None
177
+ Lines: {'Start': 64, 'End': 65}
178
+ ```
179
+
180
+ ---
181
+
182
+ ## 3. `imports`
183
+
184
+ List imports used by a Python file.
185
+
186
+ ### Usage
187
+
188
+ ```bash
189
+ inspectlab imports FILE
190
+ ```
191
+
192
+ Example:
193
+
194
+ ```bash
195
+ inspectlab imports app.py
196
+ ```
197
+
198
+ ### What it outputs
199
+
200
+ The command shows:
201
+
202
+ * Import type: `import` or `from ... import ...`
203
+ * Imported module or name
204
+ * Import aliases
205
+ * Source line number
206
+
207
+ Example output:
208
+
209
+ ```text
210
+ Type: Import
211
+ Line: 2
212
+ Imports:
213
+ - sys as system
214
+
215
+ Type: ImportFrom
216
+ Line: 6
217
+ Module: collections
218
+ Imports:
219
+ - defaultdict as dd
220
+ ```
221
+
222
+ ---
223
+
224
+ ## 4. `tree`
225
+
226
+ Print the complete Abstract Syntax Tree of a Python file.
227
+
228
+ ### Usage
229
+
230
+ ```bash
231
+ inspectlab tree FILE
232
+ ```
233
+
234
+ Example:
235
+
236
+ ```bash
237
+ inspectlab tree app.py
238
+ ```
239
+
240
+ ### What it outputs
241
+
242
+ This command prints Python's AST representation using an indented tree. It is useful when you need to see the exact syntax nodes generated from the source code.
243
+
244
+ Example output:
245
+
246
+ ```text
247
+ Module(
248
+ body=[
249
+ Import(
250
+ names=[
251
+ alias(name='os')]),
252
+ FunctionDef(
253
+ name='add',
254
+ args=arguments(...),
255
+ body=[...])
256
+ ])
257
+ ```
258
+
259
+ ## Example Workflow
260
+
261
+ ```bash
262
+ # See the functions in a file
263
+ inspectlab functions main.py
264
+
265
+ # Inspect its classes
266
+ inspectlab classes main.py
267
+
268
+ # Check its dependencies/imports
269
+ inspectlab imports main.py
270
+
271
+ # View the raw AST
272
+ inspectlab tree main.py
273
+ ```
274
+
275
+ ## Error Handling
276
+
277
+ If InspectLab cannot find or parse the requested file, the CLI currently prints:
278
+
279
+ ```text
280
+ Wrong file name or typed out command
281
+ ```
282
+
283
+ Make sure you run the command from a directory where InspectLab can find the requested filename.
284
+
285
+ ## License
286
+
287
+ Add your project license here.
@@ -0,0 +1,279 @@
1
+ <p align="center">
2
+ <img src="logo.png" alt="InspectLab Logo" width="220">
3
+ </p>
4
+
5
+ # InspectLab
6
+
7
+ InspectLab is a lightweight Python CLI for inspecting Python source code directly from the terminal.
8
+
9
+ It uses Python's built-in `ast` module to analyze source files without executing them. InspectLab can quickly show functions, classes, imports, and the full AST structure of a file.
10
+
11
+ ## Features
12
+
13
+ * Inspect functions and async functions
14
+ * Detect generators and return/yield expressions
15
+ * Inspect classes, inheritance, metaclasses, and methods
16
+ * Show imports and aliases
17
+ * Show arguments and type annotations
18
+ * Show decorators and docstrings
19
+ * Show source line ranges
20
+ * Print the complete Python AST
21
+
22
+ ## Why InspectLab?
23
+
24
+ InspectLab is useful when you want a fast structural overview of a Python file without opening it manually or running its code.
25
+
26
+ ### Advantages
27
+
28
+ * **Safe static inspection** — analyzes source code without executing the target file.
29
+ * **Fast CLI workflow** — inspect a file with one command.
30
+ * **No parser setup** — built on Python's standard `ast` module.
31
+ * **Useful for debugging and review** — quickly understand unfamiliar Python code.
32
+ * **Detailed output** — includes annotations, decorators, docstrings, return values, line numbers, and more.
33
+
34
+ ## Installation
35
+
36
+ Install InspectLab from PyPI:
37
+
38
+ ```bash
39
+ pip install inspectlab
40
+ ```
41
+
42
+ Then verify that the CLI is available:
43
+
44
+ ```bash
45
+ inspectlab --help
46
+ ```
47
+
48
+ > InspectLab relies on modern Python AST features such as `ast.unparse`, so Python 3.9 or newer is recommended.
49
+
50
+ ## Basic Usage
51
+
52
+ InspectLab provides four commands:
53
+
54
+ ```bash
55
+ inspectlab functions FILE
56
+ inspectlab classes FILE
57
+ inspectlab imports FILE
58
+ inspectlab tree FILE
59
+ ```
60
+
61
+ `FILE` is the Python filename you want to inspect.
62
+
63
+ InspectLab searches for that filename recursively from your current working directory.
64
+
65
+ Example:
66
+
67
+ ```bash
68
+ inspectlab functions app.py
69
+ ```
70
+
71
+ ---
72
+
73
+ ## 1. `functions`
74
+
75
+ Inspect all functions found in a Python file.
76
+
77
+ ### Usage
78
+
79
+ ```bash
80
+ inspectlab functions FILE
81
+ ```
82
+
83
+ Example:
84
+
85
+ ```bash
86
+ inspectlab functions app.py
87
+ ```
88
+
89
+ ### What it outputs
90
+
91
+ For each function, InspectLab shows:
92
+
93
+ * Function name
94
+ * Function type
95
+ * Arguments and argument kinds
96
+ * Argument type annotations
97
+ * Return and yield expressions
98
+ * Return type annotation
99
+ * Decorators
100
+ * Docstring
101
+ * Start and end line numbers
102
+
103
+ It recognizes normal functions, async functions, generators, and async generators.
104
+
105
+ Example output:
106
+
107
+ ```text
108
+ Name: add
109
+ Type: Function with Return
110
+ Arguments:
111
+ - a: int [Normal]
112
+ - b: int [Normal]
113
+ Returns: [{'Return': 'a + b'}]
114
+ Return Data Type: int
115
+ Decorators: []
116
+ Docstring: Add two integers.
117
+ Lines: {'Start': 9, 'End': 11}
118
+ ```
119
+
120
+ ---
121
+
122
+ ## 2. `classes`
123
+
124
+ Inspect classes and their methods.
125
+
126
+ ### Usage
127
+
128
+ ```bash
129
+ inspectlab classes FILE
130
+ ```
131
+
132
+ Example:
133
+
134
+ ```bash
135
+ inspectlab classes models.py
136
+ ```
137
+
138
+ ### What it outputs
139
+
140
+ For each class, InspectLab shows:
141
+
142
+ * Class name
143
+ * Inherited classes
144
+ * Metaclass
145
+ * Class decorators
146
+ * Docstring
147
+ * Start and end line numbers
148
+ * Methods defined directly inside the class
149
+ * Detailed function information for each method
150
+
151
+ Example output:
152
+
153
+ ```text
154
+ Class: Admin
155
+ Inherits: User
156
+ Metaclass: None
157
+ Decorators: None
158
+ Docstring: Represents an administrator.
159
+ Lines: 54 - 65
160
+ Methods:
161
+ Name: validate
162
+ Type: Function with Return
163
+ Arguments:
164
+ - value: int [Normal]
165
+ Returns: [{'Return': 'value > 0'}]
166
+ Return Data Type: bool
167
+ Decorators: ['staticmethod']
168
+ Docstring: None
169
+ Lines: {'Start': 64, 'End': 65}
170
+ ```
171
+
172
+ ---
173
+
174
+ ## 3. `imports`
175
+
176
+ List imports used by a Python file.
177
+
178
+ ### Usage
179
+
180
+ ```bash
181
+ inspectlab imports FILE
182
+ ```
183
+
184
+ Example:
185
+
186
+ ```bash
187
+ inspectlab imports app.py
188
+ ```
189
+
190
+ ### What it outputs
191
+
192
+ The command shows:
193
+
194
+ * Import type: `import` or `from ... import ...`
195
+ * Imported module or name
196
+ * Import aliases
197
+ * Source line number
198
+
199
+ Example output:
200
+
201
+ ```text
202
+ Type: Import
203
+ Line: 2
204
+ Imports:
205
+ - sys as system
206
+
207
+ Type: ImportFrom
208
+ Line: 6
209
+ Module: collections
210
+ Imports:
211
+ - defaultdict as dd
212
+ ```
213
+
214
+ ---
215
+
216
+ ## 4. `tree`
217
+
218
+ Print the complete Abstract Syntax Tree of a Python file.
219
+
220
+ ### Usage
221
+
222
+ ```bash
223
+ inspectlab tree FILE
224
+ ```
225
+
226
+ Example:
227
+
228
+ ```bash
229
+ inspectlab tree app.py
230
+ ```
231
+
232
+ ### What it outputs
233
+
234
+ This command prints Python's AST representation using an indented tree. It is useful when you need to see the exact syntax nodes generated from the source code.
235
+
236
+ Example output:
237
+
238
+ ```text
239
+ Module(
240
+ body=[
241
+ Import(
242
+ names=[
243
+ alias(name='os')]),
244
+ FunctionDef(
245
+ name='add',
246
+ args=arguments(...),
247
+ body=[...])
248
+ ])
249
+ ```
250
+
251
+ ## Example Workflow
252
+
253
+ ```bash
254
+ # See the functions in a file
255
+ inspectlab functions main.py
256
+
257
+ # Inspect its classes
258
+ inspectlab classes main.py
259
+
260
+ # Check its dependencies/imports
261
+ inspectlab imports main.py
262
+
263
+ # View the raw AST
264
+ inspectlab tree main.py
265
+ ```
266
+
267
+ ## Error Handling
268
+
269
+ If InspectLab cannot find or parse the requested file, the CLI currently prints:
270
+
271
+ ```text
272
+ Wrong file name or typed out command
273
+ ```
274
+
275
+ Make sure you run the command from a directory where InspectLab can find the requested filename.
276
+
277
+ ## License
278
+
279
+ Add your project license here.
File without changes
@@ -0,0 +1,75 @@
1
+ import os
2
+ import sys as system
3
+ import json
4
+
5
+ from pathlib import Path
6
+ from collections import defaultdict as dd
7
+
8
+
9
+ def add(a: int, b: int) -> int:
10
+ """Add two integers."""
11
+ return a + b
12
+
13
+
14
+ def greet(name, /, greeting: str):
15
+ return f"{greeting}, {name}"
16
+
17
+
18
+ def generator(limit: int):
19
+ """Yield numbers up to limit."""
20
+ for number in range(limit):
21
+ if number == 5:
22
+ return
23
+
24
+ yield number
25
+
26
+
27
+ async def fetch_user(user_id: int) -> dict:
28
+ return {
29
+ "id": user_id,
30
+ "name": "Test User"
31
+ }
32
+
33
+
34
+ @staticmethod
35
+ def multiply(a: float, b: float) -> float:
36
+ return a * b
37
+
38
+
39
+ class User:
40
+ """Represents a normal user."""
41
+
42
+ role = "member"
43
+
44
+ def __init__(self, name: str):
45
+ self.name = name
46
+
47
+ def greet(self) -> str:
48
+ return f"Hello {self.name}"
49
+
50
+ async def save(self) -> None:
51
+ return None
52
+
53
+
54
+ class Admin(User):
55
+ """Represents an administrator."""
56
+
57
+ level = 10
58
+
59
+ @classmethod
60
+ def create(cls, name: str):
61
+ return cls(name)
62
+
63
+ @staticmethod
64
+ def validate(value: int) -> bool:
65
+ return value > 0
66
+
67
+
68
+ class Config(metaclass=type):
69
+ """Configuration class."""
70
+
71
+ enabled = True
72
+
73
+ @property
74
+ def status(self) -> str:
75
+ return "enabled"
@@ -0,0 +1,28 @@
1
+ from pathlib import Path
2
+ import ast
3
+
4
+ def find_file(file_name: str):
5
+ try:
6
+ path = Path.cwd()
7
+ file = next(path.rglob(file_name))
8
+ return file.read_text()
9
+ except StopIteration:
10
+ raise FileNotFoundError(f'File not found: {file_name}')
11
+
12
+
13
+ def create_ast(code: str):
14
+ code = ast.parse(code)
15
+ return code
16
+
17
+ def view_tree(file: str):
18
+ code = find_file(file)
19
+ tree = create_ast(code)
20
+ return ast.dump(tree, indent=4)
21
+
22
+ def create_main(file: str):
23
+ main = find_file(file)
24
+ tree = create_ast(main)
25
+ return tree
26
+
27
+
28
+