algokit-utils 2.3.3b2__py3-none-any.whl → 2.4.0__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 algokit-utils might be problematic. Click here for more details.

@@ -27,7 +27,7 @@ SOURCES_FILE = "sources.avm.json"
27
27
  TRACES_FILE_EXT = ".trace.avm.json"
28
28
  DEBUG_TRACES_DIR = "debug_traces"
29
29
  TEAL_FILE_EXT = ".teal"
30
- TEAL_SOURCEMAP_EXT = ".teal.tok.map"
30
+ TEAL_SOURCEMAP_EXT = ".teal.map"
31
31
 
32
32
 
33
33
  @dataclass
@@ -107,37 +107,6 @@ def _load_or_create_sources(sources_path: Path) -> AVMDebuggerSourceMap:
107
107
  return AVMDebuggerSourceMap.from_dict(json.load(f))
108
108
 
109
109
 
110
- def _upsert_debug_sourcemaps(sourcemaps: list[AVMDebuggerSourceMapEntry], project_root: Path) -> None:
111
- """
112
- This function updates or inserts debug sourcemaps. If path in the sourcemap during iteration leads to non
113
- existing file, removes it. Otherwise upserts.
114
-
115
- Args:
116
- sourcemaps (list[AVMDebuggerSourceMapEntry]): A list of AVMDebuggerSourceMapEntry objects.
117
- project_root (Path): The root directory of the project.
118
-
119
- Returns:
120
- None
121
- """
122
-
123
- sources_path = project_root / ALGOKIT_DIR / SOURCES_DIR / SOURCES_FILE
124
- sources = _load_or_create_sources(sources_path)
125
-
126
- for sourcemap in sourcemaps:
127
- source_file_path = Path(sourcemap.location)
128
- if not source_file_path.exists() and sourcemap in sources.txn_group_sources:
129
- sources.txn_group_sources.remove(sourcemap)
130
- elif source_file_path.exists():
131
- if sourcemap not in sources.txn_group_sources:
132
- sources.txn_group_sources.append(sourcemap)
133
- else:
134
- index = sources.txn_group_sources.index(sourcemap)
135
- sources.txn_group_sources[index] = sourcemap
136
-
137
- with sources_path.open("w") as f:
138
- json.dump(sources.to_dict(), f)
139
-
140
-
141
110
  def _write_to_file(path: Path, content: str) -> None:
142
111
  path.parent.mkdir(parents=True, exist_ok=True)
143
112
  path.write_text(content)
@@ -174,8 +143,29 @@ def _build_avm_sourcemap( # noqa: PLR0913
174
143
  return AVMDebuggerSourceMapEntry(str(source_map_output_path), program_hash)
175
144
 
176
145
 
146
+ def cleanup_old_trace_files(output_dir: Path, buffer_size_mb: float) -> None:
147
+ """
148
+ Cleanup old trace files if total size exceeds buffer size limit.
149
+
150
+ Args:
151
+ output_dir (Path): Directory containing trace files
152
+ buffer_size_mb (float): Maximum allowed size in megabytes
153
+ """
154
+ total_size = sum(f.stat().st_size for f in output_dir.glob("*") if f.is_file())
155
+ if total_size > buffer_size_mb * 1024 * 1024:
156
+ sorted_files = sorted(output_dir.glob("*"), key=lambda p: p.stat().st_mtime)
157
+ while total_size > buffer_size_mb * 1024 * 1024 and sorted_files:
158
+ oldest_file = sorted_files.pop(0)
159
+ total_size -= oldest_file.stat().st_size
160
+ oldest_file.unlink()
161
+
162
+
177
163
  def persist_sourcemaps(
178
- *, sources: list[PersistSourceMapInput], project_root: Path, client: "AlgodClient", with_sources: bool = True
164
+ *,
165
+ sources: list[PersistSourceMapInput],
166
+ project_root: Path,
167
+ client: "AlgodClient",
168
+ with_sources: bool = True,
179
169
  ) -> None:
180
170
  """
181
171
  Persist the sourcemaps for the given sources as an AlgoKit AVM Debugger compliant artifacts.
@@ -187,7 +177,7 @@ def persist_sourcemaps(
187
177
  Default is True, as needed by an AlgoKit AVM debugger.
188
178
  """
189
179
 
190
- sourcemaps = [
180
+ for source in sources:
191
181
  _build_avm_sourcemap(
192
182
  raw_teal=source.raw_teal,
193
183
  compiled_teal=source.compiled_teal,
@@ -197,10 +187,6 @@ def persist_sourcemaps(
197
187
  client=client,
198
188
  with_sources=with_sources,
199
189
  )
200
- for source in sources
201
- ]
202
-
203
- _upsert_debug_sourcemaps(sourcemaps, project_root)
204
190
 
205
191
 
206
192
  def simulate_response(atc: AtomicTransactionComposer, algod_client: "AlgodClient") -> SimulateAtomicTransactionResponse:
@@ -257,24 +243,20 @@ def simulate_and_persist_response(
257
243
  response = simulate_response(atc_to_simulate, algod_client)
258
244
  txn_results = response.simulate_response["txn-groups"]
259
245
 
260
- txn_types = [txn_result["txn-results"][0]["txn-result"]["txn"]["txn"]["type"] for txn_result in txn_results]
261
- txn_types_count = {txn_type: txn_types.count(txn_type) for txn_type in set(txn_types)}
262
- txn_types_str = "_".join([f"{count}#{txn_type}" for txn_type, count in txn_types_count.items()])
246
+ txn_types = [
247
+ txn["txn-result"]["txn"]["txn"]["type"] for txn_result in txn_results for txn in txn_result["txn-results"]
248
+ ]
249
+ txn_types_count = {}
250
+ for txn_type in txn_types:
251
+ if txn_type not in txn_types_count:
252
+ txn_types_count[txn_type] = txn_types.count(txn_type)
253
+ txn_types_str = "_".join([f"{count}{txn_type}" for txn_type, count in txn_types_count.items()])
263
254
 
264
255
  last_round = response.simulate_response["last-round"]
265
256
  timestamp = datetime.now(tz=timezone.utc).strftime("%Y%m%d_%H%M%S")
266
257
  output_file = project_root / DEBUG_TRACES_DIR / f"{timestamp}_lr{last_round}_{txn_types_str}{TRACES_FILE_EXT}"
267
258
 
268
259
  output_file.parent.mkdir(parents=True, exist_ok=True)
269
-
270
- # cleanup old files if buffer size is exceeded
271
- total_size = sum(f.stat().st_size for f in output_file.parent.glob("*") if f.is_file())
272
- if total_size > buffer_size_mb * 1024 * 1024:
273
- sorted_files = sorted(output_file.parent.glob("*"), key=lambda p: p.stat().st_mtime)
274
- while total_size > buffer_size_mb * 1024 * 1024:
275
- oldest_file = sorted_files.pop(0)
276
- total_size -= oldest_file.stat().st_size
277
- oldest_file.unlink()
278
-
260
+ cleanup_old_trace_files(output_file.parent, buffer_size_mb)
279
261
  output_file.write_text(json.dumps(response.simulate_response, indent=2))
280
262
  return response
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: algokit-utils
3
- Version: 2.3.3b2
3
+ Version: 2.4.0
4
4
  Summary: Utilities for Algorand development for use by AlgoKit
5
5
  License: MIT
6
6
  Author: Algorand Foundation
@@ -1,5 +1,5 @@
1
1
  algokit_utils/__init__.py,sha256=Xc9NVy3cETI2qzbkkAea2YrZ9-CLtZLHnuS1UHQ13wQ,4909
2
- algokit_utils/_debugging.py,sha256=HlO_mOsVTaz2aqci_4tOpGT-rAd-xZ1RxFphnTRgDLQ,10751
2
+ algokit_utils/_debugging.py,sha256=ACNayBEjA5_Y91YAIg-4_h5ld0IyKfW7vqoxo1xcxGE,9873
3
3
  algokit_utils/_ensure_funded.py,sha256=ZdEdUB43QGIQrg7cSSgNrDmWaLSUhli9x9I6juwKfgo,6786
4
4
  algokit_utils/_transfer.py,sha256=R9q8RoMHiwtqcwQjuGHEluMxIzmYqAsI5WrTsQd24Ds,6021
5
5
  algokit_utils/account.py,sha256=JYovI84sxiU2mIbwNwWVuoEJBMuAPJauHx5jkKFrR7E,7067
@@ -18,7 +18,7 @@ algokit_utils/logic_error.py,sha256=I9fJJ09zfpPlKgcJJ7fqC77BBPTz37QsSlGfZwXDdPQ,
18
18
  algokit_utils/models.py,sha256=KMpSUv7XGjZ9_50U6qUjcPjGh9_7lsRj3ZlO9Fb2zyE,8421
19
19
  algokit_utils/network_clients.py,sha256=TlGRZ4l62_vi__AKg9zyVGiAawTrA0ca6AfPDzRL44E,5136
20
20
  algokit_utils/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
21
- algokit_utils-2.3.3b2.dist-info/LICENSE,sha256=J5i7U1Q9Q2c7saUzlvFRmrCCFhQyXb5Juz_LO5omNUw,1076
22
- algokit_utils-2.3.3b2.dist-info/METADATA,sha256=6yh9fbbT3vGZbBQMb8vwWeoKn-XO-3WiFp5AMNrlsTs,2258
23
- algokit_utils-2.3.3b2.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
24
- algokit_utils-2.3.3b2.dist-info/RECORD,,
21
+ algokit_utils-2.4.0.dist-info/LICENSE,sha256=J5i7U1Q9Q2c7saUzlvFRmrCCFhQyXb5Juz_LO5omNUw,1076
22
+ algokit_utils-2.4.0.dist-info/METADATA,sha256=cDRvMEzxKtLUWbnctWZP93OfdMUAwgk-rMlreSPikjI,2256
23
+ algokit_utils-2.4.0.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
24
+ algokit_utils-2.4.0.dist-info/RECORD,,