apdev 0.1.6__tar.gz → 0.2.1__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.
Files changed (26) hide show
  1. {apdev-0.1.6 → apdev-0.2.1}/PKG-INFO +3 -2
  2. {apdev-0.1.6 → apdev-0.2.1}/README.md +1 -1
  3. {apdev-0.1.6 → apdev-0.2.1}/pyproject.toml +13 -2
  4. {apdev-0.1.6 → apdev-0.2.1}/src/apdev/__init__.py +1 -1
  5. apdev-0.2.1/src/apdev/charsets/base.json +44 -0
  6. apdev-0.2.1/src/apdev/charsets/chinese.json +9 -0
  7. apdev-0.2.1/src/apdev/charsets/japanese.json +11 -0
  8. apdev-0.2.1/src/apdev/charsets/korean.json +11 -0
  9. {apdev-0.1.6 → apdev-0.2.1}/src/apdev/check_chars.py +118 -62
  10. {apdev-0.1.6 → apdev-0.2.1}/src/apdev/cli.py +35 -2
  11. {apdev-0.1.6 → apdev-0.2.1}/src/apdev/release.sh +6 -1
  12. {apdev-0.1.6 → apdev-0.2.1}/src/apdev.egg-info/PKG-INFO +3 -2
  13. {apdev-0.1.6 → apdev-0.2.1}/src/apdev.egg-info/SOURCES.txt +4 -0
  14. {apdev-0.1.6 → apdev-0.2.1}/tests/test_check_chars.py +119 -0
  15. {apdev-0.1.6 → apdev-0.2.1}/tests/test_check_imports.py +1 -0
  16. {apdev-0.1.6 → apdev-0.2.1}/tests/test_cli.py +51 -0
  17. {apdev-0.1.6 → apdev-0.2.1}/setup.cfg +0 -0
  18. {apdev-0.1.6 → apdev-0.2.1}/src/apdev/__main__.py +0 -0
  19. {apdev-0.1.6 → apdev-0.2.1}/src/apdev/check_imports.py +0 -0
  20. {apdev-0.1.6 → apdev-0.2.1}/src/apdev/config.py +0 -0
  21. {apdev-0.1.6 → apdev-0.2.1}/src/apdev/py.typed +0 -0
  22. {apdev-0.1.6 → apdev-0.2.1}/src/apdev.egg-info/dependency_links.txt +0 -0
  23. {apdev-0.1.6 → apdev-0.2.1}/src/apdev.egg-info/entry_points.txt +0 -0
  24. {apdev-0.1.6 → apdev-0.2.1}/src/apdev.egg-info/requires.txt +0 -0
  25. {apdev-0.1.6 → apdev-0.2.1}/src/apdev.egg-info/top_level.txt +0 -0
  26. {apdev-0.1.6 → apdev-0.2.1}/tests/test_config.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: apdev
3
- Version: 0.1.6
3
+ Version: 0.2.1
4
4
  Summary: Shared development tools for Python projects - character validation, circular import detection, and more
5
5
  Author-email: aipartnerup <tercel.yi@gmail.com>
6
6
  License: Apache-2.0
@@ -8,6 +8,7 @@ Project-URL: Homepage, https://aipartnerup.com
8
8
  Project-URL: Documentation, https://github.com/aipartnerup/apdev
9
9
  Project-URL: Repository, https://github.com/aipartnerup/apdev
10
10
  Project-URL: Issues, https://github.com/aipartnerup/apdev/issues
11
+ Keywords: development-tools,quality-assurance,linting,static-analysis,character-validation,circular-imports,release-automation,unicode-checker,trojan-source-detection
11
12
  Classifier: Development Status :: 4 - Beta
12
13
  Classifier: Intended Audience :: Developers
13
14
  Classifier: License :: OSI Approved :: Apache Software License
@@ -29,7 +30,7 @@ Requires-Dist: ruff>=0.1.0; extra == "dev"
29
30
 
30
31
  # apdev (Python)
31
32
 
32
- Shared development tools for Python projects.
33
+ General-purpose development tools for Python projects.
33
34
 
34
35
  ## Installation
35
36
 
@@ -1,6 +1,6 @@
1
1
  # apdev (Python)
2
2
 
3
- Shared development tools for Python projects.
3
+ General-purpose development tools for Python projects.
4
4
 
5
5
  ## Installation
6
6
 
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "apdev"
7
- version = "0.1.6"
7
+ version = "0.2.1"
8
8
  description = "Shared development tools for Python projects - character validation, circular import detection, and more"
9
9
  readme = "README.md"
10
10
  license = {text = "Apache-2.0"}
@@ -12,6 +12,17 @@ requires-python = ">=3.10"
12
12
  authors = [
13
13
  {name = "aipartnerup", email = "tercel.yi@gmail.com"}
14
14
  ]
15
+ keywords = [
16
+ "development-tools",
17
+ "quality-assurance",
18
+ "linting",
19
+ "static-analysis",
20
+ "character-validation",
21
+ "circular-imports",
22
+ "release-automation",
23
+ "unicode-checker",
24
+ "trojan-source-detection",
25
+ ]
15
26
  classifiers = [
16
27
  "Development Status :: 4 - Beta",
17
28
  "Intended Audience :: Developers",
@@ -43,7 +54,7 @@ dev = [
43
54
  where = ["src"]
44
55
 
45
56
  [tool.setuptools.package-data]
46
- apdev = ["release.sh"]
57
+ apdev = ["release.sh", "charsets/*.json"]
47
58
 
48
59
  [tool.pytest.ini_options]
49
60
  testpaths = ["tests"]
@@ -1,3 +1,3 @@
1
1
  """apdev - Shared development tools for Python projects."""
2
2
 
3
- __version__ = "0.1.6"
3
+ __version__ = "0.2.1"
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "base",
3
+ "description": "Default: ASCII + emoji + technical symbols",
4
+ "emoji_ranges": [
5
+ { "start": "0x1F300", "end": "0x1F5FF", "name": "Symbols and Pictographs" },
6
+ { "start": "0x1F600", "end": "0x1F64F", "name": "Emoticons" },
7
+ { "start": "0x1F680", "end": "0x1F6FF", "name": "Transport and Map Symbols" },
8
+ { "start": "0x1F780", "end": "0x1F7FF", "name": "Geometric Shapes Extended" },
9
+ { "start": "0x1F900", "end": "0x1F9FF", "name": "Supplemental Symbols and Pictographs" },
10
+ { "start": "0x2600", "end": "0x26FF", "name": "Miscellaneous Symbols" },
11
+ { "start": "0x2700", "end": "0x27BF", "name": "Dingbats" }
12
+ ],
13
+ "extra_ranges": [
14
+ { "start": "0x0080", "end": "0x00FF", "name": "Latin-1 Supplement" },
15
+ { "start": "0x2000", "end": "0x206F", "name": "General Punctuation" },
16
+ { "start": "0x2100", "end": "0x214F", "name": "Letterlike Symbols" },
17
+ { "start": "0x2190", "end": "0x21FF", "name": "Arrows" },
18
+ { "start": "0x2200", "end": "0x22FF", "name": "Mathematical Operators" },
19
+ { "start": "0x2300", "end": "0x23FF", "name": "Miscellaneous Technical" },
20
+ { "start": "0x2500", "end": "0x257F", "name": "Box Drawing" },
21
+ { "start": "0x2580", "end": "0x259F", "name": "Block Elements" },
22
+ { "start": "0x25A0", "end": "0x25FF", "name": "Geometric Shapes" },
23
+ { "start": "0x2800", "end": "0x28FF", "name": "Braille Patterns" },
24
+ { "start": "0x2B00", "end": "0x2BFF", "name": "Miscellaneous Symbols and Arrows" },
25
+ { "start": "0xFE00", "end": "0xFE0F", "name": "Variation Selectors" }
26
+ ],
27
+ "dangerous": [
28
+ { "code": "0x202A", "name": "LEFT-TO-RIGHT EMBEDDING" },
29
+ { "code": "0x202B", "name": "RIGHT-TO-LEFT EMBEDDING" },
30
+ { "code": "0x202C", "name": "POP DIRECTIONAL FORMATTING" },
31
+ { "code": "0x202D", "name": "LEFT-TO-RIGHT OVERRIDE" },
32
+ { "code": "0x202E", "name": "RIGHT-TO-LEFT OVERRIDE" },
33
+ { "code": "0x2066", "name": "LEFT-TO-RIGHT ISOLATE" },
34
+ { "code": "0x2067", "name": "RIGHT-TO-LEFT ISOLATE" },
35
+ { "code": "0x2068", "name": "FIRST STRONG ISOLATE" },
36
+ { "code": "0x2069", "name": "POP DIRECTIONAL ISOLATE" },
37
+ { "code": "0x200B", "name": "ZERO WIDTH SPACE" },
38
+ { "code": "0x200C", "name": "ZERO WIDTH NON-JOINER" },
39
+ { "code": "0x200D", "name": "ZERO WIDTH JOINER" },
40
+ { "code": "0x200E", "name": "LEFT-TO-RIGHT MARK" },
41
+ { "code": "0x200F", "name": "RIGHT-TO-LEFT MARK" },
42
+ { "code": "0x2060", "name": "WORD JOINER" }
43
+ ]
44
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "chinese",
3
+ "description": "Chinese: CJK Unified Ideographs, CJK Punctuation, Fullwidth Forms",
4
+ "extra_ranges": [
5
+ { "start": "0x3000", "end": "0x303F", "name": "CJK Symbols and Punctuation" },
6
+ { "start": "0x4E00", "end": "0x9FFF", "name": "CJK Unified Ideographs" },
7
+ { "start": "0xFF00", "end": "0xFFEF", "name": "Fullwidth Forms" }
8
+ ]
9
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "name": "japanese",
3
+ "description": "Japanese: Hiragana, Katakana, CJK Unified Ideographs, CJK Punctuation, Fullwidth Forms",
4
+ "extra_ranges": [
5
+ { "start": "0x3000", "end": "0x303F", "name": "CJK Symbols and Punctuation" },
6
+ { "start": "0x3040", "end": "0x309F", "name": "Hiragana" },
7
+ { "start": "0x30A0", "end": "0x30FF", "name": "Katakana" },
8
+ { "start": "0x4E00", "end": "0x9FFF", "name": "CJK Unified Ideographs" },
9
+ { "start": "0xFF00", "end": "0xFFEF", "name": "Fullwidth Forms" }
10
+ ]
11
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "name": "korean",
3
+ "description": "Korean: Hangul Jamo, Hangul Syllables, CJK Unified Ideographs, CJK Punctuation, Fullwidth Forms",
4
+ "extra_ranges": [
5
+ { "start": "0x1100", "end": "0x11FF", "name": "Hangul Jamo" },
6
+ { "start": "0x3000", "end": "0x303F", "name": "CJK Symbols and Punctuation" },
7
+ { "start": "0x4E00", "end": "0x9FFF", "name": "CJK Unified Ideographs" },
8
+ { "start": "0xAC00", "end": "0xD7AF", "name": "Hangul Syllables" },
9
+ { "start": "0xFF00", "end": "0xFFEF", "name": "Fullwidth Forms" }
10
+ ]
11
+ }
@@ -9,75 +9,115 @@ Additionally flags dangerous invisible/bidi characters in code regions
9
9
 
10
10
  from __future__ import annotations
11
11
 
12
+ import importlib.resources
13
+ import json
14
+ import os
12
15
  from pathlib import Path
13
16
 
14
- # Allowed Unicode ranges beyond ASCII (0-127)
15
- EMOJI_RANGES: list[tuple[int, int]] = [
16
- (0x1F300, 0x1F5FF), # Symbols and Pictographs
17
- (0x1F600, 0x1F64F), # Emoticons
18
- (0x1F680, 0x1F6FF), # Transport and Map Symbols
19
- (0x1F780, 0x1F7FF), # Geometric Shapes Extended
20
- (0x1F900, 0x1F9FF), # Supplemental Symbols and Pictographs
21
- (0x2600, 0x26FF), # Miscellaneous Symbols
22
- (0x2700, 0x27BF), # Dingbats
23
- ]
24
-
25
- EXTRA_ALLOWED_RANGES: list[tuple[int, int]] = [
26
- (0x0080, 0x00FF), # Latin-1 Supplement
27
- (0x2000, 0x206F), # General Punctuation
28
- (0x2100, 0x214F), # Letterlike Symbols
29
- (0x2190, 0x21FF), # Arrows
30
- (0x2200, 0x22FF), # Mathematical Operators
31
- (0x2300, 0x23FF), # Miscellaneous Technical
32
- (0x2500, 0x257F), # Box Drawing
33
- (0x25A0, 0x25FF), # Geometric Shapes
34
- (0x2B00, 0x2BFF), # Miscellaneous Symbols and Arrows
35
- (0xFE00, 0xFE0F), # Variation Selectors
36
- ]
37
-
38
- _ALL_RANGES = EMOJI_RANGES + EXTRA_ALLOWED_RANGES
39
-
40
- # Dangerous codepoints that pass the allowed-range check but should be
41
- # flagged when they appear in code (not comments). These are within the
42
- # General Punctuation range (0x2000-0x206F) which is broadly allowed.
43
- DANGEROUS_CODEPOINTS: dict[int, str] = {
44
- # Bidi control characters (Trojan Source - CVE-2021-42574)
45
- 0x202A: "LEFT-TO-RIGHT EMBEDDING",
46
- 0x202B: "RIGHT-TO-LEFT EMBEDDING",
47
- 0x202C: "POP DIRECTIONAL FORMATTING",
48
- 0x202D: "LEFT-TO-RIGHT OVERRIDE",
49
- 0x202E: "RIGHT-TO-LEFT OVERRIDE",
50
- 0x2066: "LEFT-TO-RIGHT ISOLATE",
51
- 0x2067: "RIGHT-TO-LEFT ISOLATE",
52
- 0x2068: "FIRST STRONG ISOLATE",
53
- 0x2069: "POP DIRECTIONAL ISOLATE",
54
- # Zero-width characters
55
- 0x200B: "ZERO WIDTH SPACE",
56
- 0x200C: "ZERO WIDTH NON-JOINER",
57
- 0x200D: "ZERO WIDTH JOINER",
58
- 0x200E: "LEFT-TO-RIGHT MARK",
59
- 0x200F: "RIGHT-TO-LEFT MARK",
60
- 0x2060: "WORD JOINER",
61
- }
62
17
 
63
- _PYTHON_SUFFIXES = {".py"}
64
- _JS_SUFFIXES = {".js", ".ts", ".tsx", ".jsx", ".mjs", ".cjs"}
18
+ def load_charset(name_or_path: str) -> dict:
19
+ """Load a charset definition by preset name or file path.
65
20
 
21
+ If name_or_path contains a path separator or ends with .json,
22
+ it is treated as a file path. Otherwise it is looked up from
23
+ the bundled charsets/ directory.
24
+ """
25
+ if os.sep in name_or_path or name_or_path.endswith(".json"):
26
+ p = Path(name_or_path)
27
+ if not p.is_file():
28
+ raise FileNotFoundError(f"Charset file not found: {name_or_path}")
29
+ return json.loads(p.read_text(encoding="utf-8"))
66
30
 
67
- def is_allowed_char(c: str) -> bool:
68
- """Return True if the character is in the allowed set."""
31
+ ref = importlib.resources.files("apdev").joinpath("charsets", f"{name_or_path}.json")
32
+ try:
33
+ text = ref.read_text(encoding="utf-8")
34
+ except Exception as exc:
35
+ raise FileNotFoundError(f"Unknown charset: {name_or_path}") from exc
36
+ return json.loads(text)
37
+
38
+
39
+ def _parse_ranges(entries: list[dict]) -> list[tuple[int, int]]:
40
+ """Convert JSON range entries to (start, end) tuples."""
41
+ return [(int(e["start"], 16), int(e["end"], 16)) for e in entries]
42
+
43
+
44
+ def _parse_dangerous(entries: list[dict]) -> dict[int, str]:
45
+ """Convert JSON dangerous entries to {code: name} dict."""
46
+ return {int(e["code"], 16): e["name"] for e in entries}
47
+
48
+
49
+ def resolve_charsets(
50
+ charset_names: list[str],
51
+ charset_files: list[str],
52
+ ) -> tuple[list[tuple[int, int]], dict[int, str]]:
53
+ """Load base charset and merge any additional charsets.
54
+
55
+ Returns (all_ranges, dangerous_codepoints).
56
+ """
57
+ base = load_charset("base")
58
+ ranges_set: set[tuple[int, int]] = set()
59
+ ranges_set.update(_parse_ranges(base.get("emoji_ranges", [])))
60
+ ranges_set.update(_parse_ranges(base.get("extra_ranges", [])))
61
+ dangerous = _parse_dangerous(base.get("dangerous", []))
62
+
63
+ for name in charset_names:
64
+ data = load_charset(name)
65
+ ranges_set.update(_parse_ranges(data.get("emoji_ranges", [])))
66
+ ranges_set.update(_parse_ranges(data.get("extra_ranges", [])))
67
+ dangerous.update(_parse_dangerous(data.get("dangerous", [])))
68
+
69
+ for path in charset_files:
70
+ data = load_charset(path)
71
+ ranges_set.update(_parse_ranges(data.get("emoji_ranges", [])))
72
+ ranges_set.update(_parse_ranges(data.get("extra_ranges", [])))
73
+ dangerous.update(_parse_dangerous(data.get("dangerous", [])))
74
+
75
+ return sorted(ranges_set), dangerous
76
+
77
+
78
+ def _is_in_ranges(c: str, ranges: list[tuple[int, int]]) -> bool:
79
+ """Return True if the character is in any of the given ranges or ASCII."""
69
80
  code = ord(c)
70
81
  if code <= 127:
71
82
  return True
72
- for start, end in _ALL_RANGES:
83
+ for start, end in ranges:
73
84
  if start <= code <= end:
74
85
  return True
75
86
  return False
76
87
 
77
88
 
89
+ # Lazy-loaded base charset defaults for backward-compatible public API
90
+ _BASE_RANGES: list[tuple[int, int]] | None = None
91
+ _BASE_DANGEROUS: dict[int, str] | None = None
92
+
93
+
94
+ def _get_base_defaults() -> tuple[list[tuple[int, int]], dict[int, str]]:
95
+ global _BASE_RANGES, _BASE_DANGEROUS
96
+ if _BASE_RANGES is None or _BASE_DANGEROUS is None:
97
+ _BASE_RANGES, _BASE_DANGEROUS = resolve_charsets([], [])
98
+ return _BASE_RANGES, _BASE_DANGEROUS
99
+
100
+
101
+ def is_allowed_char(c: str) -> bool:
102
+ """Return True if the character is in the base allowed set.
103
+
104
+ Dangerous codepoints (Trojan Source vectors) are excluded even though
105
+ they fall within allowed Unicode ranges.
106
+ """
107
+ ranges, dangerous = _get_base_defaults()
108
+ if ord(c) in dangerous:
109
+ return False
110
+ return _is_in_ranges(c, ranges)
111
+
112
+
78
113
  def is_dangerous_char(c: str) -> bool:
79
114
  """Return True if the character is a dangerous invisible/bidi codepoint."""
80
- return ord(c) in DANGEROUS_CODEPOINTS
115
+ _, dangerous = _get_base_defaults()
116
+ return ord(c) in dangerous
117
+
118
+
119
+ _PYTHON_SUFFIXES = {".py"}
120
+ _JS_SUFFIXES = {".js", ".ts", ".tsx", ".jsx", ".mjs", ".cjs"}
81
121
 
82
122
 
83
123
  def _compute_comment_mask(content: str, suffix: str) -> set[int]:
@@ -196,29 +236,40 @@ def _compute_comment_mask_js(content: str) -> set[int]:
196
236
  return mask
197
237
 
198
238
 
199
- def check_file(path: Path, *, max_problems: int = 5) -> list[str]:
239
+ def check_file(
240
+ path: Path,
241
+ *,
242
+ max_problems: int = 5,
243
+ extra_ranges: list[tuple[int, int]] | None = None,
244
+ dangerous: dict[int, str] | None = None,
245
+ ) -> list[str]:
200
246
  """Check a single file for illegal characters.
201
247
 
202
248
  Returns a list of problem descriptions (empty if the file is clean).
203
249
  """
204
250
  problems: list[str] = []
251
+ if extra_ranges is None or dangerous is None:
252
+ default_ranges, default_dangerous = _get_base_defaults()
253
+ if extra_ranges is None:
254
+ extra_ranges = default_ranges
255
+ if dangerous is None:
256
+ dangerous = default_dangerous
205
257
  try:
206
258
  content = path.read_text(encoding="utf-8")
207
259
  suffix = path.suffix.lower()
208
260
  comment_mask = _compute_comment_mask(content, suffix)
209
261
  for i, char in enumerate(content):
210
- if is_dangerous_char(char):
262
+ if ord(char) in dangerous:
211
263
  if i not in comment_mask:
212
264
  code = ord(char)
213
- name = DANGEROUS_CODEPOINTS[code]
265
+ name = dangerous[code]
214
266
  problems.append(
215
267
  f"Dangerous character in code at position {i + 1}: "
216
268
  f"U+{code:04X} ({name})"
217
269
  )
218
- elif not is_allowed_char(char):
270
+ elif not _is_in_ranges(char, extra_ranges):
219
271
  problems.append(
220
- f"Illegal character at position {i + 1}: "
221
- f"{char!r} (U+{ord(char):04X})"
272
+ f"Illegal character at position {i + 1}: " f"{char!r} (U+{ord(char):04X})"
222
273
  )
223
274
  if len(problems) >= max_problems:
224
275
  break
@@ -227,11 +278,16 @@ def check_file(path: Path, *, max_problems: int = 5) -> list[str]:
227
278
  return problems
228
279
 
229
280
 
230
- def check_paths(paths: list[Path]) -> int:
281
+ def check_paths(
282
+ paths: list[Path],
283
+ *,
284
+ extra_ranges: list[tuple[int, int]] | None = None,
285
+ dangerous: dict[int, str] | None = None,
286
+ ) -> int:
231
287
  """Check multiple files. Returns 0 if all clean, 1 if any have problems."""
232
288
  has_error = False
233
289
  for path in paths:
234
- problems = check_file(path)
290
+ problems = check_file(path, extra_ranges=extra_ranges, dangerous=dangerous)
235
291
  if problems:
236
292
  has_error = True
237
293
  print(f"\n{path} contains illegal characters:")
@@ -44,6 +44,19 @@ def _build_parser() -> argparse.ArgumentParser:
44
44
  type=Path,
45
45
  help="Files to check",
46
46
  )
47
+ chars_parser.add_argument(
48
+ "--charset",
49
+ action="append",
50
+ default=[],
51
+ help="Extra charset preset to enable (repeatable, e.g. --charset chinese)",
52
+ )
53
+ chars_parser.add_argument(
54
+ "--charset-file",
55
+ action="append",
56
+ default=[],
57
+ dest="charset_files",
58
+ help="Path to custom charset JSON file (repeatable)",
59
+ )
47
60
 
48
61
  # check-imports
49
62
  imports_parser = subparsers.add_parser(
@@ -67,7 +80,8 @@ def _build_parser() -> argparse.ArgumentParser:
67
80
  help="Interactive release automation (build, tag, GitHub release, PyPI upload)",
68
81
  )
69
82
  release_parser.add_argument(
70
- "--yes", "-y",
83
+ "--yes",
84
+ "-y",
71
85
  action="store_true",
72
86
  help="Auto-accept all defaults (silent mode)",
73
87
  )
@@ -90,7 +104,26 @@ def main(argv: list[str] | None = None) -> int:
90
104
  return 0
91
105
 
92
106
  if args.command == "check-chars":
93
- return check_paths(args.files)
107
+ from apdev.check_chars import resolve_charsets
108
+
109
+ charset_names = list(args.charset)
110
+ charset_files = list(args.charset_files)
111
+
112
+ # Fall back to APDEV_EXTRA_CHARS env var if no CLI args
113
+ if not charset_names and not charset_files:
114
+ env_val = os.environ.get("APDEV_EXTRA_CHARS", "")
115
+ if env_val:
116
+ for item in env_val.split(","):
117
+ item = item.strip()
118
+ if not item:
119
+ continue
120
+ if os.sep in item or item.endswith(".json"):
121
+ charset_files.append(item)
122
+ else:
123
+ charset_names.append(item)
124
+
125
+ extra_ranges, dangerous = resolve_charsets(charset_names, charset_files)
126
+ return check_paths(args.files, extra_ranges=extra_ranges, dangerous=dangerous)
94
127
 
95
128
  if args.command == "check-imports":
96
129
  config = load_config()
@@ -203,7 +203,11 @@ step1_version_verification() {
203
203
  echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
204
204
 
205
205
  PYPROJECT_VERSION=$(grep -E '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/')
206
- INIT_VERSION=$(grep -E '^__version__ = ' src/${PACKAGE_NAME}/__init__.py | sed 's/__version__ = "\(.*\)"/\1/')
206
+ # Support both static (__version__ = "x.x.x") and dynamic (importlib.metadata) version patterns
207
+ INIT_VERSION=$(python3 -c "from ${PACKAGE_NAME} import __version__; print(__version__)" 2>/dev/null)
208
+ if [ -z "$INIT_VERSION" ]; then
209
+ INIT_VERSION=$(grep -E '^__version__ = ' src/${PACKAGE_NAME}/__init__.py | sed 's/__version__ = "\(.*\)"/\1/')
210
+ fi
207
211
 
208
212
  echo -e " pyproject.toml: ${CYAN}${PYPROJECT_VERSION}${NC}"
209
213
  echo -e " __init__.py: ${CYAN}${INIT_VERSION}${NC}"
@@ -211,6 +215,7 @@ step1_version_verification() {
211
215
 
212
216
  if [ "$PYPROJECT_VERSION" != "$VERSION" ] || [ "$INIT_VERSION" != "$VERSION" ]; then
213
217
  echo -e "${RED}❌ Version mismatch detected!${NC}"
218
+ echo -e "${YELLOW}💡 Hint: Try 'pip install -e .' to sync the installed package version${NC}"
214
219
  return 1
215
220
  fi
216
221
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: apdev
3
- Version: 0.1.6
3
+ Version: 0.2.1
4
4
  Summary: Shared development tools for Python projects - character validation, circular import detection, and more
5
5
  Author-email: aipartnerup <tercel.yi@gmail.com>
6
6
  License: Apache-2.0
@@ -8,6 +8,7 @@ Project-URL: Homepage, https://aipartnerup.com
8
8
  Project-URL: Documentation, https://github.com/aipartnerup/apdev
9
9
  Project-URL: Repository, https://github.com/aipartnerup/apdev
10
10
  Project-URL: Issues, https://github.com/aipartnerup/apdev/issues
11
+ Keywords: development-tools,quality-assurance,linting,static-analysis,character-validation,circular-imports,release-automation,unicode-checker,trojan-source-detection
11
12
  Classifier: Development Status :: 4 - Beta
12
13
  Classifier: Intended Audience :: Developers
13
14
  Classifier: License :: OSI Approved :: Apache Software License
@@ -29,7 +30,7 @@ Requires-Dist: ruff>=0.1.0; extra == "dev"
29
30
 
30
31
  # apdev (Python)
31
32
 
32
- Shared development tools for Python projects.
33
+ General-purpose development tools for Python projects.
33
34
 
34
35
  ## Installation
35
36
 
@@ -14,6 +14,10 @@ src/apdev.egg-info/dependency_links.txt
14
14
  src/apdev.egg-info/entry_points.txt
15
15
  src/apdev.egg-info/requires.txt
16
16
  src/apdev.egg-info/top_level.txt
17
+ src/apdev/charsets/base.json
18
+ src/apdev/charsets/chinese.json
19
+ src/apdev/charsets/japanese.json
20
+ src/apdev/charsets/korean.json
17
21
  tests/test_check_chars.py
18
22
  tests/test_check_imports.py
19
23
  tests/test_cli.py
@@ -7,6 +7,8 @@ from apdev.check_chars import (
7
7
  check_paths,
8
8
  is_allowed_char,
9
9
  is_dangerous_char,
10
+ load_charset,
11
+ resolve_charsets,
10
12
  )
11
13
 
12
14
 
@@ -36,6 +38,29 @@ def test_arrow_chars_allowed() -> None:
36
38
  assert is_allowed_char("\u2190") # leftwards arrow
37
39
 
38
40
 
41
+ def test_block_elements_allowed() -> None:
42
+ """Block element characters used in progress bars should be allowed."""
43
+ chars = ["\u2580", "\u2584", "\u2588", "\u2591", "\u2592", "\u2593"] # ▀ ▄ █ ░ ▒ ▓
44
+ for ch in chars:
45
+ assert is_allowed_char(ch), f"{ch!r} (U+{ord(ch):04X}) should be allowed"
46
+
47
+
48
+ def test_braille_patterns_allowed() -> None:
49
+ """Braille pattern characters used in terminal graphics should be allowed."""
50
+ chars = ["\u2800", "\u2801", "\u28ff", "\u2840"] # ⠀ ⠁ ⣿ ⡀
51
+ for ch in chars:
52
+ assert is_allowed_char(ch), f"{ch!r} (U+{ord(ch):04X}) should be allowed"
53
+
54
+
55
+ def test_dangerous_chars_not_allowed() -> None:
56
+ """Dangerous codepoints should NOT pass is_allowed_char even though they
57
+ fall within the General Punctuation allowed range."""
58
+ assert not is_allowed_char("\u200b") # ZERO WIDTH SPACE
59
+ assert not is_allowed_char("\u202e") # RIGHT-TO-LEFT OVERRIDE
60
+ assert not is_allowed_char("\u2066") # LEFT-TO-RIGHT ISOLATE
61
+ assert not is_allowed_char("\u2060") # WORD JOINER
62
+
63
+
39
64
  def test_chinese_chars_rejected() -> None:
40
65
  """CJK characters should be rejected by default."""
41
66
  assert not is_allowed_char("\u4e2d") # Chinese character
@@ -89,6 +114,7 @@ def test_check_paths_returns_exit_code(tmp_path: Path) -> None:
89
114
  # Dangerous character tests
90
115
  # ---------------------------------------------------------------------------
91
116
 
117
+
92
118
  def test_is_dangerous_char() -> None:
93
119
  """is_dangerous_char identifies all 15 dangerous codepoints."""
94
120
  # Bidi controls
@@ -194,3 +220,96 @@ def test_unknown_extension_treats_all_as_code(tmp_path: Path) -> None:
194
220
  problems = check_file(f)
195
221
  assert len(problems) == 1
196
222
  assert "Dangerous character in code" in problems[0]
223
+
224
+
225
+ # ---------------------------------------------------------------------------
226
+ # Charset loading tests
227
+ # ---------------------------------------------------------------------------
228
+
229
+
230
+ def test_load_charset_base() -> None:
231
+ """load_charset('base') returns ranges and dangerous dicts."""
232
+ data = load_charset("base")
233
+ assert data["name"] == "base"
234
+ assert len(data["emoji_ranges"]) > 0
235
+ assert len(data["extra_ranges"]) > 0
236
+ assert len(data["dangerous"]) > 0
237
+
238
+
239
+ def test_load_charset_chinese() -> None:
240
+ """load_charset('chinese') returns CJK ranges."""
241
+ data = load_charset("chinese")
242
+ assert data["name"] == "chinese"
243
+ assert len(data["extra_ranges"]) > 0
244
+
245
+
246
+ def test_load_charset_unknown_raises() -> None:
247
+ """load_charset with unknown name raises FileNotFoundError."""
248
+ import pytest
249
+
250
+ with pytest.raises(FileNotFoundError):
251
+ load_charset("nonexistent")
252
+
253
+
254
+ def test_load_charset_file(tmp_path: Path) -> None:
255
+ """load_charset can load from an absolute file path."""
256
+ custom = tmp_path / "custom.json"
257
+ custom.write_text(
258
+ '{"name":"custom","extra_ranges":[{"start":"0x4E00","end":"0x9FFF","name":"CJK"}]}'
259
+ )
260
+ data = load_charset(str(custom))
261
+ assert data["name"] == "custom"
262
+
263
+
264
+ def test_resolve_charsets_default() -> None:
265
+ """No extra charsets returns base ranges only."""
266
+ ranges, dangerous = resolve_charsets([], [])
267
+ assert len(ranges) > 0
268
+ assert len(dangerous) > 0
269
+ # CJK should NOT be in ranges
270
+ assert not any(0x4E00 <= s and e <= 0x9FFF for s, e in ranges)
271
+
272
+
273
+ def test_resolve_charsets_with_chinese() -> None:
274
+ """Adding 'chinese' charset includes CJK Unified Ideographs."""
275
+ ranges, dangerous = resolve_charsets(["chinese"], [])
276
+ assert any(s <= 0x4E00 and 0x9FFF <= e for s, e in ranges)
277
+
278
+
279
+ def test_resolve_charsets_with_custom_file(tmp_path: Path) -> None:
280
+ """Custom charset file ranges are merged."""
281
+ custom = tmp_path / "custom.json"
282
+ custom.write_text(
283
+ '{"name":"custom","extra_ranges":[{"start":"0xABCD","end":"0xABFF","name":"Test"}]}'
284
+ )
285
+ ranges, _ = resolve_charsets([], [str(custom)])
286
+ assert any(s <= 0xABCD and 0xABFF <= e for s, e in ranges)
287
+
288
+
289
+ def test_resolve_charsets_deduplicates() -> None:
290
+ """Duplicate ranges from overlapping charsets are deduplicated."""
291
+ ranges, _ = resolve_charsets(["chinese", "japanese"], [])
292
+ cjk_count = sum(1 for s, e in ranges if s == 0x4E00 and e == 0x9FFF)
293
+ assert cjk_count == 1
294
+
295
+
296
+ # ---------------------------------------------------------------------------
297
+ # check_file / check_paths with custom charsets
298
+ # ---------------------------------------------------------------------------
299
+
300
+
301
+ def test_check_file_with_chinese_charset(tmp_path: Path) -> None:
302
+ """Chinese characters should pass when chinese charset is active."""
303
+ f = tmp_path / "cn.py"
304
+ f.write_text("x = '\u4e2d\u6587'\n", encoding="utf-8")
305
+ ranges, dangerous = resolve_charsets(["chinese"], [])
306
+ problems = check_file(f, extra_ranges=ranges, dangerous=dangerous)
307
+ assert problems == []
308
+
309
+
310
+ def test_check_paths_with_charset(tmp_path: Path) -> None:
311
+ """check_paths passes charsets through to check_file."""
312
+ f = tmp_path / "cn.py"
313
+ f.write_text("x = '\u4e2d\u6587'\n", encoding="utf-8")
314
+ ranges, dangerous = resolve_charsets(["chinese"], [])
315
+ assert check_paths([f], extra_ranges=ranges, dangerous=dangerous) == 0
@@ -94,6 +94,7 @@ def test_find_cycles_deduplication() -> None:
94
94
  # Relative import tests
95
95
  # ---------------------------------------------------------------------------
96
96
 
97
+
97
98
  def test_import_analyzer_relative_from_dot_module() -> None:
98
99
  """'from .b import x' in mypkg.a resolves to mypkg.b."""
99
100
  source = "from .b import something"
@@ -1,5 +1,6 @@
1
1
  """Tests for the apdev CLI."""
2
2
 
3
+ import os
3
4
  import subprocess
4
5
  import sys
5
6
  import textwrap
@@ -81,3 +82,53 @@ def test_cli_check_imports_reads_config(tmp_path: Path) -> None:
81
82
  result = run_apdev("check-imports", cwd=tmp_path)
82
83
  assert result.returncode == 0
83
84
  assert "No circular imports" in result.stdout
85
+
86
+
87
+ def test_cli_check_chars_with_charset(tmp_path: Path) -> None:
88
+ """--charset chinese allows CJK characters."""
89
+ f = tmp_path / "cn.py"
90
+ f.write_text("x = '\u4e2d\u6587'\n")
91
+ result = run_apdev("check-chars", "--charset", "chinese", str(f))
92
+ assert result.returncode == 0
93
+
94
+
95
+ def test_cli_check_chars_with_env_var(tmp_path: Path) -> None:
96
+ """APDEV_EXTRA_CHARS=chinese allows CJK characters."""
97
+ f = tmp_path / "cn.py"
98
+ f.write_text("x = '\u4e2d\u6587'\n")
99
+ result = subprocess.run(
100
+ [sys.executable, "-m", "apdev", "check-chars", str(f)],
101
+ capture_output=True,
102
+ text=True,
103
+ env={**os.environ, "APDEV_EXTRA_CHARS": "chinese"},
104
+ )
105
+ assert result.returncode == 0
106
+
107
+
108
+ def test_cli_check_chars_cli_overrides_env(tmp_path: Path) -> None:
109
+ """CLI --charset overrides APDEV_EXTRA_CHARS (env ignored when CLI args present)."""
110
+ f = tmp_path / "cn.py"
111
+ f.write_text("x = '\u4e2d\u6587'\n")
112
+ # Env says chinese, but CLI provides a charset that doesn't include CJK
113
+ custom = tmp_path / "empty.json"
114
+ custom.write_text('{"name":"empty","extra_ranges":[]}')
115
+ result = subprocess.run(
116
+ [sys.executable, "-m", "apdev", "check-chars", "--charset-file", str(custom), str(f)],
117
+ capture_output=True,
118
+ text=True,
119
+ env={**os.environ, "APDEV_EXTRA_CHARS": "chinese"},
120
+ )
121
+ # CLI args present → env var ignored → CJK rejected
122
+ assert result.returncode == 1
123
+
124
+
125
+ def test_cli_check_chars_charset_file(tmp_path: Path) -> None:
126
+ """--charset-file with custom JSON allows specified ranges."""
127
+ custom = tmp_path / "custom.json"
128
+ custom.write_text(
129
+ '{"name":"custom","extra_ranges":[{"start":"0x4E00","end":"0x9FFF","name":"CJK"}]}'
130
+ )
131
+ f = tmp_path / "cn.py"
132
+ f.write_text("x = '\u4e2d\u6587'\n")
133
+ result = run_apdev("check-chars", "--charset-file", str(custom), str(f))
134
+ assert result.returncode == 0
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes