codehealthkit 0.1.0__py3-none-any.whl

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,16 @@
1
+ # CodeHealthKit - Main Package Init
2
+ # Import all functions so users can access them directly
3
+
4
+ from codehealthkit.analyzer import (
5
+ count_lines,
6
+ find_todos,
7
+ find_missing_docstrings,
8
+ find_duplicate_lines
9
+ )
10
+
11
+ from codehealthkit.formatter import (
12
+ snake_to_camel,
13
+ camel_to_snake,
14
+ remove_trailing_whitespace,
15
+ find_long_lines
16
+ )
@@ -0,0 +1,57 @@
1
+ # analyzer.py
2
+ # This module contains functions to analyze Python code files.
3
+
4
+ def count_lines(file_path):
5
+ """Count the total number of lines in a file."""
6
+ with open(file_path, "r") as f:
7
+ lines = f.readlines()
8
+ return len(lines)
9
+
10
+
11
+ def find_todos(file_path):
12
+ """Find all lines that contain TODO comments."""
13
+ todos = []
14
+ with open(file_path, "r") as f:
15
+ for line_number, line in enumerate(f, start=1):
16
+ if "TODO" in line:
17
+ todos.append((line_number, line.strip()))
18
+ return todos
19
+
20
+
21
+ def find_missing_docstrings(file_path):
22
+ """Find functions that do not have a docstring."""
23
+ missing = []
24
+ with open(file_path, "r") as f:
25
+ lines = f.readlines()
26
+
27
+ for i, line in enumerate(lines):
28
+ # Check if line defines a function
29
+ if line.strip().startswith("def "):
30
+ func_name = line.strip()
31
+ # Check the next line for a docstring
32
+ next_line_index = i + 1
33
+ if next_line_index < len(lines):
34
+ next_line = lines[next_line_index].strip()
35
+ if not next_line.startswith('"""') and not next_line.startswith("'''"):
36
+ missing.append((i + 1, func_name))
37
+
38
+ return missing
39
+
40
+
41
+ def find_duplicate_lines(file_path):
42
+ """Find lines that appear more than once in a file."""
43
+ seen = {}
44
+ duplicates = []
45
+
46
+ with open(file_path, "r") as f:
47
+ for line_number, line in enumerate(f, start=1):
48
+ stripped = line.strip()
49
+ # Skip empty lines
50
+ if stripped == "":
51
+ continue
52
+ if stripped in seen:
53
+ duplicates.append((line_number, stripped))
54
+ else:
55
+ seen[stripped] = line_number
56
+
57
+ return duplicates
@@ -0,0 +1,47 @@
1
+ # formatter.py
2
+ # This module contains functions to format Python code and text.
3
+
4
+ import re
5
+
6
+
7
+ def snake_to_camel(text):
8
+ """Convert snake_case text to camelCase."""
9
+ # Split by underscore
10
+ parts = text.split("_")
11
+ # First word stays lowercase, rest get capitalized
12
+ camel = parts[0] + "".join(word.capitalize() for word in parts[1:])
13
+ return camel
14
+
15
+
16
+ def camel_to_snake(text):
17
+ """Convert camelCase text to snake_case."""
18
+ # Add underscore before uppercase letters and lowercase everything
19
+ result = re.sub(r"([A-Z])", r"_\1", text).lower()
20
+ # Remove leading underscore if present
21
+ if result.startswith("_"):
22
+ result = result[1:]
23
+ return result
24
+
25
+
26
+ def remove_trailing_whitespace(file_path):
27
+ """Remove trailing whitespace from each line in a file."""
28
+ with open(file_path, "r") as f:
29
+ lines = f.readlines()
30
+
31
+ # Strip trailing spaces from each line
32
+ cleaned_lines = [line.rstrip() + "\n" for line in lines]
33
+
34
+ with open(file_path, "w") as f:
35
+ f.writelines(cleaned_lines)
36
+
37
+ print(f"Trailing whitespace removed from: {file_path}")
38
+
39
+
40
+ def find_long_lines(file_path, limit=79):
41
+ """Find lines that exceed the given character limit (default is 79)."""
42
+ long_lines = []
43
+ with open(file_path, "r") as f:
44
+ for line_number, line in enumerate(f, start=1):
45
+ if len(line.rstrip()) > limit:
46
+ long_lines.append((line_number, len(line.rstrip()), line.strip()))
47
+ return long_lines
@@ -0,0 +1,76 @@
1
+ Metadata-Version: 2.4
2
+ Name: codehealthkit
3
+ Version: 0.1.0
4
+ Summary: Simple Python code analysis and formatting library.
5
+ Author-email: Student Developer <student@example.com>
6
+ License: MIT License
7
+
8
+ Copyright (c) 2024 Student Developer
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+ Requires-Python: >=3.10
28
+ Description-Content-Type: text/markdown
29
+ License-File: LICENSE
30
+ Provides-Extra: dev
31
+ Requires-Dist: pytest; extra == "dev"
32
+ Dynamic: license-file
33
+
34
+ # CodeHealthKit
35
+
36
+ A simple Python library for analyzing and formatting Python code.
37
+
38
+ ## Installation
39
+
40
+ ```bash
41
+ pip install codehealthkit
42
+ ```
43
+
44
+ ## Usage
45
+
46
+ ### Analyzer
47
+
48
+ ```python
49
+ from codehealthkit.analyzer import count_lines
50
+ print(count_lines("sample.py"))
51
+ ```
52
+
53
+ ### Formatter
54
+
55
+ ```python
56
+ from codehealthkit.formatter import snake_to_camel
57
+ print(snake_to_camel("student_name"))
58
+ ```
59
+
60
+ ## Functions
61
+
62
+ ### analyzer.py
63
+ - `count_lines(file_path)` - Count total lines in a file
64
+ - `find_todos(file_path)` - Find TODO comments
65
+ - `find_missing_docstrings(file_path)` - Detect functions without docstrings
66
+ - `find_duplicate_lines(file_path)` - Detect duplicate lines
67
+
68
+ ### formatter.py
69
+ - `snake_to_camel(text)` - Convert snake_case to camelCase
70
+ - `camel_to_snake(text)` - Convert camelCase to snake_case
71
+ - `remove_trailing_whitespace(file_path)` - Remove trailing spaces
72
+ - `find_long_lines(file_path, limit=79)` - Find lines over the limit
73
+
74
+ ## License
75
+
76
+ MIT
@@ -0,0 +1,8 @@
1
+ codehealthkit/__init__.py,sha256=-Ih9robhmdKF6cZI_Jyhyjy5iE-yIpRSElRSyMhNaSE,367
2
+ codehealthkit/analyzer.py,sha256=Dq2rEME3BaAM3JmX5i5atWzO52R_EXX_-3SNjESseDc,1818
3
+ codehealthkit/formatter.py,sha256=Pf4himXsVqTCkT8I-Keur0JAFt2cm3UhiRaZv5xol68,1524
4
+ codehealthkit-0.1.0.dist-info/licenses/LICENSE,sha256=Gi_4WJSwqAqTCmbjxi4c_QdDv2S_6IuXlk_ZoltEJLs,1093
5
+ codehealthkit-0.1.0.dist-info/METADATA,sha256=ttbux7yLvMZ2aLKwsClowesBpWbQc1xSPUxi89T5LmU,2596
6
+ codehealthkit-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
7
+ codehealthkit-0.1.0.dist-info/top_level.txt,sha256=TSxRY2iqxvrV4OE45rlMikpZFlT0xpC54Oz4NmKkzJg,14
8
+ codehealthkit-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Student Developer
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 @@
1
+ codehealthkit