codehealthkit 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,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,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,43 @@
1
+ # CodeHealthKit
2
+
3
+ A simple Python library for analyzing and formatting Python code.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pip install codehealthkit
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### Analyzer
14
+
15
+ ```python
16
+ from codehealthkit.analyzer import count_lines
17
+ print(count_lines("sample.py"))
18
+ ```
19
+
20
+ ### Formatter
21
+
22
+ ```python
23
+ from codehealthkit.formatter import snake_to_camel
24
+ print(snake_to_camel("student_name"))
25
+ ```
26
+
27
+ ## Functions
28
+
29
+ ### analyzer.py
30
+ - `count_lines(file_path)` - Count total lines in a file
31
+ - `find_todos(file_path)` - Find TODO comments
32
+ - `find_missing_docstrings(file_path)` - Detect functions without docstrings
33
+ - `find_duplicate_lines(file_path)` - Detect duplicate lines
34
+
35
+ ### formatter.py
36
+ - `snake_to_camel(text)` - Convert snake_case to camelCase
37
+ - `camel_to_snake(text)` - Convert camelCase to snake_case
38
+ - `remove_trailing_whitespace(file_path)` - Remove trailing spaces
39
+ - `find_long_lines(file_path, limit=79)` - Find lines over the limit
40
+
41
+ ## License
42
+
43
+ MIT
@@ -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,13 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ codehealthkit/__init__.py
5
+ codehealthkit/analyzer.py
6
+ codehealthkit/formatter.py
7
+ codehealthkit.egg-info/PKG-INFO
8
+ codehealthkit.egg-info/SOURCES.txt
9
+ codehealthkit.egg-info/dependency_links.txt
10
+ codehealthkit.egg-info/requires.txt
11
+ codehealthkit.egg-info/top_level.txt
12
+ tests/test_analyzer.py
13
+ tests/test_formatter.py
@@ -0,0 +1,3 @@
1
+
2
+ [dev]
3
+ pytest
@@ -0,0 +1 @@
1
+ codehealthkit
@@ -0,0 +1,21 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "codehealthkit"
7
+ version = "0.1.0"
8
+ description = "Simple Python code analysis and formatting library."
9
+ readme = "README.md"
10
+ license = { file = "LICENSE" }
11
+ authors = [
12
+ { name = "Student Developer", email = "student@example.com" }
13
+ ]
14
+ requires-python = ">=3.10"
15
+
16
+ [tool.setuptools.packages.find]
17
+ where = ["."]
18
+ include = ["codehealthkit*"]
19
+
20
+ [project.optional-dependencies]
21
+ dev = ["pytest"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,59 @@
1
+ # test_analyzer.py
2
+ # Basic tests for analyzer.py functions
3
+
4
+ import os
5
+ import pytest
6
+ from codehealthkit.analyzer import (
7
+ count_lines,
8
+ find_todos,
9
+ find_missing_docstrings,
10
+ find_duplicate_lines
11
+ )
12
+
13
+ # Create a temporary test file
14
+ TEST_FILE = "test_sample.py"
15
+
16
+ def setup_module():
17
+ """Create a sample file before tests run."""
18
+ content = """def hello():
19
+ print("hello")
20
+
21
+ def greet():
22
+ \"\"\"This has a docstring.\"\"\"
23
+ pass
24
+
25
+ # TODO: fix this later
26
+ x = 1
27
+ x = 1
28
+ """
29
+ with open(TEST_FILE, "w") as f:
30
+ f.write(content)
31
+
32
+
33
+ def teardown_module():
34
+ """Delete the sample file after tests finish."""
35
+ if os.path.exists(TEST_FILE):
36
+ os.remove(TEST_FILE)
37
+
38
+
39
+ def test_count_lines():
40
+ result = count_lines(TEST_FILE)
41
+ assert result > 0
42
+
43
+
44
+ def test_find_todos():
45
+ result = find_todos(TEST_FILE)
46
+ assert len(result) >= 1
47
+ assert any("TODO" in line for _, line in result)
48
+
49
+
50
+ def test_find_missing_docstrings():
51
+ result = find_missing_docstrings(TEST_FILE)
52
+ # hello() has no docstring
53
+ assert len(result) >= 1
54
+
55
+
56
+ def test_find_duplicate_lines():
57
+ result = find_duplicate_lines(TEST_FILE)
58
+ # x = 1 appears twice
59
+ assert len(result) >= 1
@@ -0,0 +1,48 @@
1
+ # test_formatter.py
2
+ # Basic tests for formatter.py functions
3
+
4
+ import os
5
+ import pytest
6
+ from codehealthkit.formatter import (
7
+ snake_to_camel,
8
+ camel_to_snake,
9
+ remove_trailing_whitespace,
10
+ find_long_lines
11
+ )
12
+
13
+ TEST_FILE = "test_format_sample.py"
14
+
15
+
16
+ def setup_module():
17
+ """Create a sample file before tests run."""
18
+ content = "x = 1 \nthis_is_a_very_long_line_that_exceeds_the_limit_of_seventy_nine_characters_in_total = True\nclean line\n"
19
+ with open(TEST_FILE, "w") as f:
20
+ f.write(content)
21
+
22
+
23
+ def teardown_module():
24
+ """Delete the sample file after tests finish."""
25
+ if os.path.exists(TEST_FILE):
26
+ os.remove(TEST_FILE)
27
+
28
+
29
+ def test_snake_to_camel():
30
+ assert snake_to_camel("student_name") == "studentName"
31
+ assert snake_to_camel("hello_world") == "helloWorld"
32
+
33
+
34
+ def test_camel_to_snake():
35
+ assert camel_to_snake("studentName") == "student_name"
36
+ assert camel_to_snake("helloWorld") == "hello_world"
37
+
38
+
39
+ def test_remove_trailing_whitespace():
40
+ remove_trailing_whitespace(TEST_FILE)
41
+ with open(TEST_FILE, "r") as f:
42
+ for line in f:
43
+ assert not line.rstrip("\n").endswith(" ")
44
+
45
+
46
+ def test_find_long_lines():
47
+ result = find_long_lines(TEST_FILE, limit=79)
48
+ assert len(result) >= 1