omdev 0.0.0.dev140__py3-none-any.whl → 0.0.0.dev141__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.
Potentially problematic release.
This version of omdev might be problematic. Click here for more details.
- omdev/.manifests.json +12 -0
- omdev/tools/cloc.py +149 -0
- {omdev-0.0.0.dev140.dist-info → omdev-0.0.0.dev141.dist-info}/METADATA +2 -2
- {omdev-0.0.0.dev140.dist-info → omdev-0.0.0.dev141.dist-info}/RECORD +8 -7
- {omdev-0.0.0.dev140.dist-info → omdev-0.0.0.dev141.dist-info}/LICENSE +0 -0
- {omdev-0.0.0.dev140.dist-info → omdev-0.0.0.dev141.dist-info}/WHEEL +0 -0
- {omdev-0.0.0.dev140.dist-info → omdev-0.0.0.dev141.dist-info}/entry_points.txt +0 -0
- {omdev-0.0.0.dev140.dist-info → omdev-0.0.0.dev141.dist-info}/top_level.txt +0 -0
omdev/.manifests.json
CHANGED
|
@@ -230,6 +230,18 @@
|
|
|
230
230
|
}
|
|
231
231
|
}
|
|
232
232
|
},
|
|
233
|
+
{
|
|
234
|
+
"module": ".tools.cloc",
|
|
235
|
+
"attr": "_CLI_MODULE",
|
|
236
|
+
"file": "omdev/tools/cloc.py",
|
|
237
|
+
"line": 144,
|
|
238
|
+
"value": {
|
|
239
|
+
"$.cli.types.CliModule": {
|
|
240
|
+
"cmd_name": "cloc",
|
|
241
|
+
"mod_name": "omdev.tools.cloc"
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
},
|
|
233
245
|
{
|
|
234
246
|
"module": ".tools.doc",
|
|
235
247
|
"attr": "_CLI_MODULE",
|
omdev/tools/cloc.py
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import dataclasses as dc
|
|
2
|
+
import os
|
|
3
|
+
import re
|
|
4
|
+
import typing as ta
|
|
5
|
+
|
|
6
|
+
from ..cli import CliModule
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
SUPPORTED_EXTENSIONS: ta.Mapping[str, str] = {
|
|
10
|
+
'.c': 'c',
|
|
11
|
+
'.cpp': 'c',
|
|
12
|
+
'.h': 'c',
|
|
13
|
+
'.hpp': 'c',
|
|
14
|
+
'.py': 'python',
|
|
15
|
+
'.js': 'javascript',
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
COMMENT_PATTERNS: ta.Mapping[str, tuple[str, str | None, str | None]] = {
|
|
20
|
+
'c': (r'//', r'/\*', r'\*/'),
|
|
21
|
+
'python': (r'#', None, None),
|
|
22
|
+
'javascript': (r'//', r'/\*', r'\*/'),
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@dc.dataclass(frozen=True)
|
|
27
|
+
class FileLineCount:
|
|
28
|
+
loc: int
|
|
29
|
+
blanks: int
|
|
30
|
+
comments: int
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def count_lines(file_path: str, language: str) -> FileLineCount:
|
|
34
|
+
single_line_comment, block_comment_start, block_comment_end = COMMENT_PATTERNS[language]
|
|
35
|
+
|
|
36
|
+
in_block_comment = False
|
|
37
|
+
|
|
38
|
+
loc = 0
|
|
39
|
+
blank_lines = 0
|
|
40
|
+
comment_lines = 0
|
|
41
|
+
|
|
42
|
+
with open(file_path, encoding='utf-8') as file:
|
|
43
|
+
for line in file:
|
|
44
|
+
stripped = line.strip()
|
|
45
|
+
if not stripped:
|
|
46
|
+
blank_lines += 1
|
|
47
|
+
continue
|
|
48
|
+
|
|
49
|
+
if in_block_comment:
|
|
50
|
+
comment_lines += 1
|
|
51
|
+
if block_comment_end and re.search(block_comment_end, stripped):
|
|
52
|
+
in_block_comment = False
|
|
53
|
+
continue
|
|
54
|
+
|
|
55
|
+
if block_comment_start and re.search(block_comment_start, stripped):
|
|
56
|
+
comment_lines += 1
|
|
57
|
+
if block_comment_end and not re.search(block_comment_end, stripped):
|
|
58
|
+
in_block_comment = True
|
|
59
|
+
continue
|
|
60
|
+
|
|
61
|
+
if single_line_comment and stripped.startswith(single_line_comment):
|
|
62
|
+
comment_lines += 1
|
|
63
|
+
continue
|
|
64
|
+
|
|
65
|
+
loc += 1
|
|
66
|
+
|
|
67
|
+
return FileLineCount(
|
|
68
|
+
loc=loc,
|
|
69
|
+
blanks=blank_lines,
|
|
70
|
+
comments=comment_lines,
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def count_lines_in_directory(directory: str) -> ta.Mapping[str, FileLineCount]:
|
|
75
|
+
results: dict[str, FileLineCount] = {}
|
|
76
|
+
for root, _, files in os.walk(directory):
|
|
77
|
+
for file in files:
|
|
78
|
+
ext = os.path.splitext(file)[1]
|
|
79
|
+
if ext in SUPPORTED_EXTENSIONS:
|
|
80
|
+
language = SUPPORTED_EXTENSIONS[ext]
|
|
81
|
+
file_path = os.path.join(root, file)
|
|
82
|
+
results[file_path] = count_lines(file_path, language)
|
|
83
|
+
return results
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def display_results(results: ta.Mapping[str, FileLineCount]) -> None:
|
|
87
|
+
total_loc = total_blanks = total_comments = 0
|
|
88
|
+
file_width = max(map(len, results))
|
|
89
|
+
dash_width = 41 + file_width
|
|
90
|
+
|
|
91
|
+
print(
|
|
92
|
+
f"{'File'.ljust(file_width)} "
|
|
93
|
+
f"{'LOC':<10} "
|
|
94
|
+
f"{'Blank Lines':<15} "
|
|
95
|
+
f"{'Comment Lines':<15}",
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
print('-' * dash_width)
|
|
99
|
+
|
|
100
|
+
for file, counts in sorted(results.items()):
|
|
101
|
+
loc, blanks, comments = counts.loc, counts.blanks, counts.comments
|
|
102
|
+
total_loc += loc
|
|
103
|
+
total_blanks += blanks
|
|
104
|
+
total_comments += comments
|
|
105
|
+
print(
|
|
106
|
+
f'{file.ljust(file_width)} '
|
|
107
|
+
f'{loc:<10} '
|
|
108
|
+
f'{blanks:<15} '
|
|
109
|
+
f'{comments:<15}',
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
print('-' * dash_width)
|
|
113
|
+
|
|
114
|
+
print(
|
|
115
|
+
f"{' ' * file_width} "
|
|
116
|
+
f"{'LOC':<10} "
|
|
117
|
+
f"{'Blank Lines':<15} "
|
|
118
|
+
f"{'Comment Lines':<15}",
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
print('-' * dash_width)
|
|
122
|
+
|
|
123
|
+
print(
|
|
124
|
+
f"{'Total'.ljust(file_width)} "
|
|
125
|
+
f"{total_loc:<10} "
|
|
126
|
+
f"{total_blanks:<15} "
|
|
127
|
+
f"{total_comments:<15}",
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def _main() -> None:
|
|
132
|
+
import argparse
|
|
133
|
+
|
|
134
|
+
parser = argparse.ArgumentParser(description='Count lines of code in source files.')
|
|
135
|
+
parser.add_argument('directory', help='The directory to analyze.', nargs='+')
|
|
136
|
+
args = parser.parse_args()
|
|
137
|
+
|
|
138
|
+
for directory in args.directory:
|
|
139
|
+
results = count_lines_in_directory(directory)
|
|
140
|
+
display_results(results)
|
|
141
|
+
print()
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
# @omlish-manifest
|
|
145
|
+
_CLI_MODULE = CliModule('cloc', __name__)
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
if __name__ == '__main__':
|
|
149
|
+
_main()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: omdev
|
|
3
|
-
Version: 0.0.0.
|
|
3
|
+
Version: 0.0.0.dev141
|
|
4
4
|
Summary: omdev
|
|
5
5
|
Author: wrmsr
|
|
6
6
|
License: BSD-3-Clause
|
|
@@ -12,7 +12,7 @@ Classifier: Operating System :: OS Independent
|
|
|
12
12
|
Classifier: Operating System :: POSIX
|
|
13
13
|
Requires-Python: >=3.12
|
|
14
14
|
License-File: LICENSE
|
|
15
|
-
Requires-Dist: omlish==0.0.0.
|
|
15
|
+
Requires-Dist: omlish==0.0.0.dev141
|
|
16
16
|
Provides-Extra: all
|
|
17
17
|
Requires-Dist: black~=24.10; extra == "all"
|
|
18
18
|
Requires-Dist: pycparser~=2.22; extra == "all"
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
omdev/.manifests.json,sha256=
|
|
1
|
+
omdev/.manifests.json,sha256=Km5mOi7_lFQef4qX5OZ5PkcJleIif_pmKZLnbCUQ7Yw,8015
|
|
2
2
|
omdev/__about__.py,sha256=n5x-SO70OgbDQFzQ1d7sZDVMsnkQc4PxQZPFaIQFa0E,1281
|
|
3
3
|
omdev/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
4
|
omdev/bracepy.py,sha256=I8EdqtDvxzAi3I8TuMEW-RBfwXfqKbwp06CfOdj3L1o,2743
|
|
@@ -138,6 +138,7 @@ omdev/toml/__init__.py,sha256=Y3l4WY4JRi2uLG6kgbGp93fuGfkxkKwZDvhsa0Rwgtk,15
|
|
|
138
138
|
omdev/toml/parser.py,sha256=ojhCYIk23ELRx2f9xUCwLTRq13UM6wrYGWoyxZBurlo,29327
|
|
139
139
|
omdev/toml/writer.py,sha256=lk3on3YXVbWuLJa-xsOzOhs1bBAT1vXqw4mBbluZl_w,3040
|
|
140
140
|
omdev/tools/__init__.py,sha256=iVJAOQ0viGTQOm0DLX4uZLro-9jOioYJGLg9s0kDx1A,78
|
|
141
|
+
omdev/tools/cloc.py,sha256=13lUsYLyn1LoelhsCeKrRkIwwPE0x54JmdhXJ_lvWh0,3811
|
|
141
142
|
omdev/tools/doc.py,sha256=mv9XfitzqXl3vFHSenv01xHCxWf8g03rUAb_sqoty98,2556
|
|
142
143
|
omdev/tools/docker.py,sha256=k2BrVvFYwyGov064CPHd_HWo9aqR1zHc2UeEsVwPth4,6827
|
|
143
144
|
omdev/tools/git.py,sha256=bfhYUFip7zVxtsyXk8yEFbK2y2zguhvgraLhXc7A53M,6899
|
|
@@ -151,9 +152,9 @@ omdev/tools/sqlrepl.py,sha256=tmFZh80-xsGM62dyQ7_UGLebChrj7IHbIPYBWDJMgVk,5741
|
|
|
151
152
|
omdev/tools/pawk/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
152
153
|
omdev/tools/pawk/__main__.py,sha256=VCqeRVnqT1RPEoIrqHFSu4PXVMg4YEgF4qCQm90-eRI,66
|
|
153
154
|
omdev/tools/pawk/pawk.py,sha256=Eckymn22GfychCQcQi96BFqRo_LmiJ-EPhC8TTUJdB4,11446
|
|
154
|
-
omdev-0.0.0.
|
|
155
|
-
omdev-0.0.0.
|
|
156
|
-
omdev-0.0.0.
|
|
157
|
-
omdev-0.0.0.
|
|
158
|
-
omdev-0.0.0.
|
|
159
|
-
omdev-0.0.0.
|
|
155
|
+
omdev-0.0.0.dev141.dist-info/LICENSE,sha256=B_hVtavaA8zCYDW99DYdcpDLKz1n3BBRjZrcbv8uG8c,1451
|
|
156
|
+
omdev-0.0.0.dev141.dist-info/METADATA,sha256=Pbq09pqhxLZmSxFaSMTI5fE031QMw-Xe-WMEMNwAmjY,1760
|
|
157
|
+
omdev-0.0.0.dev141.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
|
158
|
+
omdev-0.0.0.dev141.dist-info/entry_points.txt,sha256=dHLXFmq5D9B8qUyhRtFqTGWGxlbx3t5ejedjrnXNYLU,33
|
|
159
|
+
omdev-0.0.0.dev141.dist-info/top_level.txt,sha256=1nr7j30fEWgLYHW3lGR9pkdHkb7knv1U1ES1XRNVQ6k,6
|
|
160
|
+
omdev-0.0.0.dev141.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|