picobuild 0.0.4__py313-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.
picobuild/__about__.py ADDED
@@ -0,0 +1 @@
1
+ __version__ = "0.0.4"
picobuild/__init__.py ADDED
@@ -0,0 +1,19 @@
1
+ from .__about__ import __version__
2
+ from ._setuptools import Extension, find_packages, setup
3
+ from .cython_utils import cythonize, get_cython_build_dir
4
+ from .executable import ExecutableParameters, build_cython_executable
5
+
6
+ __all__: tuple[str, ...] = (
7
+ # About
8
+ "__version__",
9
+ # CythonUtils
10
+ "get_cython_build_dir",
11
+ "cythonize",
12
+ # Setuptools
13
+ "Extension",
14
+ "find_packages",
15
+ "setup",
16
+ # Executable
17
+ "build_cython_executable",
18
+ "ExecutableParameters",
19
+ )
@@ -0,0 +1,9 @@
1
+ from typing import Any, Callable, TypeAlias
2
+
3
+ from setuptools import Extension as _Extension
4
+ from setuptools import find_packages as _find_packages
5
+ from setuptools import setup as _setup
6
+
7
+ Extension: TypeAlias = _Extension
8
+ find_packages: Callable[..., list[str]] = _find_packages
9
+ setup: Callable[..., Any] = _setup
@@ -0,0 +1,34 @@
1
+ import platform
2
+ import sys
3
+
4
+ from Cython.Build import cythonize as _cythonize
5
+ from setuptools import Extension
6
+
7
+
8
+ def get_cython_build_dir(build_dir: str = "build"):
9
+ """
10
+ Get the build directory for the given build directory.
11
+ Args:
12
+ build_dir: The build directory.
13
+ Returns:
14
+ The build directory.
15
+ # Example: build/cython.linux-x86_64-cpython-313
16
+ """
17
+ plat = platform.system().lower()
18
+ machine = platform.machine().lower()
19
+ py_version = f"{sys.version_info.major}{sys.version_info.minor}"
20
+ impl = platform.python_implementation().lower()
21
+ return f"{build_dir}/cython.{plat}-{machine}-{impl}-{py_version}"
22
+
23
+
24
+ def cythonize(*args, **kwargs) -> list[Extension]:
25
+ """
26
+ Cythonize the given extensions.
27
+ Args:
28
+ *args: The extensions to cythonize.
29
+ **kwargs: The keyword arguments to pass to the cythonize function.
30
+ Returns:
31
+ The list of cythonized extensions.
32
+ """
33
+ build_dir: str = kwargs.pop("build_dir", "build")
34
+ return _cythonize(*args, **kwargs, build_dir=get_cython_build_dir(build_dir))
@@ -0,0 +1,121 @@
1
+ import subprocess
2
+ import sysconfig
3
+ from typing import Optional
4
+
5
+ from Cython.Compiler import Options as CythonOptions
6
+ from Cython.Compiler.Main import compile as cython_compile
7
+ from Cython.Compiler.Options import CompilationOptions
8
+
9
+ # pylint: disable=pointless-string-statement
10
+ """
11
+ # TODO
12
+ *Cython*
13
+ This is embedded, doesnt require env activation to be run.
14
+ TODO:
15
+ - cythonize is better option i think
16
+ - maebe a class CythonExecutable with methods:
17
+ - build
18
+ - compile
19
+ - add moar args
20
+
21
+ *C*
22
+ Issa not embedded, activate env to run.
23
+ TODO:
24
+ - c file generator
25
+ - compile (think is same as cython)
26
+
27
+ *Impl*
28
+ - shall i clean cy/c files after executable is done? idkidk
29
+ """
30
+
31
+
32
+ class ExecutableParameters:
33
+ """
34
+ Parameters for building a standalone executable from a Python source file.
35
+
36
+ Args:
37
+ source_file: Python source file (e.g., "hello.py")
38
+ build_dir: Output directory for the executable (e.g., "bin")
39
+ executable_name: Name of the executable (e.g., "hello")
40
+ """
41
+
42
+ def __init__(
43
+ self, source_file: str, build_dir: str, executable_name: Optional[str] = None
44
+ ):
45
+ """
46
+ Initialize the ExecutableParameters.
47
+
48
+ Args:
49
+ source_file: Python source file (e.g., "hello.py")
50
+ build_dir: Output directory for the executable (e.g., "bin")
51
+ executable_name: Name of the executable (e.g., "hello")
52
+ """
53
+ self._build_dir = build_dir
54
+
55
+ self._source_file = source_file
56
+ self._executable_name = executable_name or source_file.split("/")[
57
+ -1
58
+ ].removesuffix(".py")
59
+ self._executable_file = f"{self._build_dir}/{self._executable_name}"
60
+ self._c_file = f"{self._build_dir}/{self._executable_name}.c"
61
+
62
+ def as_tuple(self):
63
+ """
64
+ Return the source file and executable name as a tuple.
65
+ """
66
+ return (self._source_file, self._executable_file)
67
+
68
+
69
+ def _cythonize_executable(source_file: str, dest_file: str = None):
70
+ """
71
+ Cythonize the source_file to a C file suitable for embedding in a standalone executable.
72
+ Equivalent to: cython --embed hello.py -o bin/hello_cy.c
73
+ """
74
+ # This is equivalent to --embed
75
+ CythonOptions.embed = "main"
76
+
77
+ options = CompilationOptions()
78
+ if dest_file:
79
+ options.output_file = dest_file
80
+
81
+ cython_compile(source_file, options)
82
+
83
+
84
+ def _build_cython_executable(c_file: str, dest_file: str):
85
+ """
86
+ Compile the C file to an executable using gcc.
87
+ Equivalent to: gcc bin/hello_cy.c -o bin/hello_cy \
88
+ $(python -c "import sysconfig as s; print(f'-I{s.get_path(\"include\")} -L{s.get_config_var(\"LIBDIR\")} -lpython{s.get_config_var(\"VERSION\")}')")
89
+ """
90
+ include_dir = sysconfig.get_path("include")
91
+ lib_dir = sysconfig.get_config_var("LIBDIR")
92
+ python_version = sysconfig.get_config_var("VERSION")
93
+
94
+ cmd = [
95
+ "gcc",
96
+ c_file,
97
+ "-o",
98
+ dest_file,
99
+ f"-I{include_dir}",
100
+ f"-L{lib_dir}",
101
+ f"-lpython{python_version}",
102
+ ]
103
+
104
+ subprocess.run(cmd, check=True)
105
+
106
+
107
+ def build_cython_executable(source_file: str, dest_file: str = None):
108
+ """
109
+ Build a standalone executable from a Python source file.
110
+
111
+ Args:
112
+ source_file: Python source file (e.g., "hello.py")
113
+ dest_file: Output executable path (e.g., "hello"). If None, derived from source_file.
114
+ """
115
+ if dest_file is None:
116
+ dest_file = source_file.removesuffix(".py")
117
+
118
+ c_file = f"{dest_file}.c"
119
+
120
+ _cythonize_executable(source_file, c_file)
121
+ _build_cython_executable(c_file, dest_file)
@@ -0,0 +1,20 @@
1
+ Metadata-Version: 2.4
2
+ Name: picobuild
3
+ Version: 0.0.4
4
+ Summary: Building tools for CPython extensions
5
+ Author-email: ckirua <aquipongoalgo.dsz@gmail.com>
6
+ License-Expression: BSD-3-Clause
7
+ Requires-Python: >=3.12
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ Requires-Dist: setuptools>=80.9.0
11
+ Provides-Extra: dev
12
+ Requires-Dist: black; extra == "dev"
13
+ Requires-Dist: build; extra == "dev"
14
+ Requires-Dist: flake8; extra == "dev"
15
+ Requires-Dist: isort; extra == "dev"
16
+ Requires-Dist: mypy; extra == "dev"
17
+ Dynamic: license-file
18
+
19
+ # picobuild
20
+ CPython building tools
@@ -0,0 +1,10 @@
1
+ picobuild/__about__.py,sha256=1mptEzQihbdyqqzMgdns_j5ZGK9gz7hR2bsgA_TnjO4,22
2
+ picobuild/__init__.py,sha256=ler7AILWx0Y4Lsp8KkjBVGs-Em8-OsoH2vIVoB_uhSo,490
3
+ picobuild/_setuptools.py,sha256=ZYMNjPArHNgEUbCPVgWgQvZ3NjtrlIh474AUNEO0zRk,313
4
+ picobuild/cython_utils.py,sha256=b5639Q8oOQnIQuMHZcVadcRSU6qiio8c6dq0WvWBUs4,1079
5
+ picobuild/executable.py,sha256=G2YLtTZlshSc4PMgtjm3zT9Dt4fpsubGU1JY7fDQLsw,3606
6
+ picobuild-0.0.4.dist-info/licenses/LICENSE,sha256=Gco-IPwzTMCrnepWMoAaFPEli4JMiJs0GWz_PN2H6ss,1493
7
+ picobuild-0.0.4.dist-info/METADATA,sha256=cmJtwL4z_hAVZYQt-7FvaIYI6_NER1F7-9eGX03FcPU,567
8
+ picobuild-0.0.4.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
9
+ picobuild-0.0.4.dist-info/top_level.txt,sha256=MTdsM-BZRhOrXapaSjQB9TRgly0bk5XT2v88zJ8Sjt0,10
10
+ picobuild-0.0.4.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.10.2)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,28 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2025, ckirua
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1 @@
1
+ picobuild