codetree-cli 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,99 @@
1
+ Metadata-Version: 2.4
2
+ Name: codetree-cli
3
+ Version: 0.1.0
4
+ Summary: A tool for counting lines of code in a project.
5
+ Home-page: https://github.com/rezamardaniDev/codetree.git
6
+ Author: Reza Mardani
7
+ Author-email: mardanireza30@gmail.com
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.6
12
+ Description-Content-Type: text/markdown
13
+ Dynamic: author
14
+ Dynamic: author-email
15
+ Dynamic: classifier
16
+ Dynamic: description
17
+ Dynamic: description-content-type
18
+ Dynamic: home-page
19
+ Dynamic: requires-python
20
+ Dynamic: summary
21
+
22
+ # Codetree
23
+
24
+ Codetree is a Python tool that helps you count the lines of code in your project directory. It supports multiple programming languages and provides a detailed breakdown of the number of lines in your project files. Perfect for analyzing and tracking the size of your codebase in an easy-to-read format.
25
+
26
+ ## Features
27
+
28
+ - Counts lines of code for a wide variety of programming languages.
29
+ - Skips hidden files and directories (those starting with a \.dot).
30
+ - Provides a summary of total lines of code and file count.
31
+ - Supports command-line interface (CLI) for easy integration.
32
+
33
+ ## Installation
34
+
35
+ ### Using pip
36
+
37
+ Install Codetree directly from PyPI using pip:
38
+
39
+ ```bash
40
+ pip install codetree
41
+ ```
42
+
43
+ ### Manual Installation
44
+
45
+ To install Codetree manually, clone the repository and use pip:
46
+
47
+ ```bash
48
+ git clone https://github.com/rezamardaniDev/codetree.git
49
+ cd codetree
50
+ pip install .
51
+ ```
52
+
53
+ ## Usage
54
+
55
+ Use Codetree via the command-line interface (CLI). Run the following command in your terminal:
56
+
57
+ ```bash
58
+ codetree /path/to/your/project
59
+ ```
60
+
61
+ This scans the specified directory (or current directory by default) and outputs the number of lines of code in each file, plus a summary of total lines.
62
+
63
+ ### Example
64
+
65
+ ```bash
66
+ $ codetree .
67
+ Scanning directory: .
68
+ |-- src/
69
+ | └── main.py -> 150 lines of code
70
+ | └── utils.py -> 85 lines of code
71
+ |
72
+ |-- test/
73
+ | └── test_main.py -> 25 lines of code
74
+ |
75
+ Total files checked: 3
76
+ Total lines of code: 260
77
+ Total folders: 2
78
+ ```
79
+
80
+ ## Options
81
+
82
+ - **Path**: Specify the project directory as an argument. If no path is provided, the current directory (\.) is used by default.
83
+
84
+ ```bash
85
+ codetree /path/to/project
86
+ ```
87
+
88
+ ## Contributing
89
+
90
+ We welcome contributions to Codetree! To contribute:
91
+
92
+ 1. Fork the repository.
93
+ 2. Create a new branch (`git checkout -b feature-name`).
94
+ 3. Make your changes.
95
+ 4. Commit your changes (`git commit -m 'Add new feature'`).
96
+ 5. Push to the branch (`git push origin feature-name`).
97
+ 6. Create a new pull request.
98
+
99
+ If you find a bug or want to add a feature, feel free to open an issue or submit a pull request!
@@ -0,0 +1,78 @@
1
+ # Codetree
2
+
3
+ Codetree is a Python tool that helps you count the lines of code in your project directory. It supports multiple programming languages and provides a detailed breakdown of the number of lines in your project files. Perfect for analyzing and tracking the size of your codebase in an easy-to-read format.
4
+
5
+ ## Features
6
+
7
+ - Counts lines of code for a wide variety of programming languages.
8
+ - Skips hidden files and directories (those starting with a \.dot).
9
+ - Provides a summary of total lines of code and file count.
10
+ - Supports command-line interface (CLI) for easy integration.
11
+
12
+ ## Installation
13
+
14
+ ### Using pip
15
+
16
+ Install Codetree directly from PyPI using pip:
17
+
18
+ ```bash
19
+ pip install codetree
20
+ ```
21
+
22
+ ### Manual Installation
23
+
24
+ To install Codetree manually, clone the repository and use pip:
25
+
26
+ ```bash
27
+ git clone https://github.com/rezamardaniDev/codetree.git
28
+ cd codetree
29
+ pip install .
30
+ ```
31
+
32
+ ## Usage
33
+
34
+ Use Codetree via the command-line interface (CLI). Run the following command in your terminal:
35
+
36
+ ```bash
37
+ codetree /path/to/your/project
38
+ ```
39
+
40
+ This scans the specified directory (or current directory by default) and outputs the number of lines of code in each file, plus a summary of total lines.
41
+
42
+ ### Example
43
+
44
+ ```bash
45
+ $ codetree .
46
+ Scanning directory: .
47
+ |-- src/
48
+ | └── main.py -> 150 lines of code
49
+ | └── utils.py -> 85 lines of code
50
+ |
51
+ |-- test/
52
+ | └── test_main.py -> 25 lines of code
53
+ |
54
+ Total files checked: 3
55
+ Total lines of code: 260
56
+ Total folders: 2
57
+ ```
58
+
59
+ ## Options
60
+
61
+ - **Path**: Specify the project directory as an argument. If no path is provided, the current directory (\.) is used by default.
62
+
63
+ ```bash
64
+ codetree /path/to/project
65
+ ```
66
+
67
+ ## Contributing
68
+
69
+ We welcome contributions to Codetree! To contribute:
70
+
71
+ 1. Fork the repository.
72
+ 2. Create a new branch (`git checkout -b feature-name`).
73
+ 3. Make your changes.
74
+ 4. Commit your changes (`git commit -m 'Add new feature'`).
75
+ 5. Push to the branch (`git push origin feature-name`).
76
+ 6. Create a new pull request.
77
+
78
+ If you find a bug or want to add a feature, feel free to open an issue or submit a pull request!
File without changes
@@ -0,0 +1,123 @@
1
+ import os
2
+ import argparse
3
+ from collections import defaultdict
4
+
5
+ def is_text_file(file_path):
6
+ """Check if a file is a text file based on its content."""
7
+ try:
8
+ with open(file_path, 'r', encoding='utf-8') as file:
9
+ file.read()
10
+ return True
11
+ except (UnicodeDecodeError, IOError):
12
+ return False
13
+
14
+ def count_lines_of_code(file_path):
15
+ """Counts the number of lines in a file if it's a text file."""
16
+ if not is_text_file(file_path):
17
+ return 0 # Skip non-text files
18
+
19
+ try:
20
+ with open(file_path, 'r', encoding='utf-8') as file:
21
+ lines = file.readlines()
22
+ return len(lines)
23
+ except Exception as e:
24
+ # If there is an error reading the file, print the error and skip the file
25
+ print(f"Error reading {file_path}: {e}")
26
+ return 0
27
+
28
+ def print_directory_tree(path):
29
+ """Prints the directory structure with files and their line counts."""
30
+ folder_files = defaultdict(list)
31
+ folder_count = 0 # Initialize folder count
32
+ checked_files = 0 # Initialize checked files count
33
+
34
+ # Process the root directory separately to include files in the root
35
+ if not os.path.basename(path).startswith('.'): # Skip hidden files and folders
36
+ folder_name = os.path.basename(path)
37
+ folder_count += 1 # Increment folder count
38
+ for file in sorted(os.listdir(path)):
39
+ file_path = os.path.join(path, file)
40
+ if os.path.isfile(file_path) and not file.startswith('.'):
41
+ lines = count_lines_of_code(file_path)
42
+ if lines > 0:
43
+ folder_files[folder_name].append((file, lines))
44
+ checked_files += 1 # Increment checked files count
45
+
46
+ # Walk through the directory and get files with line counts
47
+ for root, dirs, files in os.walk(path):
48
+ # Skip any directories that start with a dot
49
+ dirs[:] = [d for d in dirs if not d.startswith('.')]
50
+
51
+ # Only process the current directory if it does not start with a dot
52
+ rel_root = os.path.relpath(root, path)
53
+ if rel_root.startswith('.'):
54
+ continue
55
+
56
+ folder_name = rel_root if rel_root != '.' else os.path.basename(path)
57
+ folder_count += 1 # Increment folder count
58
+
59
+ for file in sorted(files):
60
+ # Skip files that start with a dot
61
+ if file.startswith('.'):
62
+ continue
63
+
64
+ file_path = os.path.join(root, file)
65
+ lines = count_lines_of_code(file_path)
66
+ if lines > 0:
67
+ folder_files[folder_name].append((file, lines))
68
+ checked_files += 1 # Increment checked files count
69
+
70
+ # Print directory tree with line counts
71
+ for folder in sorted(folder_files.keys()):
72
+ print(f"|-- {folder}/")
73
+ for file, lines in folder_files[folder]:
74
+ print(f" └── {file} -> {lines} line")
75
+ print("")
76
+
77
+ return folder_count, checked_files
78
+
79
+ def scan_directory(path):
80
+ """Scan the directory and prints summary of files and line counts."""
81
+ print(f"\nScanning directory: {path}")
82
+ total_files = 0
83
+ total_lines = 0
84
+ folder_count = 0
85
+ checked_files = 0
86
+
87
+ folder_count, checked_files = print_directory_tree(path)
88
+
89
+ # Count total files and lines, including those outside folders
90
+ for root, dirs, files in os.walk(path):
91
+ # Skip any directories that start with a dot
92
+ dirs[:] = [d for d in dirs if not d.startswith('.')]
93
+
94
+ for file in files:
95
+ # Skip files that start with a dot
96
+ if file.startswith('.'):
97
+ continue
98
+
99
+ file_path = os.path.join(root, file)
100
+ lines = count_lines_of_code(file_path)
101
+ if lines > 0:
102
+ total_files += 1
103
+ total_lines += lines
104
+ checked_files += 1
105
+
106
+ print(f"\nTotal files checked: {checked_files}")
107
+ print(f"Total lines of code: {total_lines}")
108
+ print(f"Total folders: {folder_count}")
109
+
110
+ def main():
111
+ """Main function to handle argument parsing and execution."""
112
+ parser = argparse.ArgumentParser(description="Count lines of code in a project directory.")
113
+ parser.add_argument('path', nargs='?', default=".", help="Path to the project directory (default: current directory)")
114
+ args = parser.parse_args()
115
+
116
+ print(f"Checking path: {args.path}")
117
+ if os.path.exists(args.path):
118
+ scan_directory(args.path)
119
+ else:
120
+ print(f"Path '{args.path}' not found.")
121
+
122
+ if __name__ == "__main__":
123
+ main()
@@ -0,0 +1,99 @@
1
+ Metadata-Version: 2.4
2
+ Name: codetree-cli
3
+ Version: 0.1.0
4
+ Summary: A tool for counting lines of code in a project.
5
+ Home-page: https://github.com/rezamardaniDev/codetree.git
6
+ Author: Reza Mardani
7
+ Author-email: mardanireza30@gmail.com
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.6
12
+ Description-Content-Type: text/markdown
13
+ Dynamic: author
14
+ Dynamic: author-email
15
+ Dynamic: classifier
16
+ Dynamic: description
17
+ Dynamic: description-content-type
18
+ Dynamic: home-page
19
+ Dynamic: requires-python
20
+ Dynamic: summary
21
+
22
+ # Codetree
23
+
24
+ Codetree is a Python tool that helps you count the lines of code in your project directory. It supports multiple programming languages and provides a detailed breakdown of the number of lines in your project files. Perfect for analyzing and tracking the size of your codebase in an easy-to-read format.
25
+
26
+ ## Features
27
+
28
+ - Counts lines of code for a wide variety of programming languages.
29
+ - Skips hidden files and directories (those starting with a \.dot).
30
+ - Provides a summary of total lines of code and file count.
31
+ - Supports command-line interface (CLI) for easy integration.
32
+
33
+ ## Installation
34
+
35
+ ### Using pip
36
+
37
+ Install Codetree directly from PyPI using pip:
38
+
39
+ ```bash
40
+ pip install codetree
41
+ ```
42
+
43
+ ### Manual Installation
44
+
45
+ To install Codetree manually, clone the repository and use pip:
46
+
47
+ ```bash
48
+ git clone https://github.com/rezamardaniDev/codetree.git
49
+ cd codetree
50
+ pip install .
51
+ ```
52
+
53
+ ## Usage
54
+
55
+ Use Codetree via the command-line interface (CLI). Run the following command in your terminal:
56
+
57
+ ```bash
58
+ codetree /path/to/your/project
59
+ ```
60
+
61
+ This scans the specified directory (or current directory by default) and outputs the number of lines of code in each file, plus a summary of total lines.
62
+
63
+ ### Example
64
+
65
+ ```bash
66
+ $ codetree .
67
+ Scanning directory: .
68
+ |-- src/
69
+ | └── main.py -> 150 lines of code
70
+ | └── utils.py -> 85 lines of code
71
+ |
72
+ |-- test/
73
+ | └── test_main.py -> 25 lines of code
74
+ |
75
+ Total files checked: 3
76
+ Total lines of code: 260
77
+ Total folders: 2
78
+ ```
79
+
80
+ ## Options
81
+
82
+ - **Path**: Specify the project directory as an argument. If no path is provided, the current directory (\.) is used by default.
83
+
84
+ ```bash
85
+ codetree /path/to/project
86
+ ```
87
+
88
+ ## Contributing
89
+
90
+ We welcome contributions to Codetree! To contribute:
91
+
92
+ 1. Fork the repository.
93
+ 2. Create a new branch (`git checkout -b feature-name`).
94
+ 3. Make your changes.
95
+ 4. Commit your changes (`git commit -m 'Add new feature'`).
96
+ 5. Push to the branch (`git push origin feature-name`).
97
+ 6. Create a new pull request.
98
+
99
+ If you find a bug or want to add a feature, feel free to open an issue or submit a pull request!
@@ -0,0 +1,10 @@
1
+ README.md
2
+ pyproject.toml
3
+ setup.py
4
+ codetree-cli/__init__.py
5
+ codetree-cli/cli.py
6
+ codetree_cli.egg-info/PKG-INFO
7
+ codetree_cli.egg-info/SOURCES.txt
8
+ codetree_cli.egg-info/dependency_links.txt
9
+ codetree_cli.egg-info/entry_points.txt
10
+ codetree_cli.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ codetree = codetree.cli:main
@@ -0,0 +1 @@
1
+ codetree-cli
@@ -0,0 +1,3 @@
1
+ [build-system]
2
+ requires = ["setuptools", "wheel"]
3
+ build-backend = "setuptools.build_meta"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,26 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ setup(
4
+ name="codetree-cli",
5
+ version="0.1.0",
6
+ author="Reza Mardani",
7
+ author_email="mardanireza30@gmail.com",
8
+ description="A tool for counting lines of code in a project.",
9
+ long_description=open("README.md").read(),
10
+ long_description_content_type="text/markdown",
11
+ url="https://github.com/rezamardaniDev/codetree.git",
12
+ packages=find_packages(),
13
+ classifiers=[
14
+ "Programming Language :: Python :: 3",
15
+ "License :: OSI Approved :: MIT License",
16
+ "Operating System :: OS Independent",
17
+ ],
18
+ python_requires='>=3.6',
19
+ install_requires=[
20
+ ],
21
+ entry_points={
22
+ 'console_scripts': [
23
+ 'codetree=codetree.cli:main',
24
+ ],
25
+ },
26
+ )