omdev 0.0.0.dev349__py3-none-any.whl → 0.0.0.dev350__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 CHANGED
@@ -306,7 +306,7 @@
306
306
  "module": ".tools.cloc",
307
307
  "attr": "_CLI_MODULE",
308
308
  "file": "omdev/tools/cloc.py",
309
- "line": 202,
309
+ "line": 248,
310
310
  "value": {
311
311
  "$.cli.types.CliModule": {
312
312
  "cmd_name": "cloc",
omdev/tools/cloc.py CHANGED
@@ -8,46 +8,83 @@ import os
8
8
  import re
9
9
  import typing as ta
10
10
 
11
+ from omlish import collections as col
12
+
11
13
  from ..cli import CliModule
12
14
 
13
15
 
14
16
  ##
15
17
 
16
18
 
17
- SUPPORTED_EXTENSIONS: ta.Mapping[str, str] = {
18
- '.c': 'c',
19
- '.cpp': 'c',
20
- '.h': 'c',
21
- '.hpp': 'c',
22
- '.py': 'python',
23
- '.js': 'javascript',
24
- }
19
+ @dc.dataclass(frozen=True)
20
+ class Lang:
21
+ name: str
22
+ extensions: ta.AbstractSet[str]
23
+
24
+ _: dc.KW_ONLY
25
+
26
+ comment_pats: tuple[str, str | None, str | None]
27
+ is_test_file_fn: ta.Callable[[str], bool] | None = None
28
+
29
+
30
+ _LANG = [
31
+ Lang(
32
+ 'python',
33
+ {'.py'},
34
+ comment_pats=(r'#', None, None),
35
+ is_test_file_fn=lambda fp: 'tests' in os.path.normpath(fp).split(os.sep),
36
+ ),
25
37
 
38
+ Lang(
39
+ 'c',
40
+ {'.c', '.cc', '.cpp', '.h', '.hh', '.hpp'},
41
+ comment_pats=(r'//', r'/\*', r'\*/'),
42
+ ),
26
43
 
27
- COMMENT_PATTERNS: ta.Mapping[str, tuple[str, str | None, str | None]] = {
28
- 'c': (r'//', r'/\*', r'\*/'),
29
- 'python': (r'#', None, None),
30
- 'javascript': (r'//', r'/\*', r'\*/'),
31
- }
44
+ Lang(
45
+ 'javascript',
46
+ {'.js'},
47
+ comment_pats=(r'//', r'/\*', r'\*/'),
48
+ ),
49
+ ]
50
+
51
+
52
+ LANGS = col.make_map_by(lambda l: l.name, _LANG, strict=True)
53
+ LANGS_BY_EXTENSION = col.make_map([(e, l) for l in _LANG for e in l.extensions], strict=True)
54
+
55
+
56
+ ##
32
57
 
33
58
 
34
59
  @dc.dataclass(frozen=True)
35
- class FileLineCount:
60
+ class FileStats:
36
61
  loc: int
37
62
  blanks: int
38
63
  comments: int
39
64
 
40
65
 
41
- def count_lines(file_path: str, language: str) -> FileLineCount:
42
- single_line_comment, block_comment_start, block_comment_end = COMMENT_PATTERNS[language]
66
+ @dc.dataclass(frozen=True)
67
+ class File:
68
+ path: str
69
+ lang: Lang
70
+ stats: FileStats
71
+ is_test: bool
72
+
73
+
74
+ def examine_file(path: str, lang: Lang | None = None) -> File | None:
75
+ if lang is None:
76
+ ext = os.path.splitext(os.path.basename(path))[1]
77
+ if (lang := LANGS_BY_EXTENSION.get(ext)) is None:
78
+ return None
43
79
 
80
+ single_line_comment, block_comment_start, block_comment_end = lang.comment_pats
44
81
  in_block_comment = False
45
82
 
46
83
  loc = 0
47
84
  blank_lines = 0
48
85
  comment_lines = 0
49
86
 
50
- with open(file_path, encoding='utf-8') as file:
87
+ with open(path, encoding='utf-8') as file:
51
88
  for line in file:
52
89
  stripped = line.strip()
53
90
  if not stripped:
@@ -72,26 +109,30 @@ def count_lines(file_path: str, language: str) -> FileLineCount:
72
109
 
73
110
  loc += 1
74
111
 
75
- return FileLineCount(
76
- loc=loc,
77
- blanks=blank_lines,
78
- comments=comment_lines,
112
+ return File(
113
+ path=path,
114
+ lang=lang,
115
+ stats=FileStats(
116
+ loc=loc,
117
+ blanks=blank_lines,
118
+ comments=comment_lines,
119
+ ),
120
+ is_test=lang.is_test_file_fn(path) if lang.is_test_file_fn is not None else False,
79
121
  )
80
122
 
81
123
 
124
+ ##
125
+
126
+
82
127
  def count_lines_in_directory(
83
128
  directory: str,
84
129
  *,
85
130
  include: list[re.Pattern[str]] | None = None,
86
131
  exclude: list[re.Pattern[str]] | None = None,
87
- ) -> ta.Mapping[str, FileLineCount]:
88
- results: dict[str, FileLineCount] = {}
132
+ ) -> ta.Mapping[str, FileStats]:
133
+ results: dict[str, FileStats] = {}
89
134
  for root, _, files in os.walk(directory):
90
135
  for file in files:
91
- ext = os.path.splitext(file)[1]
92
- if ext not in SUPPORTED_EXTENSIONS:
93
- continue
94
-
95
136
  file_path = os.path.join(root, file)
96
137
 
97
138
  if include and not any(p.fullmatch(file_path) for p in include):
@@ -99,13 +140,15 @@ def count_lines_in_directory(
99
140
  if exclude and any(p.fullmatch(file_path) for p in exclude):
100
141
  continue
101
142
 
102
- language = SUPPORTED_EXTENSIONS[ext]
103
- results[file_path] = count_lines(file_path, language)
143
+ if (ex := examine_file(file_path)) is None:
144
+ continue
145
+
146
+ results[file_path] = ex.stats
104
147
 
105
148
  return results
106
149
 
107
150
 
108
- def display_results(results: ta.Mapping[str, FileLineCount]) -> None:
151
+ def display_results(results: ta.Mapping[str, FileStats]) -> None:
109
152
  total_loc = total_blanks = total_comments = 0
110
153
  file_width = max(map(len, results))
111
154
  dash_width = 41 + file_width
@@ -150,6 +193,9 @@ def display_results(results: ta.Mapping[str, FileLineCount]) -> None:
150
193
  )
151
194
 
152
195
 
196
+ ##
197
+
198
+
153
199
  def _main() -> None:
154
200
  import argparse
155
201
 
@@ -174,7 +220,7 @@ def _main() -> None:
174
220
 
175
221
  #
176
222
 
177
- results_by_directory: dict[str, FileLineCount] = {}
223
+ results_by_directory: dict[str, FileStats] = {}
178
224
  for directory in args.directory:
179
225
  results = count_lines_in_directory(
180
226
  directory,
@@ -188,7 +234,7 @@ def _main() -> None:
188
234
  display_results(results)
189
235
  print()
190
236
 
191
- results_by_directory[directory] = FileLineCount(
237
+ results_by_directory[directory] = FileStats(
192
238
  loc=sum(flc.loc for flc in results.values()),
193
239
  blanks=sum(flc.blanks for flc in results.values()),
194
240
  comments=sum(flc.comments for flc in results.values()),
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: omdev
3
- Version: 0.0.0.dev349
3
+ Version: 0.0.0.dev350
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.dev349
15
+ Requires-Dist: omlish==0.0.0.dev350
16
16
  Provides-Extra: all
17
17
  Requires-Dist: black~=25.1; extra == "all"
18
18
  Requires-Dist: pycparser~=2.22; extra == "all"
@@ -1,4 +1,4 @@
1
- omdev/.manifests.json,sha256=L7A85Vj8U60KXQwEEr2wWeUSv2sXTgiTHE10hIp8Uxk,11870
1
+ omdev/.manifests.json,sha256=fHOFj2p3JY4pmLF7FYYFODTnwvjWjhO14QbAqpG6Tdg,11870
2
2
  omdev/__about__.py,sha256=2_6pQyjxqAspvwBSJUWQgdBBcGaDO3zX8yETLaspUQE,1202
3
3
  omdev/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
4
  omdev/cmake.py,sha256=9rfSvFHPmKDj9ngvfDB2vK8O-xO_ZwUm7hMKLWA-yOw,4578
@@ -262,7 +262,7 @@ omdev/tokens/all.py,sha256=a_fJ9vp9_Sky4OgtxQ6e6JXwvFSaY0XluVjKeBYCheU,770
262
262
  omdev/tokens/tokenizert.py,sha256=66tTP7J4vCYMgn-EKtfLBmc8SfycL1llvI4Q7LSxOk4,7890
263
263
  omdev/tokens/utils.py,sha256=vF2c8vHwe1zfSXNeU0q1CaA_66oZl0YdkqBKzNhFsAM,1758
264
264
  omdev/tools/__init__.py,sha256=iVJAOQ0viGTQOm0DLX4uZLro-9jOioYJGLg9s0kDx1A,78
265
- omdev/tools/cloc.py,sha256=99LHGT6p7c_afen8Js6Y_8g0CVwCXITtBQoR8-jtHEc,5210
265
+ omdev/tools/cloc.py,sha256=BiIf2PnnoRH6ByH4mnua69Vv-ZDPHsSAPUds7giRolI,6013
266
266
  omdev/tools/diff.py,sha256=_ThKWXFE-bG5SPDYNs8GqstEUPzL_PTWb03nJN0laLg,515
267
267
  omdev/tools/doc.py,sha256=PCtqDjFA55Ed4QVUpMiw05NwyXivCeox-ZE_JDN0BD0,2575
268
268
  omdev/tools/docker.py,sha256=le6QvWEeMo8rB-qxD_AwZRH5kf78uJmdy-ENAamZDBM,7374
@@ -303,9 +303,9 @@ omdev/tools/jsonview/resources/jsonview.js,sha256=faDvXDOXKvEvjOuIlz4D3F2ReQXb_b
303
303
  omdev/tools/pawk/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
304
304
  omdev/tools/pawk/__main__.py,sha256=VCqeRVnqT1RPEoIrqHFSu4PXVMg4YEgF4qCQm90-eRI,66
305
305
  omdev/tools/pawk/pawk.py,sha256=zsEkfQX0jF5bn712uqPAyBSdJt2dno1LH2oeSMNfXQI,11424
306
- omdev-0.0.0.dev349.dist-info/licenses/LICENSE,sha256=B_hVtavaA8zCYDW99DYdcpDLKz1n3BBRjZrcbv8uG8c,1451
307
- omdev-0.0.0.dev349.dist-info/METADATA,sha256=V-BgRu3OjjGcjNvFC1BhN7FqDQmJ0oQSW9WvPDs_VHI,1674
308
- omdev-0.0.0.dev349.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
309
- omdev-0.0.0.dev349.dist-info/entry_points.txt,sha256=dHLXFmq5D9B8qUyhRtFqTGWGxlbx3t5ejedjrnXNYLU,33
310
- omdev-0.0.0.dev349.dist-info/top_level.txt,sha256=1nr7j30fEWgLYHW3lGR9pkdHkb7knv1U1ES1XRNVQ6k,6
311
- omdev-0.0.0.dev349.dist-info/RECORD,,
306
+ omdev-0.0.0.dev350.dist-info/licenses/LICENSE,sha256=B_hVtavaA8zCYDW99DYdcpDLKz1n3BBRjZrcbv8uG8c,1451
307
+ omdev-0.0.0.dev350.dist-info/METADATA,sha256=rt7MtKW9MDK0h2j3-MdZ-d7VMIVoZh9CpeM7Eya6KVE,1674
308
+ omdev-0.0.0.dev350.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
309
+ omdev-0.0.0.dev350.dist-info/entry_points.txt,sha256=dHLXFmq5D9B8qUyhRtFqTGWGxlbx3t5ejedjrnXNYLU,33
310
+ omdev-0.0.0.dev350.dist-info/top_level.txt,sha256=1nr7j30fEWgLYHW3lGR9pkdHkb7knv1U1ES1XRNVQ6k,6
311
+ omdev-0.0.0.dev350.dist-info/RECORD,,