IncludeCPP 3.4.10__py3-none-any.whl → 3.5.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.
includecpp/__init__.py CHANGED
@@ -2,7 +2,7 @@ from .core.cpp_api import CppApi
2
2
  from .core import cssl_bridge as CSSL
3
3
  import warnings
4
4
 
5
- __version__ = "3.4.10"
5
+ __version__ = "3.5.0"
6
6
  __all__ = ["CppApi", "CSSL"]
7
7
 
8
8
  # Module-level cache for C++ modules
includecpp/__init__.pyi CHANGED
@@ -1,8 +1,9 @@
1
1
  """Type stubs for includecpp package - VSCode IntelliSense support."""
2
2
 
3
- from typing import Any, Dict, Optional, List, Literal, overload
3
+ from typing import Any, Dict, Optional, List, Literal, overload, Callable
4
4
  from pathlib import Path
5
5
  from types import ModuleType
6
+ import threading
6
7
 
7
8
  # Import generated module wrappers for VSCode autocomplete
8
9
  # These are created by 'includecpp rebuild' and provide module-specific type hints
@@ -11,8 +12,135 @@ try:
11
12
  except ImportError:
12
13
  pass # Generated during rebuild
13
14
 
14
- # CSSL module - CSO Service Script Language
15
- from .core import cssl_bridge as CSSL
15
+
16
+ # ========== CSSL Module - CSO Service Script Language ==========
17
+ class _CSSLModule:
18
+ """CSSL callable module created via CSSL.module()"""
19
+ def __call__(self, *args: Any) -> Any:
20
+ """Execute the module code with arguments."""
21
+ ...
22
+
23
+ class _CSSLFunctionModule:
24
+ """CSSL function module created via CSSL.makemodule()"""
25
+ def __getattr__(self, name: str) -> Callable[..., Any]:
26
+ """Get a function from the module."""
27
+ ...
28
+
29
+ class _CsslLang:
30
+ """CSSL Language interface."""
31
+
32
+ def exec(self, path_or_code: str, *args: Any) -> Any:
33
+ """Execute CSSL code or file.
34
+
35
+ Args:
36
+ path_or_code: Path to .cssl file or CSSL code string
37
+ *args: Arguments accessible via parameter.get(index)
38
+
39
+ Returns:
40
+ Execution result
41
+ """
42
+ ...
43
+
44
+ def T_exec(
45
+ self,
46
+ path_or_code: str,
47
+ *args: Any,
48
+ callback: Optional[Callable[[Any], None]] = None
49
+ ) -> threading.Thread:
50
+ """Execute CSSL code asynchronously in a thread."""
51
+ ...
52
+
53
+ def wait_all(self, timeout: Optional[float] = None) -> None:
54
+ """Wait for all async executions to complete."""
55
+ ...
56
+
57
+ def get_output(self) -> List[str]:
58
+ """Get output buffer from last execution."""
59
+ ...
60
+
61
+ def clear_output(self) -> None:
62
+ """Clear output buffer."""
63
+ ...
64
+
65
+ def set_global(self, name: str, value: Any) -> None:
66
+ """Set a global variable in CSSL runtime."""
67
+ ...
68
+
69
+ def get_global(self, name: str) -> Any:
70
+ """Get a global variable from CSSL runtime."""
71
+ ...
72
+
73
+ def module(self, code: str) -> _CSSLModule:
74
+ """Create a callable CSSL module from code."""
75
+ ...
76
+
77
+ def makemodule(self, code: str) -> _CSSLFunctionModule:
78
+ """Create a CSSL module with accessible functions."""
79
+ ...
80
+
81
+
82
+ class _CSSLBridge:
83
+ """CSSL Bridge module - access to CSSL language from Python."""
84
+
85
+ CsslLang: type[_CsslLang]
86
+
87
+ def exec(self, path_or_code: str, *args: Any) -> Any:
88
+ """Execute CSSL code or file."""
89
+ ...
90
+
91
+ def _exec(self, code: str, *args: Any) -> Any:
92
+ """Execute CSSL code (alias for exec)."""
93
+ ...
94
+
95
+ def T_exec(
96
+ self,
97
+ path_or_code: str,
98
+ *args: Any,
99
+ callback: Optional[Callable[[Any], None]] = None
100
+ ) -> threading.Thread:
101
+ """Execute CSSL code asynchronously."""
102
+ ...
103
+
104
+ def _T_exec(
105
+ self,
106
+ code: str,
107
+ *args: Any,
108
+ callback: Optional[Callable[[Any], None]] = None
109
+ ) -> threading.Thread:
110
+ """Execute CSSL code asynchronously (alias)."""
111
+ ...
112
+
113
+ def set_global(self, name: str, value: Any) -> None:
114
+ """Set a global variable."""
115
+ ...
116
+
117
+ def get_global(self, name: str) -> Any:
118
+ """Get a global variable."""
119
+ ...
120
+
121
+ def get_output(self) -> List[str]:
122
+ """Get output buffer."""
123
+ ...
124
+
125
+ def clear_output(self) -> None:
126
+ """Clear output buffer."""
127
+ ...
128
+
129
+ def module(self, code: str) -> _CSSLModule:
130
+ """Create a callable CSSL module."""
131
+ ...
132
+
133
+ def makemodule(self, code: str) -> _CSSLFunctionModule:
134
+ """Create a CSSL function module."""
135
+ ...
136
+
137
+ def get_cssl(self) -> _CsslLang:
138
+ """Get default CSSL instance."""
139
+ ...
140
+
141
+
142
+ # CSSL module instance - CSO Service Script Language
143
+ CSSL: _CSSLBridge
16
144
 
17
145
  __version__: str
18
146
 
@@ -7139,20 +7139,21 @@ def cppy_types():
7139
7139
  # EXEC - Interactive Code Execution
7140
7140
  # ============================================================================
7141
7141
 
7142
- @cli.command()
7143
- @click.argument('lang', type=click.Choice(['py', 'cpp', 'python', 'c++']))
7142
+ @cli.command(name='exec')
7143
+ @click.argument('lang', type=click.Choice(['py', 'cpp', 'python', 'c++', 'cssl']))
7144
7144
  @click.argument('path', required=False, type=click.Path())
7145
7145
  @click.option('--all', 'import_all', is_flag=True, help='Import all available modules')
7146
- def exec(lang, path, import_all):
7146
+ def exec_repl(lang, path, import_all):
7147
7147
  """Execute code interactively for quick testing.
7148
7148
 
7149
- Run Python or C++ code snippets without creating files.
7149
+ Run Python, C++ or CSSL code snippets without creating files.
7150
7150
  Perfect for testing your IncludeCPP modules quickly.
7151
7151
 
7152
7152
  \b
7153
7153
  Usage:
7154
7154
  includecpp exec py # Interactive Python
7155
7155
  includecpp exec cpp # Interactive C++
7156
+ includecpp exec cssl # Interactive CSSL
7156
7157
  includecpp exec py mymodule # Auto-import mymodule
7157
7158
  includecpp exec py plugins/x.cp # Auto-import from plugin
7158
7159
  includecpp exec py --all # Import all modules
@@ -7178,7 +7179,8 @@ def exec(lang, path, import_all):
7178
7179
 
7179
7180
  # Normalize language
7180
7181
  is_python = lang in ('py', 'python')
7181
- lang_name = 'Python' if is_python else 'C++'
7182
+ is_cssl = lang == 'cssl'
7183
+ lang_name = 'Python' if is_python else ('CSSL' if is_cssl else 'C++')
7182
7184
 
7183
7185
  # Build imports/includes
7184
7186
  imports = []
@@ -7286,6 +7288,7 @@ def exec(lang, path, import_all):
7286
7288
 
7287
7289
  if is_python:
7288
7290
  # Execute Python code
7291
+ import builtins
7289
7292
  full_code = '\n'.join(code_lines)
7290
7293
  try:
7291
7294
  # Use exec with captured output
@@ -7299,7 +7302,7 @@ def exec(lang, path, import_all):
7299
7302
  exec_globals = {'__name__': '__main__'}
7300
7303
 
7301
7304
  with redirect_stdout(stdout_capture), redirect_stderr(stderr_capture):
7302
- exec(full_code, exec_globals)
7305
+ builtins.exec(full_code, exec_globals)
7303
7306
 
7304
7307
  stdout_val = stdout_capture.getvalue()
7305
7308
  stderr_val = stderr_capture.getvalue()
@@ -7315,6 +7318,29 @@ def exec(lang, path, import_all):
7315
7318
  except Exception as e:
7316
7319
  click.secho(f"Error: {e}", fg='red')
7317
7320
 
7321
+ elif is_cssl:
7322
+ # Execute CSSL code
7323
+ full_code = '\n'.join(lines)
7324
+ try:
7325
+ from ..core.cssl_bridge import CsslLang
7326
+ cssl_lang = CsslLang()
7327
+ result = cssl_lang.exec(full_code)
7328
+
7329
+ # Print any output from the execution
7330
+ output = cssl_lang.get_output()
7331
+ if output:
7332
+ for line in output:
7333
+ click.echo(line)
7334
+
7335
+ if result is not None:
7336
+ click.echo(result)
7337
+
7338
+ if not output and result is None:
7339
+ click.secho("(no output)", fg='bright_black')
7340
+
7341
+ except Exception as e:
7342
+ click.secho(f"Error: {e}", fg='red')
7343
+
7318
7344
  else:
7319
7345
  # Execute C++ code
7320
7346
  # Build a complete C++ program
@@ -7507,6 +7533,198 @@ def cssl_makemodule(path, output):
7507
7533
  click.echo(f" Type: {module_data['type']}")
7508
7534
 
7509
7535
 
7536
+ @cssl.command(name='doc')
7537
+ def cssl_doc():
7538
+ """Show CSSL documentation."""
7539
+ from pathlib import Path as PathLib
7540
+ import os
7541
+
7542
+ # Find the documentation file in the cssl package directory
7543
+ cssl_dir = PathLib(__file__).parent.parent / 'core' / 'cssl'
7544
+ doc_path = cssl_dir / 'CSSL_DOCUMENTATION.md'
7545
+
7546
+ if not doc_path.exists():
7547
+ # Try alternative locations
7548
+ alt_paths = [
7549
+ PathLib(__file__).parent.parent.parent / 'CSSL_DOCUMENTATION.md',
7550
+ PathLib(__file__).parent.parent / 'CSSL_DOCUMENTATION.md',
7551
+ PathLib(os.getcwd()) / 'CSSL_DOCUMENTATION.md',
7552
+ ]
7553
+ for alt in alt_paths:
7554
+ if alt.exists():
7555
+ doc_path = alt
7556
+ break
7557
+
7558
+ if doc_path.exists():
7559
+ content = doc_path.read_text(encoding='utf-8')
7560
+ # Use pager for long content
7561
+ click.echo_via_pager(content)
7562
+ else:
7563
+ click.secho("Documentation file not found.", fg='yellow')
7564
+ click.echo("Looking for: CSSL_DOCUMENTATION.md")
7565
+ click.echo()
7566
+ click.echo("Quick Reference:")
7567
+ click.echo(" - Variables: string x = \"hello\"; int n = 42;")
7568
+ click.echo(" - Functions: void foo() { } or define bar() { }")
7569
+ click.echo(" - Loops: for (i in range(0, 10)) { } or for (int i = 0; i < 10; i++) { }")
7570
+ click.echo(" - Conditions: if (x) { } elif (y) { } else { }")
7571
+ click.echo(" - Containers: stack<T>, vector<T>, array<T>")
7572
+ click.echo(" - Globals: global x = value; @x")
7573
+ click.echo(" - Payloads: payload(\"file.cssl-pl\");")
7574
+ click.echo()
7575
+ click.echo("For full docs, see: https://github.com/liliassg/IncludeCPP")
7576
+
7577
+
7578
+ @cssl.command(name='create')
7579
+ @click.argument('name')
7580
+ @click.option('--dir', '-d', type=click.Path(), default='.', help='Output directory')
7581
+ def cssl_create(name, dir):
7582
+ """Create a new CSSL project with .cssl and .cssl-pl files."""
7583
+ from pathlib import Path as PathLib
7584
+
7585
+ out_dir = PathLib(dir)
7586
+ out_dir.mkdir(parents=True, exist_ok=True)
7587
+
7588
+ cssl_file = out_dir / f"{name}.cssl"
7589
+ payload_file = out_dir / f"{name}.cssl-pl"
7590
+
7591
+ # Create .cssl file
7592
+ cssl_content = f'''// {name}.cssl - CSSL Application
7593
+ // Created with: includecpp cssl create {name}
7594
+
7595
+ // Load payload (globals, injections, config)
7596
+ payload("{name}.cssl-pl");
7597
+
7598
+ // Main application code
7599
+ void main() {{
7600
+ printl("Hello from {name}!");
7601
+ printl("Version: " + @version);
7602
+ }}
7603
+
7604
+ main();
7605
+ '''
7606
+
7607
+ # Create .cssl-pl payload file
7608
+ payload_content = f'''// {name}.cssl-pl - CSSL Payload
7609
+ // Loaded via: payload("{name}.cssl-pl");
7610
+
7611
+ // ============================================================================
7612
+ // Configuration & Variables
7613
+ // ============================================================================
7614
+ global version = "1.0.0";
7615
+ global appName = "{name}";
7616
+ global debug = false;
7617
+
7618
+ // ============================================================================
7619
+ // Builtin Injections
7620
+ // ============================================================================
7621
+ // Inject cleanup code into exit()
7622
+ exit() <<== {{
7623
+ if (@debug) {{
7624
+ printl("[DEBUG] {name} shutting down...");
7625
+ }}
7626
+ }}
7627
+
7628
+ // ============================================================================
7629
+ // Helper Functions (globally callable via @functionName)
7630
+ // ============================================================================
7631
+ void log(string message) {{
7632
+ if (@debug) {{
7633
+ printl("[LOG] " + message);
7634
+ }}
7635
+ }}
7636
+
7637
+ void error(string message) {{
7638
+ printl("[ERROR] " + message);
7639
+ }}
7640
+ '''
7641
+
7642
+ # Write files
7643
+ cssl_file.write_text(cssl_content, encoding='utf-8')
7644
+ payload_file.write_text(payload_content, encoding='utf-8')
7645
+
7646
+ click.secho(f"Created CSSL project: {name}", fg='green', bold=True)
7647
+ click.echo()
7648
+ click.echo("Files created:")
7649
+ click.echo(f" {cssl_file} - Main application")
7650
+ click.echo(f" {payload_file} - Payload (globals, injections)")
7651
+ click.echo()
7652
+ click.echo("Run with:")
7653
+ click.secho(f" includecpp cssl exec {cssl_file}", fg='cyan')
7654
+ click.echo()
7655
+ click.echo("Or from Python:")
7656
+ click.echo(" from includecpp import CSSL")
7657
+ click.echo(f" CSSL.exec('{cssl_file}')")
7658
+
7659
+
7660
+ @cssl.command(name='vscode')
7661
+ def cssl_vscode():
7662
+ """Install VSCode extension for CSSL syntax highlighting."""
7663
+ from pathlib import Path as PathLib
7664
+ import shutil
7665
+ import os
7666
+
7667
+ # Find VSCode extensions directory
7668
+ if os.name == 'nt': # Windows
7669
+ vscode_ext_dir = PathLib(os.environ.get('USERPROFILE', '')) / '.vscode' / 'extensions'
7670
+ else: # Linux/Mac
7671
+ vscode_ext_dir = PathLib.home() / '.vscode' / 'extensions'
7672
+
7673
+ if not vscode_ext_dir.exists():
7674
+ # Try VSCode Insiders
7675
+ if os.name == 'nt':
7676
+ vscode_ext_dir = PathLib(os.environ.get('USERPROFILE', '')) / '.vscode-insiders' / 'extensions'
7677
+ else:
7678
+ vscode_ext_dir = PathLib.home() / '.vscode-insiders' / 'extensions'
7679
+
7680
+ if not vscode_ext_dir.exists():
7681
+ click.secho("VSCode extensions directory not found.", fg='red')
7682
+ click.echo("Make sure VSCode is installed.")
7683
+ click.echo()
7684
+ click.echo("Expected locations:")
7685
+ if os.name == 'nt':
7686
+ click.echo(f" %USERPROFILE%\\.vscode\\extensions")
7687
+ else:
7688
+ click.echo(f" ~/.vscode/extensions")
7689
+ return
7690
+
7691
+ # Find our bundled extension
7692
+ package_dir = PathLib(__file__).parent.parent
7693
+ source_ext_dir = package_dir / 'vscode' / 'cssl'
7694
+
7695
+ if not source_ext_dir.exists():
7696
+ click.secho("CSSL extension files not found in package.", fg='red')
7697
+ return
7698
+
7699
+ # Install extension
7700
+ target_dir = vscode_ext_dir / 'includecpp.cssl-1.0.0'
7701
+
7702
+ try:
7703
+ if target_dir.exists():
7704
+ shutil.rmtree(target_dir)
7705
+
7706
+ shutil.copytree(source_ext_dir, target_dir)
7707
+
7708
+ click.secho("CSSL VSCode extension installed!", fg='green', bold=True)
7709
+ click.echo()
7710
+ click.echo(f"Installed to: {target_dir}")
7711
+ click.echo()
7712
+ click.echo("Features:")
7713
+ click.echo(" - Syntax highlighting for .cssl, .cssl-pl, .cssl-mod files")
7714
+ click.echo(" - BruteInjection operators: <==, ==>, <<==, +<==, etc.")
7715
+ click.echo(" - Type highlighting: int, string, stack<T>, datastruct<T>")
7716
+ click.echo(" - Global references: @Name, r@Name, s@Name")
7717
+ click.echo(" - Shared objects: $Name")
7718
+ click.echo(" - Filter helpers: string::contains, json::key, etc.")
7719
+ click.echo()
7720
+ click.secho("Restart VSCode to activate the extension.", fg='yellow')
7721
+
7722
+ except PermissionError:
7723
+ click.secho("Permission denied. Try running as administrator.", fg='red')
7724
+ except Exception as e:
7725
+ click.secho(f"Installation failed: {e}", fg='red')
7726
+
7727
+
7510
7728
  # Register hidden cssl command group
7511
7729
  cli.add_command(cssl)
7512
7730