pyact-cli 1.0.0__tar.gz → 1.1.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyact-cli
3
- Version: 1.0.0
3
+ Version: 1.1.0
4
4
  Summary: A CLI tool to compile .pamd files to Markdown.
5
5
  Home-page: https://github.com/Abstergo2003/PyAct
6
6
  Author: Abstergo2003
@@ -1,5 +1,6 @@
1
1
  import inspect
2
2
  from typing import Callable, List, Any
3
+ from enum import Enum
3
4
  from pyact.py2tex import py2tex
4
5
 
5
6
  def equation(func: Callable, values: List[Any]) -> str:
@@ -17,10 +18,13 @@ def equation(func: Callable, values: List[Any]) -> str:
17
18
  Outputs:
18
19
  str: A Markdown math string formatted as `$$ Name = Equation = Value $$`.
19
20
  """
21
+ print("Function 'equation()' is deprecated and will be removed, please use Calculation() class.")
20
22
  source = inspect.getsource(func)
21
23
  value = func(*values)
22
24
  name, sep, tail = source.rpartition("=")
25
+ print(name, tail)
23
26
  head, sep, equ = tail.rpartition(":")
27
+ print(head, equ)
24
28
 
25
29
  name = name.strip()
26
30
  if "_" in name:
@@ -139,6 +143,7 @@ def table(headers: List[str], values: List[List[Any]], caption: str, add_no: boo
139
143
  Outputs:
140
144
  str: A formatted Markdown string containing the caption and the table.
141
145
  """
146
+ print("Function 'table()' is deprecated and will be removed, please use Table() class.")
142
147
  if add_no:
143
148
  headers_string = f"|No.|"
144
149
  breaker_line = "|---|"
@@ -192,6 +197,7 @@ def unordered_list(items: List[str]) -> str:
192
197
  Outputs:
193
198
  str: A Markdown string where each item is prefixed with `* `.
194
199
  """
200
+ print("Function 'unordered_list()' is deprecated and will be removed, please use CList() class.")
195
201
  list_string = ""
196
202
  for i in items:
197
203
  list_string += f"* {i}\n"
@@ -210,6 +216,7 @@ def ordered_list(items: List[str]) -> str:
210
216
  Outputs:
211
217
  str: A Markdown string where each item is numbered sequentially (1. 2. 3.).
212
218
  """
219
+ print("Function 'ordered_list()' is deprecated and will be removed, please use CList() class.")
213
220
  list_string = ""
214
221
  for i, item in enumerate(items):
215
222
  list_string += f"{i+1}. {item}\n"
@@ -228,6 +235,7 @@ def checklist(items: List[str]) -> str:
228
235
  Outputs:
229
236
  str: A Markdown string where each item is prefixed with `- [ ] `.
230
237
  """
238
+ print("Function 'checklist()' is deprecated and will be removed, please use CList() class.")
231
239
  list_string = ""
232
240
  for i in items:
233
241
  list_string += f"- [ ] {i}\n"
@@ -282,6 +290,7 @@ def table_to_dxf(headers: List[str], values: List[List[Any]], filename: str, cel
282
290
  Outputs:
283
291
  str: A string confirming the export, formatted as a Markdown link.
284
292
  """
293
+ print("Function 'table_to_dfx()' is deprecated and will be removed, please use Table() class.")
285
294
  try:
286
295
  import ezdxf
287
296
  except ImportError:
@@ -319,4 +328,207 @@ def table_to_dxf(headers: List[str], values: List[List[Any]], filename: str, cel
319
328
  ).set_placement((x, y), align=ezdxf.enums.TextEntityAlignment.MIDDLE_CENTER)
320
329
 
321
330
  doc.saveas(filename)
322
- return f"*[Successfully exported table to {filename}]({filename})*"
331
+ return f"*[Successfully exported table to {filename}]({filename})*"
332
+
333
+ class Calculation:
334
+ def __init__(self, func: Callable, values: List[float|int], repl: bool = False, precision: int = 3):
335
+ self.func = func
336
+ self.values = values
337
+ self.replace = repl
338
+ self.precision = precision
339
+ self.value = round(func(*values), self.precision)
340
+ self.name = None
341
+ self.vars = None
342
+ self.repr = self.get_representation()
343
+
344
+ def __repr__(self):
345
+ return self.repr
346
+
347
+ def recalculate(self, values, precision: int = None):
348
+ if precision is None:
349
+ return Calculation(self.func, values, self.replace, self.precision)
350
+ else:
351
+ return Calculation(self.func, values, self.replace, precision)
352
+
353
+ def get_representation(self):
354
+ source = inspect.getsource(self.func)
355
+
356
+ name, sep, tail = source.rpartition("=")
357
+
358
+ head, sep, equ = tail.rpartition(":")
359
+ self.vars = head.replace("lambda", "").replace(" ", "").split(",")
360
+
361
+ name = name.strip()
362
+ self.name = f"$ {py2tex(name)} $"
363
+ if "_" in name:
364
+ parts = name.split("_", 1)
365
+ name = f"{parts[0]}_{{{parts[1]}}}"
366
+
367
+ import re
368
+ greek_pattern = r'(?<![a-zA-Z])(alpha|beta|gamma|delta|epsilon|zeta|eta|theta|iota|kappa|lambda|mu|nu|xi|omicron|pi|rho|sigma|tau|upsilon|phi|chi|psi|omega|Alpha|Beta|Gamma|Delta|Epsilon|Zeta|Eta|Theta|Iota|Kappa|Lambda|Mu|Nu|Xi|Omicron|Pi|Rho|Sigma|Tau|Upsilon|Phi|Chi|Psi|Omega)(?![a-zA-Z])'
369
+ name = re.sub(greek_pattern, r'\\\1', name)
370
+ texified = py2tex(equ.replace(chr(10), ''))
371
+ replaced = texified
372
+ for i, vr in enumerate(self.vars):
373
+ replaced = replaced.replace(py2tex(vr.replace(",", "")), f"{self.values[i]}")
374
+
375
+ if self.replace:
376
+ return f"$$ {name} = {texified} = {replaced} = {self.value} $$"
377
+ else:
378
+ return f"$$ {name} = {texified} = {self.value} $$"
379
+
380
+ def _extract(self, other) -> float:
381
+ return float(other.value) if isinstance(other, Calculation) else float(other)
382
+
383
+ def __add__(self, other):
384
+ return float(self.value) + self._extract(other)
385
+
386
+ def __radd__(self, other):
387
+ return self._extract(other) + float(self.value)
388
+
389
+ def __sub__(self, other):
390
+ return float(self.value) - self._extract(other)
391
+
392
+ def __rsub__(self, other):
393
+ return self._extract(other) - float(self.value)
394
+
395
+ def __mul__(self, other):
396
+ return float(self.value) * self._extract(other)
397
+
398
+ def __rmul__(self, other):
399
+ return self._extract(other) * float(self.value)
400
+
401
+ def __truediv__(self, other):
402
+ return float(self.value) / self._extract(other)
403
+
404
+ def __rtruediv__(self, other):
405
+ return self._extract(other) / float(self.value)
406
+
407
+ def __pow__(self, power):
408
+ return float(self.value) ** self._extract(power)
409
+
410
+ def __neg__(self):
411
+ return -float(self.value)
412
+
413
+ def __abs__(self):
414
+ return abs(float(self.value))
415
+
416
+ class Table():
417
+ def __init__(self, headers: List[str], values: List[List[Any]], caption: str, add_no: bool = False, starting_number: int = 1):
418
+ self.headers = headers,
419
+ self.values = values
420
+ self.caption = caption
421
+ self.add_no = add_no
422
+ self.starting_number = starting_number
423
+ self.repr = self.get_representation()
424
+
425
+ def __repr__(self):
426
+ return self.repr
427
+
428
+ def get_representation(self):
429
+ if self.add_no:
430
+ headers_string = f"|No.|"
431
+ breaker_line = "|---|"
432
+ else:
433
+ headers_string = f"|"
434
+ breaker_line = "|"
435
+
436
+ for i in self.headers:
437
+ headers_string += f"{i}|"
438
+ breaker_line += "-"*len(i)+"|"
439
+
440
+ table_content = ""
441
+ for i, row in enumerate(self.values):
442
+ if self.add_no:
443
+ table_content += f"|{i+self.starting_number}|"
444
+ else:
445
+ table_content += "|"
446
+ for value in row:
447
+ table_content += f"{value}|"
448
+ table_content += "\n"
449
+
450
+ caption_html = f"<span style='text-align: center; display: block; font-style: italic;'>{self.caption}</span>"
451
+ return f"{caption_html} \n {headers_string}\n{breaker_line}\n{table_content}"
452
+
453
+ def toDXF(self, filename: str, cell_width: float = 50.0, cell_height: float = 10.0):
454
+ try:
455
+ import ezdxf
456
+ except ImportError:
457
+ return f"*(Error: ezdxf library is not installed. Cannot generate {filename})*"
458
+
459
+ doc = ezdxf.new('R2010')
460
+ msp = doc.modelspace()
461
+
462
+ # Construct full grid data
463
+ rows = [self.headers] + self.values
464
+ num_rows = len(rows)
465
+ num_cols = len(self.headers)
466
+
467
+ # Draw horizontal grid lines
468
+ for i in range(num_rows + 1):
469
+ y = -i * cell_height
470
+ msp.add_line((0, y), (num_cols * cell_width, y))
471
+
472
+ # Draw vertical grid lines
473
+ for j in range(num_cols + 1):
474
+ x = j * cell_width
475
+ msp.add_line((x, 0), (x, -num_rows * cell_height))
476
+
477
+ # Draw text centered in each cell
478
+ for i, row in enumerate(rows):
479
+ y = -i * cell_height - (cell_height / 2)
480
+ for j, cell_val in enumerate(row):
481
+ if j >= num_cols: continue # Safety bounds
482
+ x = j * cell_width + (cell_width / 2)
483
+ msp.add_text(
484
+ str(cell_val),
485
+ dxfattribs={
486
+ 'height': cell_height * 0.4,
487
+ }
488
+ ).set_placement((x, y), align=ezdxf.enums.TextEntityAlignment.MIDDLE_CENTER)
489
+
490
+ doc.saveas(filename)
491
+ return f"*[Successfully exported table to {filename}]({filename})*"
492
+
493
+ class ListType(Enum):
494
+ ORDERED = 1
495
+ UNORDERED = 2
496
+ CHECKLIST = 3
497
+
498
+ class CList():
499
+ def __init__(self, items: List[Any], type: ListType):
500
+ self.items = items
501
+ self.type = type
502
+ self.repr = self.get_representation()
503
+
504
+ def __repr__(self):
505
+ return self.repr
506
+
507
+ def get_representation(self):
508
+ if self.type == ListType.ORDERED:
509
+ return self.get_ordered()
510
+ elif self.type == ListType.UNORDERED:
511
+ return self.get_unordered()
512
+ elif self.type == ListType.CHECKLIST:
513
+ return self.get_checklist()
514
+
515
+ def get_ordered(self):
516
+ list_string = ""
517
+ for i, item in enumerate(self.items):
518
+ list_string += f"{i+1}. {item}\n"
519
+ return list_string
520
+ def get_unordered(self):
521
+ list_string = ""
522
+ for i in self.items:
523
+ list_string += f"* {i}\n"
524
+ return list_string
525
+ def get_checklist(self):
526
+ list_string = ""
527
+ for i in self.items:
528
+ list_string += f"- [ ] {i}\n"
529
+ return list_string
530
+
531
+ if __name__ == "__main__":
532
+ func_w = lambda x_1, y, z: x_1+y+z
533
+ func_eq = Calculation(func_w, [1,2,3], True)
534
+ print(func_eq.vars)
@@ -0,0 +1 @@
1
+ __version__ = "1.1.0"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyact-cli
3
- Version: 1.0.0
3
+ Version: 1.1.0
4
4
  Summary: A CLI tool to compile .pamd files to Markdown.
5
5
  Home-page: https://github.com/Abstergo2003/PyAct
6
6
  Author: Abstergo2003
@@ -5,7 +5,7 @@ with open("README.md", "r", encoding="utf-8") as fh:
5
5
 
6
6
  setup(
7
7
  name="pyact-cli",
8
- version="1.0.0",
8
+ version="1.1.0",
9
9
  author="Abstergo2003",
10
10
  author_email="",
11
11
  description="A CLI tool to compile .pamd files to Markdown.",
@@ -1 +0,0 @@
1
- __version__ = "1.0.0"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes