pyact-cli 0.7.0__tar.gz → 0.7.2__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: 0.7.0
3
+ Version: 0.7.2
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
@@ -21,6 +21,16 @@ def equation(func: Callable, values: List[Any]) -> str:
21
21
  value = func(*values)
22
22
  name, sep, tail = source.rpartition("=")
23
23
  head, sep, equ = tail.rpartition(":")
24
+
25
+ name = name.strip()
26
+ if "_" in name:
27
+ parts = name.split("_", 1)
28
+ name = f"{parts[0]}_{{{parts[1]}}}"
29
+
30
+ import re
31
+ 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])'
32
+ name = re.sub(greek_pattern, r'\\\1', name)
33
+
24
34
  return f"$$ {name} = {py2tex(equ.replace(chr(10), ''))} = {value} $$"
25
35
 
26
36
  def image(link: str, caption: str) -> str:
@@ -2,6 +2,7 @@ import re
2
2
  import json
3
3
  import time
4
4
  import os
5
+ import linecache
5
6
 
6
7
  build_logs = []
7
8
 
@@ -74,14 +75,23 @@ def get_imports(file: str, code_text: str):
74
75
  Outputs:
75
76
  dict: The dictionary of variables returned by the user's `context()` function.
76
77
  """
77
- file_namespace = {"__file__": f"{file}.pamd"}
78
+ filename = f"{file}.pamd"
79
+ file_namespace = {"__file__": filename}
78
80
  if not code_text.strip():
79
- raise ValueError(f"The file {file}.pamd needs a 'context()' function but has no code cell.")
81
+ raise ValueError(f"The file {filename} needs a 'context()' function but has no code cell.")
80
82
 
81
83
  try:
82
- exec(code_text, file_namespace)
84
+ # Mock linecache so inspect.getsource works on dynamically executed code
85
+ linecache.cache[filename] = (
86
+ len(code_text),
87
+ None,
88
+ [line + '\n' for line in code_text.splitlines()],
89
+ filename
90
+ )
91
+ compiled_code = compile(code_text, filename, "exec")
92
+ exec(compiled_code, file_namespace)
83
93
  except Exception as e:
84
- raise RuntimeError(f"Error executing code in {file}.pamd: {e}")
94
+ raise RuntimeError(f"Error executing code in {filename}: {e}")
85
95
 
86
96
  if "context" not in file_namespace:
87
97
  raise ValueError(f"The file {file}.pamd is missing the required 'context()' function.")
@@ -111,7 +121,8 @@ def get_globals(directory: str):
111
121
 
112
122
  file_namespace = {"__file__": global_path}
113
123
  try:
114
- exec(code_text, file_namespace)
124
+ compiled_code = compile(code_text, global_path, "exec")
125
+ exec(compiled_code, file_namespace)
115
126
  except Exception as e:
116
127
  raise RuntimeError(f"Error executing global.py: {e}")
117
128
 
@@ -86,7 +86,7 @@ def markdown_parser(md_text: str) -> list:
86
86
  blocks.append(('list', m.group(1), 'ordered'))
87
87
 
88
88
  # Math Block Parsing
89
- elif line_s.startswith('$$') and line_s.endswith('$$'):
89
+ elif (line_s.startswith('$$') and line_s.endswith('$$')) or (line_s.startswith('$') and line_s.endswith('$') and len(line_s) >= 2):
90
90
  blocks.append(('math', line_s.strip('$').strip()))
91
91
 
92
92
  # Standard Paragraph
@@ -312,15 +312,17 @@ def _add_image(paragraph, url, caption, styles):
312
312
  def _process_inline(paragraph, text, styles, tag):
313
313
  """Parses text for images, links, math, and bold/italic."""
314
314
  # Simple regex to split by math, image, or link. Captures the match as a group.
315
- # Group 5: Footnote definition [^1]: ...
316
- # Group 6: Footnote annotation [^1]
317
- pattern = r'(\$\$.*?\$\$)|(!\[.*?\]\(.*?\))|(\[.*?\]\(.*?\))|(<span.*?>.*?</span>)|(\[\^.*?\]:.*?$)|(\[\^.*?\])'
315
+ # Group 1: Double $$ math
316
+ # Group 2: Single $ math
317
+ # Group 6: Footnote definition [^1]: ...
318
+ # Group 7: Footnote annotation [^1]
319
+ pattern = r'(\$\$.*?\$\$)|(\$.*?\$)|(!\[.*?\]\(.*?\))|(\[.*?\]\(.*?\))|(<span.*?>.*?</span>)|(\[\^.*?\]:.*?$)|(\[\^.*?\])'
318
320
  parts = re.split(pattern, text)
319
321
 
320
322
  for part in parts:
321
323
  if not part: continue
322
324
 
323
- if part.startswith('$$') and part.endswith('$$'):
325
+ if (part.startswith('$$') and part.endswith('$$')) or (part.startswith('$') and part.endswith('$') and len(part) >= 2):
324
326
  math_text = part.strip('$').strip()
325
327
  try:
326
328
  math2docx.add_math(paragraph, math_text)
@@ -17,7 +17,24 @@ class LatexVisitor(ast.NodeVisitor):
17
17
  return 1000
18
18
 
19
19
  def visit_Name(self, n):
20
- return n.id
20
+ name = n.id
21
+ if "_" in name:
22
+ parts = name.split('_', 1)
23
+ name = f"{parts[0]}_{{{parts[1]}}}"
24
+
25
+ greek_letters = [
26
+ 'alpha', 'beta', 'gamma', 'delta', 'epsilon', 'zeta', 'eta', 'theta', 'iota',
27
+ 'kappa', 'lambda', 'mu', 'nu', 'xi', 'omicron', 'pi', 'rho', 'sigma', 'tau',
28
+ 'upsilon', 'phi', 'chi', 'psi', 'omega',
29
+ 'Alpha', 'Beta', 'Gamma', 'Delta', 'Epsilon', 'Zeta', 'Eta', 'Theta', 'Iota',
30
+ 'Kappa', 'Lambda', 'Mu', 'Nu', 'Xi', 'Omicron', 'Pi', 'Rho', 'Sigma', 'Tau',
31
+ 'Upsilon', 'Phi', 'Chi', 'Psi', 'Omega'
32
+ ]
33
+ import re
34
+ greek_pattern = r'(?<![a-zA-Z])(' + '|'.join(greek_letters) + r')(?![a-zA-Z])'
35
+ name = re.sub(greek_pattern, r'\\\1', name)
36
+
37
+ return name
21
38
 
22
39
  def prec_Name(self, n):
23
40
  return 1000
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyact-cli
3
- Version: 0.7.0
3
+ Version: 0.7.2
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="0.7.0",
8
+ version="0.7.2",
9
9
  author="Abstergo2003",
10
10
  author_email="",
11
11
  description="A CLI tool to compile .pamd files to Markdown.",
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes