pydefine 1.0.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.
- pydefine-1.0.0/LICENSE +21 -0
- pydefine-1.0.0/PKG-INFO +395 -0
- pydefine-1.0.0/README.md +354 -0
- pydefine-1.0.0/pydefine/__init__.py +84 -0
- pydefine-1.0.0/pydefine/cli.py +284 -0
- pydefine-1.0.0/pydefine/core.py +456 -0
- pydefine-1.0.0/pydefine/i18n.py +344 -0
- pydefine-1.0.0/pydefine/mapping.py +1037 -0
- pydefine-1.0.0/pydefine/utils.py +442 -0
- pydefine-1.0.0/pydefine/version.py +20 -0
- pydefine-1.0.0/pydefine.egg-info/PKG-INFO +395 -0
- pydefine-1.0.0/pydefine.egg-info/SOURCES.txt +18 -0
- pydefine-1.0.0/pydefine.egg-info/dependency_links.txt +1 -0
- pydefine-1.0.0/pydefine.egg-info/entry_points.txt +3 -0
- pydefine-1.0.0/pydefine.egg-info/requires.txt +8 -0
- pydefine-1.0.0/pydefine.egg-info/top_level.txt +1 -0
- pydefine-1.0.0/pyproject.toml +112 -0
- pydefine-1.0.0/setup.cfg +4 -0
- pydefine-1.0.0/tests/test_core.py +385 -0
- pydefine-1.0.0/tests/test_mapping.py +313 -0
pydefine-1.0.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Yahya
|
|
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.
|
pydefine-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pydefine
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Convert Python errors into beginner-friendly explanations
|
|
5
|
+
Author-email: Yahya <yahyabuilds@gmail.com>
|
|
6
|
+
Maintainer-email: Yahya <yahyabuilds@gmail.com>
|
|
7
|
+
License: MIT
|
|
8
|
+
Project-URL: Homepage, https://github.com/mdyahhya/pydefine
|
|
9
|
+
Project-URL: Documentation, https://github.com/mdyahhya/pydefine#readme
|
|
10
|
+
Project-URL: Repository, https://github.com/mdyahhya/pydefine.git
|
|
11
|
+
Project-URL: Issues, https://github.com/mdyahhya/pydefine/issues
|
|
12
|
+
Project-URL: Changelog, https://github.com/mdyahhya/pydefine/blob/main/CHANGELOG.md
|
|
13
|
+
Keywords: error,exception,traceback,beginner,education,debugging,learning
|
|
14
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Intended Audience :: Education
|
|
17
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
18
|
+
Classifier: Topic :: Software Development :: Debuggers
|
|
19
|
+
Classifier: Topic :: Education
|
|
20
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
21
|
+
Classifier: Programming Language :: Python :: 3
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
26
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
27
|
+
Classifier: Operating System :: OS Independent
|
|
28
|
+
Classifier: Natural Language :: English
|
|
29
|
+
Classifier: Typing :: Typed
|
|
30
|
+
Requires-Python: >=3.8
|
|
31
|
+
Description-Content-Type: text/markdown
|
|
32
|
+
License-File: LICENSE
|
|
33
|
+
Provides-Extra: dev
|
|
34
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
35
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
|
|
36
|
+
Requires-Dist: black>=23.0.0; extra == "dev"
|
|
37
|
+
Requires-Dist: flake8>=6.0.0; extra == "dev"
|
|
38
|
+
Requires-Dist: mypy>=1.0.0; extra == "dev"
|
|
39
|
+
Requires-Dist: ruff>=0.1.0; extra == "dev"
|
|
40
|
+
Dynamic: license-file
|
|
41
|
+
|
|
42
|
+
# pyDefine
|
|
43
|
+
|
|
44
|
+
**Convert Python errors into beginner-friendly explanations** โจ
|
|
45
|
+
|
|
46
|
+
[](https://pypi.org/project/pydefine/)
|
|
47
|
+
[](https://pypi.org/project/pydefine/)
|
|
48
|
+
[](https://opensource.org/licenses/MIT)
|
|
49
|
+
[](https://github.com/mdyahhya/pydefine/actions)
|
|
50
|
+
|
|
51
|
+
pyDefine is a pure-Python library that takes raw Python tracebacks and exceptions and converts them into **extremely simple, beginner-friendly explanations** with actionable fix suggestions. Perfect for students, educators, and anyone learning Python!
|
|
52
|
+
|
|
53
|
+
## ๐ Features
|
|
54
|
+
|
|
55
|
+
- **88+ Exception Types Covered** - Comprehensive support for all Python built-in exceptions
|
|
56
|
+
- **Beginner-Friendly Explanations** - No jargon, simple English with analogies and emojis
|
|
57
|
+
- **Actionable Fix Suggestions** - Every error comes with a clear solution
|
|
58
|
+
- **Multiple Interfaces** - Use as library, CLI tool, or interactive decoder
|
|
59
|
+
- **Pure Python** - Zero dependencies, works everywhere Python runs
|
|
60
|
+
- **Safe Code Execution** - Built-in `safe_run()` for testing code with automatic error decoding
|
|
61
|
+
- **i18n Support** - Hinglish (Hindi+English) translations included, extensible to more languages
|
|
62
|
+
- **Production Ready** - Fully tested, type-hinted, and documented
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## ๐ฆ Installation
|
|
67
|
+
|
|
68
|
+
### From PyPI (Recommended)
|
|
69
|
+
|
|
70
|
+
pip install pydefine
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
### From Source
|
|
74
|
+
|
|
75
|
+
git clone https://github.com/mdyahhya/pydefine.git
|
|
76
|
+
cd pydefine
|
|
77
|
+
pip install -e .
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
### For Development
|
|
81
|
+
|
|
82
|
+
pip install -e ".[dev]"
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## ๐ Quick Start
|
|
87
|
+
|
|
88
|
+
### Basic Usage
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
import pydefine
|
|
92
|
+
|
|
93
|
+
Decode a traceback string
|
|
94
|
+
traceback_text = """Traceback (most recent call last):
|
|
95
|
+
File "script.py", line 5, in <module>
|
|
96
|
+
print(x)
|
|
97
|
+
NameError: name 'x' is not defined"""
|
|
98
|
+
|
|
99
|
+
result = pydefine.decode_traceback(traceback_text)
|
|
100
|
+
print(result['simple_explanation'])
|
|
101
|
+
|
|
102
|
+
Output: You tried to use a variable or function name that doesn't exist yet...
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
### Decode Exception Objects
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
import pydefine
|
|
109
|
+
|
|
110
|
+
try:
|
|
111
|
+
result = 10 / 0
|
|
112
|
+
except Exception as e:
|
|
113
|
+
decoded = pydefine.decode_exception(e)
|
|
114
|
+
print(f"{decoded['emoji']} {decoded['simple_explanation']}")
|
|
115
|
+
print(f"๐ก Fix: {decoded['fix_suggestion']}")
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
### Safe Code Execution
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
import pydefine
|
|
122
|
+
|
|
123
|
+
code = """
|
|
124
|
+
x = 10
|
|
125
|
+
y = 0
|
|
126
|
+
result = x / y
|
|
127
|
+
"""
|
|
128
|
+
|
|
129
|
+
result = pydefine.safe_run(code)
|
|
130
|
+
if not result['success']:
|
|
131
|
+
print(result['formatted_output'])
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
### Command Line Interface
|
|
135
|
+
|
|
136
|
+
Run a Python file with error decoding
|
|
137
|
+
pydefine script.py
|
|
138
|
+
|
|
139
|
+
List all supported exceptions
|
|
140
|
+
pydefine --list
|
|
141
|
+
|
|
142
|
+
Decode a log file
|
|
143
|
+
pydefine --decode-log error.log
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
---
|
|
147
|
+
|
|
148
|
+
## ๐ API Reference
|
|
149
|
+
|
|
150
|
+
### `decode_traceback(traceback_text: str) -> Dict`
|
|
151
|
+
|
|
152
|
+
Decode a raw traceback string into beginner-friendly explanation.
|
|
153
|
+
|
|
154
|
+
**Returns:**
|
|
155
|
+
|
|
156
|
+
{
|
|
157
|
+
'error_type': 'ZeroDivisionError',
|
|
158
|
+
'original_message': 'division by zero',
|
|
159
|
+
'simple_explanation': 'You tried to divide a number by zero...',
|
|
160
|
+
'fix_suggestion': 'Check if the divisor is zero before dividing...',
|
|
161
|
+
'line_number': 5,
|
|
162
|
+
'file_name': 'script.py',
|
|
163
|
+
'tags': ['arithmetic', 'division', 'zero'],
|
|
164
|
+
'emoji': 'โ',
|
|
165
|
+
'success': False,
|
|
166
|
+
'formatted_output': '...',
|
|
167
|
+
'branding': 'Powered by pyDefine โ Created by Yahya'
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
### `decode_exception(e: Exception) -> Dict`
|
|
172
|
+
|
|
173
|
+
Decode an exception object directly.
|
|
174
|
+
|
|
175
|
+
**Example:**
|
|
176
|
+
|
|
177
|
+
try:
|
|
178
|
+
my_dict['missing_key']
|
|
179
|
+
except KeyError as e:
|
|
180
|
+
result = pydefine.decode_exception(e)
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
### `safe_run(code: str, filename: str = "<input>") -> Dict`
|
|
184
|
+
|
|
185
|
+
Execute Python code safely with automatic error decoding.
|
|
186
|
+
|
|
187
|
+
**Example:**
|
|
188
|
+
result = pydefine.safe_run("print(10 / 0)")
|
|
189
|
+
print(result['simple_explanation'])
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
### `explain(exception_or_traceback) -> str`
|
|
193
|
+
|
|
194
|
+
Quick one-liner to get explanation.
|
|
195
|
+
|
|
196
|
+
**Example:**
|
|
197
|
+
|
|
198
|
+
try:
|
|
199
|
+
xโ
|
|
200
|
+
except IndexError as e:
|
|
201
|
+
print(pydefine.explain(e))
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
---
|
|
205
|
+
|
|
206
|
+
## ๐ฏ Supported Exceptions
|
|
207
|
+
|
|
208
|
+
pyDefine supports **88+ Python built-in exceptions** including:
|
|
209
|
+
|
|
210
|
+
### Common Errors
|
|
211
|
+
- `SyntaxError`, `IndentationError`, `TabError`
|
|
212
|
+
- `NameError`, `UnboundLocalError`
|
|
213
|
+
- `TypeError`, `ValueError`, `AttributeError`
|
|
214
|
+
- `KeyError`, `IndexError`
|
|
215
|
+
- `ZeroDivisionError`, `OverflowError`
|
|
216
|
+
- `FileNotFoundError`, `PermissionError`, `IOError`
|
|
217
|
+
- `ImportError`, `ModuleNotFoundError`
|
|
218
|
+
|
|
219
|
+
### Advanced Errors
|
|
220
|
+
- `RecursionError`, `MemoryError`
|
|
221
|
+
- `ConnectionError`, `TimeoutError`
|
|
222
|
+
- `UnicodeDecodeError`, `UnicodeEncodeError`
|
|
223
|
+
- `RuntimeError`, `NotImplementedError`
|
|
224
|
+
- All warning types
|
|
225
|
+
- Exception groups (Python 3.11+)
|
|
226
|
+
|
|
227
|
+
View full list: `pydefine --list-all`
|
|
228
|
+
|
|
229
|
+
---
|
|
230
|
+
|
|
231
|
+
## ๐ก Example Output
|
|
232
|
+
|
|
233
|
+
**Before (Standard Python Error):**
|
|
234
|
+
Traceback (most recent call last):
|
|
235
|
+
File "script.py", line 5, in <module>
|
|
236
|
+
print(data['email'])
|
|
237
|
+
KeyError: 'email'
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
**After (pyDefine):**
|
|
241
|
+
|
|
242
|
+
======================================================================
|
|
243
|
+
๐ KeyError: 'email'
|
|
244
|
+
๐ What happened:
|
|
245
|
+
You tried to get a value from a dictionary using a key that doesn't
|
|
246
|
+
exist. It's like looking for a word in a dictionary that isn't there.
|
|
247
|
+
The key you asked for is missing ๐
|
|
248
|
+
|
|
249
|
+
๐ก How to fix:
|
|
250
|
+
Use dict.get(key, default) instead of dict[key], or check if the
|
|
251
|
+
key exists with 'key in dict' first
|
|
252
|
+
|
|
253
|
+
๐ Where:
|
|
254
|
+
File: script.py
|
|
255
|
+
Line: 5
|
|
256
|
+
๐ท๏ธ Tags: key, dictionary, lookup, missing
|
|
257
|
+
|
|
258
|
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
259
|
+
Powered by pyDefine โ Created by Yahya
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
---
|
|
264
|
+
|
|
265
|
+
## ๐ Internationalization (i18n)
|
|
266
|
+
|
|
267
|
+
pyDefine supports multiple languages for explanations:
|
|
268
|
+
|
|
269
|
+
import pydefine
|
|
270
|
+
from pydefine.i18n import set_language
|
|
271
|
+
|
|
272
|
+
Set language to Hinglish (Hindi + English)
|
|
273
|
+
set_language('hi')
|
|
274
|
+
|
|
275
|
+
try:
|
|
276
|
+
x = 10 / 0
|
|
277
|
+
except Exception as e:
|
|
278
|
+
result = pydefine.decode_exception(e)
|
|
279
|
+
print(result['translated_explanation'])
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
**Supported Languages:**
|
|
283
|
+
- English (`en`) - Default
|
|
284
|
+
- Hinglish (`hi`) - Hindi + English mix
|
|
285
|
+
|
|
286
|
+
More languages coming soon!
|
|
287
|
+
|
|
288
|
+
---
|
|
289
|
+
|
|
290
|
+
## ๐ ๏ธ CLI Usage
|
|
291
|
+
|
|
292
|
+
### Run Python Files
|
|
293
|
+
|
|
294
|
+
pydefine script.py
|
|
295
|
+
pydefine --verbose script.py
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
### List Exceptions
|
|
299
|
+
|
|
300
|
+
Common exceptions
|
|
301
|
+
pydefine --list
|
|
302
|
+
|
|
303
|
+
All exceptions with categories
|
|
304
|
+
pydefine --list-all
|
|
305
|
+
|
|
306
|
+
Filter by tag
|
|
307
|
+
pydefine --list --tag syntax
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
### Decode Log Files
|
|
311
|
+
|
|
312
|
+
pydefine --decode-log error.log
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
---
|
|
316
|
+
|
|
317
|
+
## ๐งช Testing
|
|
318
|
+
|
|
319
|
+
Run the test suite:
|
|
320
|
+
|
|
321
|
+
Install dev dependencies
|
|
322
|
+
pip install -e ".[dev]"
|
|
323
|
+
|
|
324
|
+
Run tests
|
|
325
|
+
pytest
|
|
326
|
+
|
|
327
|
+
Run with coverage
|
|
328
|
+
pytest --cov=pydefine --cov-report=html
|
|
329
|
+
|
|
330
|
+
Run specific test file
|
|
331
|
+
pytest tests/test_core.py -v
|
|
332
|
+
|
|
333
|
+
---
|
|
334
|
+
|
|
335
|
+
## ๐ Project Stats
|
|
336
|
+
|
|
337
|
+
- **88+ Exceptions** covered with full explanations
|
|
338
|
+
- **50+ Tags** for classification
|
|
339
|
+
- **100% Pure Python** - no dependencies
|
|
340
|
+
- **Python 3.8+** compatible
|
|
341
|
+
- **95%+ Test Coverage**
|
|
342
|
+
- **Type Hints** throughout
|
|
343
|
+
|
|
344
|
+
---
|
|
345
|
+
|
|
346
|
+
## ๐ค Contributing
|
|
347
|
+
|
|
348
|
+
Contributions are welcome! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
|
|
349
|
+
|
|
350
|
+
**Ways to contribute:**
|
|
351
|
+
- Add explanations for custom exceptions
|
|
352
|
+
- Improve existing explanations
|
|
353
|
+
- Add translations for new languages
|
|
354
|
+
- Fix bugs or add features
|
|
355
|
+
- Improve documentation
|
|
356
|
+
|
|
357
|
+
---
|
|
358
|
+
|
|
359
|
+
## ๐ License
|
|
360
|
+
|
|
361
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
362
|
+
|
|
363
|
+
---
|
|
364
|
+
|
|
365
|
+
## ๐ Acknowledgments
|
|
366
|
+
|
|
367
|
+
- Inspired by the need to make Python more accessible to beginners
|
|
368
|
+
- Built with โค๏ธ for the Python education community
|
|
369
|
+
- Special thanks to all contributors
|
|
370
|
+
|
|
371
|
+
---
|
|
372
|
+
|
|
373
|
+
## ๐ Contact
|
|
374
|
+
|
|
375
|
+
**Author:** Yahya
|
|
376
|
+
**Email:** yahyabuilds@gmail.com
|
|
377
|
+
**GitHub:** [@mdyahhya](https://github.com/mdyahhya)
|
|
378
|
+
|
|
379
|
+
---
|
|
380
|
+
|
|
381
|
+
## โญ Show Your Support
|
|
382
|
+
|
|
383
|
+
If pyDefine helped you, please:
|
|
384
|
+
- โญ Star this repository
|
|
385
|
+
- ๐ฆ Share on social media
|
|
386
|
+
- ๐ Write a blog post about it
|
|
387
|
+
- ๐ค Contribute to the project
|
|
388
|
+
|
|
389
|
+
---
|
|
390
|
+
|
|
391
|
+
** Powered by pyDefine โ Created by Yahya **
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+
|