codetree-cli 0.2.1__tar.gz → 0.2.2__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: codetree-cli
3
- Version: 0.2.1
3
+ Version: 0.2.2
4
4
  Summary: A tool for counting lines of code in a project.
5
5
  Home-page: https://github.com/rezamardaniDev/codetree.git
6
6
  Author: Reza Mardani
@@ -21,43 +21,25 @@ def count_lines_of_code(file_path):
21
21
  lines = file.readlines()
22
22
  return len(lines)
23
23
  except Exception as e:
24
- # If there is an error reading the file, print the error and skip the file
25
24
  print(f"Error reading {file_path}: {e}")
26
25
  return 0
27
26
 
28
27
  def print_directory_tree(path):
29
28
  """Prints the directory structure with files and their line counts."""
30
29
  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
30
+ folder_count = 0
31
+ checked_files = 0
45
32
 
46
33
  # Walk through the directory and get files with line counts
47
34
  for root, dirs, files in os.walk(path):
48
- # Skip any directories that start with a dot
35
+ # Skip hidden directories
49
36
  dirs[:] = [d for d in dirs if not d.startswith('.')]
50
37
 
51
- # Only process the current directory if it does not start with a dot
52
38
  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
39
+ folder_name = rel_root if rel_root != '.' else 'root' # Show root separately
40
+ folder_count += 1
58
41
 
59
42
  for file in sorted(files):
60
- # Skip files that start with a dot
61
43
  if file.startswith('.'):
62
44
  continue
63
45
 
@@ -65,7 +47,7 @@ def print_directory_tree(path):
65
47
  lines = count_lines_of_code(file_path)
66
48
  if lines > 0:
67
49
  folder_files[folder_name].append((file, lines))
68
- checked_files += 1 # Increment checked files count
50
+ checked_files += 1
69
51
 
70
52
  # Print directory tree with line counts
71
53
  for folder in sorted(folder_files.keys()):
@@ -79,29 +61,21 @@ def print_directory_tree(path):
79
61
  def scan_directory(path):
80
62
  """Scan the directory and prints summary of files and line counts."""
81
63
  print(f"\nScanning directory: {path}")
82
- total_files = 0
83
64
  total_lines = 0
84
- folder_count = 0
85
- checked_files = 0
86
65
 
87
66
  folder_count, checked_files = print_directory_tree(path)
88
67
 
89
- # Count total files and lines, including those outside folders
68
+ # Count total lines
90
69
  for root, dirs, files in os.walk(path):
91
- # Skip any directories that start with a dot
92
70
  dirs[:] = [d for d in dirs if not d.startswith('.')]
93
71
 
94
72
  for file in files:
95
- # Skip files that start with a dot
96
73
  if file.startswith('.'):
97
74
  continue
98
75
 
99
76
  file_path = os.path.join(root, file)
100
77
  lines = count_lines_of_code(file_path)
101
- if lines > 0:
102
- total_files += 1
103
- total_lines += lines
104
- checked_files += 1
78
+ total_lines += lines
105
79
 
106
80
  print(f"\nTotal files checked: {checked_files}")
107
81
  print(f"Total lines of code: {total_lines}")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: codetree-cli
3
- Version: 0.2.1
3
+ Version: 0.2.2
4
4
  Summary: A tool for counting lines of code in a project.
5
5
  Home-page: https://github.com/rezamardaniDev/codetree.git
6
6
  Author: Reza Mardani
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name="codetree-cli",
5
- version="0.2.1",
5
+ version="0.2.2",
6
6
  author="Reza Mardani",
7
7
  author_email="mardanireza30@gmail.com",
8
8
  description="A tool for counting lines of code in a project.",
File without changes
File without changes