fluidattacks_core_serializers 12.1.0__tar.gz → 12.2.0__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.
- {fluidattacks_core_serializers-12.1.0 → fluidattacks_core_serializers-12.2.0}/PKG-INFO +2 -1
- {fluidattacks_core_serializers-12.1.0 → fluidattacks_core_serializers-12.2.0}/fluidattacks_core/serializers/snippet.py +15 -161
- {fluidattacks_core_serializers-12.1.0 → fluidattacks_core_serializers-12.2.0}/pyproject.toml +17 -3
- {fluidattacks_core_serializers-12.1.0 → fluidattacks_core_serializers-12.2.0}/tests/test_make_snippet.py +0 -164
- fluidattacks_core_serializers-12.2.0/uv.lock +983 -0
- fluidattacks_core_serializers-12.1.0/uv.lock +0 -975
- {fluidattacks_core_serializers-12.1.0 → fluidattacks_core_serializers-12.2.0}/.envrc +0 -0
- {fluidattacks_core_serializers-12.1.0 → fluidattacks_core_serializers-12.2.0}/.gitignore +0 -0
- {fluidattacks_core_serializers-12.1.0 → fluidattacks_core_serializers-12.2.0}/fluidattacks_core/serializers/__init__.py +0 -0
- {fluidattacks_core_serializers-12.1.0 → fluidattacks_core_serializers-12.2.0}/fluidattacks_core/serializers/py.typed +0 -0
- {fluidattacks_core_serializers-12.1.0 → fluidattacks_core_serializers-12.2.0}/fluidattacks_core/serializers/syntax.py +0 -0
- {fluidattacks_core_serializers-12.1.0 → fluidattacks_core_serializers-12.2.0}/import-linter.cfg +0 -0
- {fluidattacks_core_serializers-12.1.0 → fluidattacks_core_serializers-12.2.0}/mypy.ini +0 -0
- {fluidattacks_core_serializers-12.1.0 → fluidattacks_core_serializers-12.2.0}/ruff.toml +0 -0
- {fluidattacks_core_serializers-12.1.0 → fluidattacks_core_serializers-12.2.0}/tests/__init__.py +0 -0
- {fluidattacks_core_serializers-12.1.0 → fluidattacks_core_serializers-12.2.0}/tests/test_elixir_syntax.py +0 -0
- {fluidattacks_core_serializers-12.1.0 → fluidattacks_core_serializers-12.2.0}/tests/test_syntax_language_resolution.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: fluidattacks_core_serializers
|
|
3
|
-
Version: 12.
|
|
3
|
+
Version: 12.2.0
|
|
4
4
|
Summary: Fluid Attacks Core Serializers Library
|
|
5
5
|
Author-email: Development <development@fluidattacks.com>
|
|
6
6
|
License: MPL-2.0
|
|
@@ -11,6 +11,7 @@ Classifier: Programming Language :: Python :: 3
|
|
|
11
11
|
Classifier: Programming Language :: Python :: 3.11
|
|
12
12
|
Classifier: Topic :: Software Development :: Libraries
|
|
13
13
|
Requires-Python: >=3.11
|
|
14
|
+
Requires-Dist: fluidattacks-core-snippets>=0.1.0
|
|
14
15
|
Requires-Dist: more-itertools>=10.0.0
|
|
15
16
|
Requires-Dist: tree-sitter-c-sharp>=0.23.1
|
|
16
17
|
Requires-Dist: tree-sitter-dart-orchard>=0.3.2
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
from collections.abc import Iterator
|
|
2
1
|
from contextlib import suppress
|
|
3
|
-
from operator import itemgetter
|
|
4
2
|
from typing import NamedTuple
|
|
5
3
|
|
|
6
|
-
from more_itertools import chunked
|
|
7
4
|
from tree_sitter import Node
|
|
8
5
|
|
|
9
6
|
from fluidattacks_core.serializers.syntax import (
|
|
@@ -16,6 +13,8 @@ from fluidattacks_core.serializers.syntax import (
|
|
|
16
13
|
get_language_from_path,
|
|
17
14
|
get_node_content,
|
|
18
15
|
)
|
|
16
|
+
from fluidattacks_core.snippets import SnippetViewport as CoreSnippetViewport
|
|
17
|
+
from fluidattacks_core.snippets import make_snippet
|
|
19
18
|
|
|
20
19
|
# Constants
|
|
21
20
|
SNIPPETS_CONTEXT: int = 10
|
|
@@ -112,169 +111,24 @@ def _make_snippet(
|
|
|
112
111
|
viewport: SnippetViewport | None = None,
|
|
113
112
|
offset: int | None = None,
|
|
114
113
|
) -> Snippet:
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
# Build a list of line numbers to line contents, handling wrapping
|
|
119
|
-
if viewport is not None:
|
|
120
|
-
lines = _get_lines(lines_raw, viewport, offset=offset)
|
|
121
|
-
# Find the vertical center of the snippet
|
|
122
|
-
viewport_center = next(
|
|
123
|
-
(index for index, (line_no, _) in enumerate(lines) if line_no == viewport.line),
|
|
124
|
-
0,
|
|
125
|
-
)
|
|
126
|
-
|
|
127
|
-
# Find the horizontal left of the snippet
|
|
128
|
-
# We'll place the center at 25% from the left border
|
|
129
|
-
viewport_left: int = (
|
|
130
|
-
max(viewport.column - viewport.columns_per_line // 4, 0)
|
|
131
|
-
if viewport.column is not None
|
|
132
|
-
else 0
|
|
133
|
-
)
|
|
134
|
-
|
|
135
|
-
if lines:
|
|
136
|
-
# How many chars do we need to write the line number
|
|
137
|
-
loc_width: int = len(str(lines[-1][0]))
|
|
138
|
-
modify_lines(lines, viewport, viewport_left, loc_width)
|
|
139
|
-
if viewport.line_context == -1:
|
|
140
|
-
offset = 0
|
|
141
|
-
elif viewport_center - viewport.line_context <= 0:
|
|
142
|
-
offset = 0
|
|
143
|
-
lines = lines[
|
|
144
|
-
slice(
|
|
145
|
-
0,
|
|
146
|
-
2 * viewport.line_context + 1,
|
|
147
|
-
)
|
|
148
|
-
]
|
|
149
|
-
else:
|
|
150
|
-
offset = (
|
|
151
|
-
max(viewport_center - viewport.line_context, 0)
|
|
152
|
-
if (viewport_center + viewport.line_context < len(lines))
|
|
153
|
-
else max(len(lines) - 2 * viewport.line_context - 1, 0)
|
|
154
|
-
)
|
|
155
|
-
lines = lines[
|
|
156
|
-
slice(
|
|
157
|
-
max(viewport_center - viewport.line_context, 0),
|
|
158
|
-
viewport_center + viewport.line_context + 1,
|
|
159
|
-
)
|
|
160
|
-
if (viewport_center + viewport.line_context < len(lines))
|
|
161
|
-
else slice(
|
|
162
|
-
max(len(lines) - 2 * viewport.line_context - 1, 0),
|
|
163
|
-
len(lines),
|
|
164
|
-
)
|
|
165
|
-
]
|
|
166
|
-
|
|
167
|
-
# Highlight the column if requested
|
|
168
|
-
|
|
169
|
-
if _must_highlight_line_number(viewport):
|
|
170
|
-
lines.append((0, f" {' ':>{loc_width}} ^ Col {viewport_left}"))
|
|
171
|
-
|
|
172
|
-
if viewport:
|
|
173
|
-
return Snippet(
|
|
174
|
-
content="\n".join(map(itemgetter(1), lines)),
|
|
175
|
-
offset=offset,
|
|
176
|
-
line=viewport.line,
|
|
177
|
-
column=viewport.column,
|
|
178
|
-
columns_per_line=viewport.columns_per_line,
|
|
179
|
-
line_context=viewport.line_context,
|
|
180
|
-
highlight_line_number=viewport.highlight_line_number,
|
|
181
|
-
show_line_numbers=viewport.show_line_numbers,
|
|
182
|
-
wrap=viewport.wrap,
|
|
183
|
-
start_point=None,
|
|
184
|
-
)
|
|
114
|
+
if viewport is None:
|
|
115
|
+
rendered = make_snippet(content, None, offset)
|
|
116
|
+
return Snippet(content=rendered.content, offset=rendered.offset)
|
|
185
117
|
|
|
118
|
+
rendered = make_snippet(content, CoreSnippetViewport(**viewport._asdict()), offset)
|
|
186
119
|
return Snippet(
|
|
187
|
-
content=
|
|
188
|
-
offset=offset,
|
|
120
|
+
content=rendered.content,
|
|
121
|
+
offset=rendered.offset,
|
|
122
|
+
line=viewport.line,
|
|
123
|
+
column=viewport.column,
|
|
124
|
+
columns_per_line=viewport.columns_per_line,
|
|
125
|
+
line_context=viewport.line_context,
|
|
126
|
+
highlight_line_number=viewport.highlight_line_number,
|
|
127
|
+
show_line_numbers=viewport.show_line_numbers,
|
|
128
|
+
wrap=viewport.wrap,
|
|
189
129
|
)
|
|
190
130
|
|
|
191
131
|
|
|
192
|
-
def modify_lines(
|
|
193
|
-
lines: list[tuple[int, str]],
|
|
194
|
-
viewport: SnippetViewport,
|
|
195
|
-
viewport_left: int,
|
|
196
|
-
loc_width: int,
|
|
197
|
-
) -> None:
|
|
198
|
-
if not lines:
|
|
199
|
-
return
|
|
200
|
-
|
|
201
|
-
line_no_last: int | None = lines[-2][0] if len(lines) >= 2 else None
|
|
202
|
-
|
|
203
|
-
for index, (line_no, line) in enumerate(lines):
|
|
204
|
-
mark_symbol = _get_mark_symbol(line_no, line_no_last, viewport._replace())
|
|
205
|
-
line_no_str = "" if line_no == line_no_last else str(line_no)
|
|
206
|
-
line_no_last = line_no
|
|
207
|
-
|
|
208
|
-
# Apply horizontal viewport slicing
|
|
209
|
-
n_line = line[viewport_left : viewport_left + viewport.columns_per_line + 1]
|
|
210
|
-
line_prefix = f"{mark_symbol} {line_no_str:>{loc_width}} | "
|
|
211
|
-
|
|
212
|
-
lines[index] = (
|
|
213
|
-
line_no,
|
|
214
|
-
_format_line(n_line, line_prefix, viewport, lines[index][1]),
|
|
215
|
-
)
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
def _format_line(
|
|
219
|
-
line: str,
|
|
220
|
-
line_prefix: str,
|
|
221
|
-
viewport: SnippetViewport,
|
|
222
|
-
original_line: str,
|
|
223
|
-
) -> str:
|
|
224
|
-
if not viewport.show_line_numbers:
|
|
225
|
-
if original_line.startswith(line_prefix.rstrip()):
|
|
226
|
-
line = line.replace(line_prefix, "").replace(line_prefix.rstrip(), "")
|
|
227
|
-
return line
|
|
228
|
-
|
|
229
|
-
if not line.startswith(line_prefix) and viewport.highlight_line_number:
|
|
230
|
-
return f"{line_prefix}{line}".rstrip(" ")
|
|
231
|
-
|
|
232
|
-
if original_line.startswith(line_prefix[0]):
|
|
233
|
-
line = line.replace(line_prefix, "")
|
|
234
|
-
return line
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
def _get_mark_symbol(
|
|
238
|
-
line_no: int,
|
|
239
|
-
line_no_last: int | None,
|
|
240
|
-
viewport: SnippetViewport,
|
|
241
|
-
) -> str:
|
|
242
|
-
if line_no == viewport.line and line_no != line_no_last:
|
|
243
|
-
return ">"
|
|
244
|
-
return " "
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
def _must_highlight_line_number(viewport: SnippetViewport) -> bool:
|
|
248
|
-
return bool(
|
|
249
|
-
viewport.column is not None
|
|
250
|
-
and viewport.highlight_line_number
|
|
251
|
-
and viewport.show_line_numbers,
|
|
252
|
-
)
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
def _get_lines(
|
|
256
|
-
lines_raw: list[str],
|
|
257
|
-
viewport: SnippetViewport,
|
|
258
|
-
offset: int | None = None,
|
|
259
|
-
) -> list[tuple[int, str]]:
|
|
260
|
-
offset = offset or 0
|
|
261
|
-
if viewport is not None and viewport.wrap:
|
|
262
|
-
return [
|
|
263
|
-
(line_no + offset, "".join(line_chunk))
|
|
264
|
-
for line_no, line in enumerate(lines_raw, start=1)
|
|
265
|
-
for line_chunk in _chunked(line, viewport.columns_per_line)
|
|
266
|
-
]
|
|
267
|
-
|
|
268
|
-
return [(line_no + offset, line) for line_no, line in enumerate(lines_raw, start=1)]
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
def _chunked(line: str, chunk_size: int) -> Iterator[str]:
|
|
272
|
-
if line:
|
|
273
|
-
yield from chunked(list(line), n=chunk_size) # type: ignore # noqa: PGH003
|
|
274
|
-
else:
|
|
275
|
-
yield ""
|
|
276
|
-
|
|
277
|
-
|
|
278
132
|
def _elixir_function_identifier(arguments: Node) -> Node | None:
|
|
279
133
|
head = arguments.named_child(0)
|
|
280
134
|
while head is not None:
|
{fluidattacks_core_serializers-12.1.0 → fluidattacks_core_serializers-12.2.0}/pyproject.toml
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "fluidattacks_core_serializers"
|
|
3
|
-
version = "12.
|
|
3
|
+
version = "12.2.0"
|
|
4
4
|
description = "Fluid Attacks Core Serializers Library"
|
|
5
5
|
authors = [{ name = "Development", email = "development@fluidattacks.com" }]
|
|
6
6
|
license = { text = "MPL-2.0" }
|
|
@@ -14,6 +14,7 @@ classifiers = [
|
|
|
14
14
|
]
|
|
15
15
|
requires-python = ">=3.11"
|
|
16
16
|
dependencies = [
|
|
17
|
+
"fluidattacks-core-snippets>=0.1.0",
|
|
17
18
|
"more-itertools>=10.0.0",
|
|
18
19
|
"tree-sitter-c-sharp>=0.23.1",
|
|
19
20
|
"tree-sitter-dart-orchard>=0.3.2",
|
|
@@ -63,8 +64,8 @@ DEP002 = [
|
|
|
63
64
|
"tree-sitter-yaml",
|
|
64
65
|
]
|
|
65
66
|
|
|
66
|
-
[tool.uv]
|
|
67
|
-
|
|
67
|
+
[tool.uv.sources]
|
|
68
|
+
fluidattacks-core-snippets = { index = "internal" }
|
|
68
69
|
|
|
69
70
|
[build-system]
|
|
70
71
|
requires = ["hatchling"]
|
|
@@ -72,3 +73,16 @@ build-backend = "hatchling.build"
|
|
|
72
73
|
|
|
73
74
|
[tool.hatch.build.targets.wheel]
|
|
74
75
|
packages = ["fluidattacks_core"]
|
|
76
|
+
|
|
77
|
+
# mirror's cooldown holds back fresh releases; uv's exclude-newer cannot
|
|
78
|
+
# work there, since Cloudsmith's index has no upload times
|
|
79
|
+
[[tool.uv.index]]
|
|
80
|
+
name = "mirror"
|
|
81
|
+
url = "https://token@dl.cloudsmith.io/basic/fluidattacks/mirror/python/simple/"
|
|
82
|
+
default = true
|
|
83
|
+
|
|
84
|
+
# ours, released from trunk; explicit, so nothing else resolves from it
|
|
85
|
+
[[tool.uv.index]]
|
|
86
|
+
name = "internal"
|
|
87
|
+
url = "https://token@dl.cloudsmith.io/basic/fluidattacks/internal/python/simple/"
|
|
88
|
+
explicit = true
|
|
@@ -22,170 +22,6 @@ def _dedent(content: str) -> str:
|
|
|
22
22
|
return textwrap.dedent(content)[1:-1]
|
|
23
23
|
|
|
24
24
|
|
|
25
|
-
@pytest.mark.parametrize(
|
|
26
|
-
"content, viewport, expected", # noqa: PT006
|
|
27
|
-
[
|
|
28
|
-
(
|
|
29
|
-
"""
|
|
30
|
-
aaaaaaaaaabbbbbbbbbbcccccccccc
|
|
31
|
-
ddddddddddeeeeeeeeeeffffffffff
|
|
32
|
-
gggggggggghhhhhhhhhhiiiiiiiiii
|
|
33
|
-
jjjjjjjjjjkkkkkkkkkkllllllllll
|
|
34
|
-
""",
|
|
35
|
-
None,
|
|
36
|
-
"""
|
|
37
|
-
aaaaaaaaaabbbbbbbbbbcccccccccc
|
|
38
|
-
ddddddddddeeeeeeeeeeffffffffff
|
|
39
|
-
gggggggggghhhhhhhhhhiiiiiiiiii
|
|
40
|
-
jjjjjjjjjjkkkkkkkkkkllllllllll
|
|
41
|
-
""",
|
|
42
|
-
),
|
|
43
|
-
(
|
|
44
|
-
"""
|
|
45
|
-
aaaaaaaaaabbbbbbbbbbcccccccccc
|
|
46
|
-
ddddddddddeeeeeeeeeeffffffffff
|
|
47
|
-
gggggggggghhhhhhhhhhiiiiiiiiii
|
|
48
|
-
jjjjjjjjjjkkkkkkkkkkllllllllll
|
|
49
|
-
""",
|
|
50
|
-
SnippetViewport(
|
|
51
|
-
columns_per_line=20,
|
|
52
|
-
column=10,
|
|
53
|
-
line=2,
|
|
54
|
-
line_context=1,
|
|
55
|
-
wrap=True,
|
|
56
|
-
),
|
|
57
|
-
"""
|
|
58
|
-
| ccccc
|
|
59
|
-
> 2 | dddddeeeeeeeeee
|
|
60
|
-
| fffff
|
|
61
|
-
^ Col 5
|
|
62
|
-
""",
|
|
63
|
-
),
|
|
64
|
-
(
|
|
65
|
-
"""
|
|
66
|
-
1 center
|
|
67
|
-
2
|
|
68
|
-
3
|
|
69
|
-
4
|
|
70
|
-
5
|
|
71
|
-
6
|
|
72
|
-
""",
|
|
73
|
-
SnippetViewport(column=10, line=1, line_context=2),
|
|
74
|
-
"""
|
|
75
|
-
> 1 | 1 center
|
|
76
|
-
2 | 2
|
|
77
|
-
3 | 3
|
|
78
|
-
4 | 4
|
|
79
|
-
5 | 5
|
|
80
|
-
^ Col 0
|
|
81
|
-
""",
|
|
82
|
-
),
|
|
83
|
-
(
|
|
84
|
-
"""
|
|
85
|
-
1
|
|
86
|
-
2 center
|
|
87
|
-
3
|
|
88
|
-
4
|
|
89
|
-
5
|
|
90
|
-
6
|
|
91
|
-
""",
|
|
92
|
-
SnippetViewport(column=10, line=2, line_context=2),
|
|
93
|
-
"""
|
|
94
|
-
1 | 1
|
|
95
|
-
> 2 | 2 center
|
|
96
|
-
3 | 3
|
|
97
|
-
4 | 4
|
|
98
|
-
5 | 5
|
|
99
|
-
^ Col 0
|
|
100
|
-
""",
|
|
101
|
-
),
|
|
102
|
-
(
|
|
103
|
-
"""
|
|
104
|
-
1
|
|
105
|
-
2
|
|
106
|
-
3 center
|
|
107
|
-
4
|
|
108
|
-
5
|
|
109
|
-
6
|
|
110
|
-
""",
|
|
111
|
-
SnippetViewport(column=10, line=3, line_context=2),
|
|
112
|
-
"""
|
|
113
|
-
1 | 1
|
|
114
|
-
2 | 2
|
|
115
|
-
> 3 | 3 center
|
|
116
|
-
4 | 4
|
|
117
|
-
5 | 5
|
|
118
|
-
^ Col 0
|
|
119
|
-
""",
|
|
120
|
-
),
|
|
121
|
-
(
|
|
122
|
-
"""
|
|
123
|
-
1
|
|
124
|
-
2
|
|
125
|
-
3
|
|
126
|
-
4 center
|
|
127
|
-
5
|
|
128
|
-
6
|
|
129
|
-
7
|
|
130
|
-
8
|
|
131
|
-
9
|
|
132
|
-
""",
|
|
133
|
-
SnippetViewport(column=10, line=4, line_context=2),
|
|
134
|
-
"""
|
|
135
|
-
2 | 2
|
|
136
|
-
3 | 3
|
|
137
|
-
> 4 | 4 center
|
|
138
|
-
5 | 5
|
|
139
|
-
6 | 6
|
|
140
|
-
^ Col 0
|
|
141
|
-
""",
|
|
142
|
-
),
|
|
143
|
-
(
|
|
144
|
-
"""
|
|
145
|
-
1
|
|
146
|
-
2
|
|
147
|
-
3
|
|
148
|
-
4
|
|
149
|
-
5 center
|
|
150
|
-
6
|
|
151
|
-
""",
|
|
152
|
-
SnippetViewport(column=10, line=5, line_context=2),
|
|
153
|
-
"""
|
|
154
|
-
2 | 2
|
|
155
|
-
3 | 3
|
|
156
|
-
4 | 4
|
|
157
|
-
> 5 | 5 center
|
|
158
|
-
6 | 6
|
|
159
|
-
^ Col 0
|
|
160
|
-
""",
|
|
161
|
-
),
|
|
162
|
-
(
|
|
163
|
-
"""
|
|
164
|
-
1
|
|
165
|
-
2
|
|
166
|
-
3
|
|
167
|
-
4
|
|
168
|
-
5
|
|
169
|
-
6 center
|
|
170
|
-
""",
|
|
171
|
-
SnippetViewport(column=10, line=6, line_context=2),
|
|
172
|
-
"""
|
|
173
|
-
2 | 2
|
|
174
|
-
3 | 3
|
|
175
|
-
4 | 4
|
|
176
|
-
5 | 5
|
|
177
|
-
> 6 | 6 center
|
|
178
|
-
^ Col 0
|
|
179
|
-
""",
|
|
180
|
-
),
|
|
181
|
-
],
|
|
182
|
-
)
|
|
183
|
-
def test__make_snippet(content: str, viewport: str, expected: str) -> None:
|
|
184
|
-
result = _make_snippet(content=_dedent(content), viewport=viewport) # type: ignore[arg-type]
|
|
185
|
-
assert result is not None
|
|
186
|
-
assert result.content == _dedent(expected)
|
|
187
|
-
|
|
188
|
-
|
|
189
25
|
def test_make_snippet_function() -> None:
|
|
190
26
|
item = _dedent("""
|
|
191
27
|
def get_tokens_per_message(message: ConverseMessage) -> int:
|