skylos 1.0.9__py3-none-any.whl → 1.0.11__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 skylos might be problematic. Click here for more details.
- skylos/__init__.py +1 -1
- skylos/analyzer.py +89 -17
- skylos/cli.py +24 -1
- skylos/visitor.py +76 -16
- {skylos-1.0.9.dist-info → skylos-1.0.11.dist-info}/METADATA +1 -1
- skylos-1.0.11.dist-info/RECORD +30 -0
- {skylos-1.0.9.dist-info → skylos-1.0.11.dist-info}/WHEEL +1 -1
- test/pykomodo/__init__.py +0 -0
- test/pykomodo/command_line.py +176 -0
- test/pykomodo/config.py +20 -0
- test/pykomodo/core.py +121 -0
- test/pykomodo/dashboard.py +608 -0
- test/pykomodo/enhanced_chunker.py +304 -0
- test/pykomodo/multi_dirs_chunker.py +783 -0
- test/pykomodo/pykomodo_config.py +68 -0
- test/pykomodo/token_chunker.py +470 -0
- skylos-1.0.9.dist-info/RECORD +0 -21
- {skylos-1.0.9.dist-info → skylos-1.0.11.dist-info}/entry_points.txt +0 -0
- {skylos-1.0.9.dist-info → skylos-1.0.11.dist-info}/top_level.txt +0 -0
test/pykomodo/core.py
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import fnmatch
|
|
3
|
+
from typing import List, Optional
|
|
4
|
+
|
|
5
|
+
class PriorityRule:
|
|
6
|
+
"""
|
|
7
|
+
Simple Python container for (pattern, score).
|
|
8
|
+
"""
|
|
9
|
+
def __init__(self, pattern, score):
|
|
10
|
+
self.pattern: str = pattern
|
|
11
|
+
self.score: int = score
|
|
12
|
+
|
|
13
|
+
class PyCConfig:
|
|
14
|
+
"""
|
|
15
|
+
A pure Python equivalent of the 'PyCConfig' that in Cython
|
|
16
|
+
wrapped the 'CConfig' struct. This class maintains the same
|
|
17
|
+
conceptual fields but in Pythonic form (lists, strings, booleans).
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
def __init__(self):
|
|
21
|
+
self.max_size: int = 0
|
|
22
|
+
self.token_mode: bool = False
|
|
23
|
+
self.output_dir: Optional[str] = None
|
|
24
|
+
self.stream: bool = False
|
|
25
|
+
|
|
26
|
+
self.ignore_patterns: List[str] = []
|
|
27
|
+
self.unignore_patterns: List[str] = []
|
|
28
|
+
self.priority_rules: List[PriorityRule] = []
|
|
29
|
+
self.binary_exts: List[str] = []
|
|
30
|
+
|
|
31
|
+
def add_ignore_pattern(self, pattern: str) -> None:
|
|
32
|
+
"""
|
|
33
|
+
Just appends to a Python list.
|
|
34
|
+
"""
|
|
35
|
+
self.ignore_patterns.append(pattern)
|
|
36
|
+
|
|
37
|
+
def add_unignore_pattern(self, pattern: str) -> None:
|
|
38
|
+
self.unignore_patterns.append(pattern)
|
|
39
|
+
|
|
40
|
+
def add_priority_rule(self, pattern: str, score: int) -> None:
|
|
41
|
+
self.priority_rules.append(PriorityRule(pattern, score))
|
|
42
|
+
|
|
43
|
+
def should_ignore(self, path: str) -> bool:
|
|
44
|
+
"""
|
|
45
|
+
Return True if path matches one of the ignore_patterns,
|
|
46
|
+
unless it matches unignore_patterns first.
|
|
47
|
+
"""
|
|
48
|
+
for pat in self.unignore_patterns:
|
|
49
|
+
if fnmatch.fnmatch(path, pat):
|
|
50
|
+
return False
|
|
51
|
+
|
|
52
|
+
for pat in self.ignore_patterns:
|
|
53
|
+
if fnmatch.fnmatch(path, pat):
|
|
54
|
+
return True
|
|
55
|
+
|
|
56
|
+
return False
|
|
57
|
+
|
|
58
|
+
def calculate_priority(self, path: str) -> int:
|
|
59
|
+
"""
|
|
60
|
+
Returns the highest score among any matching priority rule.
|
|
61
|
+
"""
|
|
62
|
+
highest = 0
|
|
63
|
+
for rule in self.priority_rules:
|
|
64
|
+
if fnmatch.fnmatch(path, rule.pattern):
|
|
65
|
+
if rule.score > highest:
|
|
66
|
+
highest = rule.score
|
|
67
|
+
return highest
|
|
68
|
+
|
|
69
|
+
def is_binary_file(self, path: str) -> bool:
|
|
70
|
+
"""
|
|
71
|
+
1) If extension is in self.binary_exts -> True
|
|
72
|
+
2) Else read up to 512 bytes, if it has a null byte -> True
|
|
73
|
+
3) If can't open -> True
|
|
74
|
+
"""
|
|
75
|
+
_, ext = os.path.splitext(path)
|
|
76
|
+
ext = ext.lstrip(".").lower()
|
|
77
|
+
if ext in (b.lower() for b in self.binary_exts):
|
|
78
|
+
return True
|
|
79
|
+
|
|
80
|
+
try:
|
|
81
|
+
with open(path, "rb") as f:
|
|
82
|
+
chunk = f.read(512)
|
|
83
|
+
except OSError:
|
|
84
|
+
return True
|
|
85
|
+
|
|
86
|
+
if b"\0" in chunk:
|
|
87
|
+
return True
|
|
88
|
+
|
|
89
|
+
return False
|
|
90
|
+
|
|
91
|
+
def read_file_contents(self, path: str) -> str:
|
|
92
|
+
"""
|
|
93
|
+
Reads the entire file as text, returns it.
|
|
94
|
+
If can't open, return "<NULL>" or handle differently.
|
|
95
|
+
"""
|
|
96
|
+
try:
|
|
97
|
+
with open(path, "rb") as f:
|
|
98
|
+
data = f.read()
|
|
99
|
+
return data.decode("utf-8", errors="replace")
|
|
100
|
+
except OSError:
|
|
101
|
+
return "<NULL>"
|
|
102
|
+
|
|
103
|
+
def count_tokens(self, text: str) -> int:
|
|
104
|
+
"""
|
|
105
|
+
Replicates py_count_tokens:
|
|
106
|
+
Simple whitespace-based token counting in pure Python.
|
|
107
|
+
"""
|
|
108
|
+
return len(text.split())
|
|
109
|
+
|
|
110
|
+
def make_c_string(self, text: Optional[str]) -> str:
|
|
111
|
+
if text is None:
|
|
112
|
+
return "<NULL>"
|
|
113
|
+
return text
|
|
114
|
+
|
|
115
|
+
def __repr__(self) -> str:
|
|
116
|
+
return (f"PyCConfig(max_size={self.max_size}, token_mode={self.token_mode}, "
|
|
117
|
+
f"output_dir={self.output_dir!r}, stream={self.stream}, "
|
|
118
|
+
f"ignore_patterns={self.ignore_patterns}, "
|
|
119
|
+
f"unignore_patterns={self.unignore_patterns}, "
|
|
120
|
+
f"priority_rules={[ (r.pattern, r.score) for r in self.priority_rules ]}, "
|
|
121
|
+
f"binary_exts={self.binary_exts})")
|