cexec 1.0.2__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.
cexec/__init__.py ADDED
@@ -0,0 +1,54 @@
1
+ """
2
+ cexec - The C Executor in Python.
3
+
4
+ Using the built-in to source TCC for compile C and Run Compiled Machine Code.
5
+
6
+ Copyright (c) Suleiman 2026
7
+ License: MIT
8
+ """
9
+
10
+ __license__ = "MIT"
11
+ __author__ = "Suleiman"
12
+ __version__ = "1.0.2"
13
+
14
+ import os
15
+ import sys
16
+ import platform
17
+ import tempfile
18
+ import subprocess
19
+
20
+ system = platform.system().lower()
21
+ if "windows" not in system: raise OSError(f"This Python Package only supports on 'windows' OS, not in '{system}'")
22
+
23
+ TCC_EXE = os.path.join(os.path.dirname(__file__), "tcc.exe")
24
+ if not os.path.exists(TCC_EXE):
25
+ TCC_EXE = "tcc.exe"
26
+
27
+ def execute(code, args=None):
28
+ if not code or not isinstance(code, str):
29
+ raise ValueError("Expected a string of C code")
30
+
31
+ if platform.architecture()[0] != "64bit":
32
+ raise RuntimeError("cexec supports only 64-bit systems")
33
+
34
+ with tempfile.TemporaryDirectory() as tmpdir:
35
+ c_file = os.path.join(tmpdir, "main.c")
36
+ exe_file = os.path.join(tmpdir, "main.exe")
37
+
38
+ with open(c_file, "w", encoding="utf-8") as f:
39
+ f.write(code)
40
+
41
+ compile_cmd = [TCC_EXE, c_file, "-o", exe_file]
42
+ try:
43
+ subprocess.run(compile_cmd, capture_output=True, text=True, check=True)
44
+ except subprocess.CalledProcessError as e:
45
+ raise RuntimeError(f"Compilation error:\n{e.stderr}")
46
+ except FileNotFoundError:
47
+ raise RuntimeError(f"TCC not found. Ensure {TCC_EXE} exists.")
48
+
49
+ try:
50
+ run_cmd = [exe_file] + (args or [])
51
+ run_result = subprocess.run(run_cmd, capture_output=True, text=True, check=True)
52
+ return run_result.stdout
53
+ except subprocess.CalledProcessError as e:
54
+ raise RuntimeError(f"Execution error:\n{e.stderr}")
cexec/libtcc.dll ADDED
Binary file
cexec/tcc.exe ADDED
Binary file
@@ -0,0 +1,66 @@
1
+ Metadata-Version: 2.4
2
+ Name: cexec
3
+ Version: 1.0.2
4
+ Summary: The C Executor in Python. Compile and run C code in real-time
5
+ Author: Suleiman
6
+ License: MIT
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: License :: OSI Approved :: MIT License
9
+ Classifier: Operating System :: Microsoft :: Windows
10
+ Classifier: Topic :: Software Development :: Compilers
11
+ Classifier: Intended Audience :: Developers
12
+ Requires-Python: >=3.6
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Dynamic: author
16
+ Dynamic: classifier
17
+ Dynamic: description
18
+ Dynamic: description-content-type
19
+ Dynamic: license
20
+ Dynamic: license-file
21
+ Dynamic: requires-python
22
+ Dynamic: summary
23
+
24
+ '# cexec โ€” The C Executor in Python
25
+
26
+ **cexec** is a lightweight Python library that allows you to **compile and run C code on the fly** directly from Python.
27
+
28
+ ## โœจ Features
29
+
30
+ * **Zero Dependencies**: Uses only the Python standard library.
31
+ * **On-the-fly Execution**: Compile and run C code in a single function call.
32
+ * **Windows Support**: Optimized for 64-bit Windows systems.
33
+
34
+ ## ๐Ÿš€ Quick Start
35
+
36
+ Make sure you have Python 3.6+ installed on **Windows** (this package currently supports only Windows).
37
+
38
+ ```python
39
+ import cexec
40
+
41
+ c_code = """
42
+ #include <stdio.h>
43
+
44
+ int main() {
45
+ printf("Hello from C Executor!\\n");
46
+ return 0;
47
+ }
48
+ """
49
+
50
+ output = cexec.execute(c_code)
51
+ print(output)
52
+ ```
53
+
54
+ โš ๏ธ Important Notes
55
+
56
+ ยท Windows Only: This package uses tcc.exe, which is a Windows binary. It will not work on Linux, macOS, or Android.
57
+
58
+ ๐Ÿ“ฆ Installation
59
+
60
+ ```bash
61
+ pip install cexec
62
+ ```
63
+
64
+ ๐Ÿ“„ License
65
+
66
+ This project is distributed under the MIT License. See the LICENSE file for details.'
@@ -0,0 +1,8 @@
1
+ cexec/__init__.py,sha256=gez8qAUCnz0GwLgv_wjQbFYPS8jvC9Z1_5uIXpDY86E,1735
2
+ cexec/libtcc.dll,sha256=4IVp00uvXFRsmhnF5tC1mT8Zb0Hl6uuxDlTHG1kQkrw,156160
3
+ cexec/tcc.exe,sha256=6cs-ieIKnv6tg8yeaxADFCdWNML3BQVtpx9CTqmwzfA,23552
4
+ cexec-1.0.2.dist-info/licenses/LICENSE,sha256=XABCXMEhX5-sSW6dVui3V35LHqtlwNF4Rj0Rfhuo4_8,1064
5
+ cexec-1.0.2.dist-info/METADATA,sha256=oKg37Kp7_qF8dV4suF52hhEuFGqm9TjgcRYEzaVzcoI,1647
6
+ cexec-1.0.2.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
7
+ cexec-1.0.2.dist-info/top_level.txt,sha256=rxyQ4fZfWN5VsCqtNNwND3fiHYQ6JnfBtw0VcPwRoyg,6
8
+ cexec-1.0.2.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Suleiman
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ cexec