picobuild 0.0.4__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.
- picobuild-0.0.4/LICENSE +28 -0
- picobuild-0.0.4/PKG-INFO +20 -0
- picobuild-0.0.4/README.md +2 -0
- picobuild-0.0.4/pyproject.toml +28 -0
- picobuild-0.0.4/setup.cfg +4 -0
- picobuild-0.0.4/setup.py +9 -0
- picobuild-0.0.4/src/picobuild/__about__.py +1 -0
- picobuild-0.0.4/src/picobuild/__init__.py +19 -0
- picobuild-0.0.4/src/picobuild/_setuptools.py +9 -0
- picobuild-0.0.4/src/picobuild/cython_utils.py +34 -0
- picobuild-0.0.4/src/picobuild/executable.py +121 -0
- picobuild-0.0.4/src/picobuild.egg-info/PKG-INFO +20 -0
- picobuild-0.0.4/src/picobuild.egg-info/SOURCES.txt +17 -0
- picobuild-0.0.4/src/picobuild.egg-info/dependency_links.txt +1 -0
- picobuild-0.0.4/src/picobuild.egg-info/requires.txt +8 -0
- picobuild-0.0.4/src/picobuild.egg-info/top_level.txt +1 -0
- picobuild-0.0.4/tests/test_cython_utils.py +23 -0
- picobuild-0.0.4/tests/test_picobuild.py +9 -0
- picobuild-0.0.4/tests/test_setuptools.py +10 -0
picobuild-0.0.4/LICENSE
ADDED
|
@@ -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.
|
picobuild-0.0.4/PKG-INFO
ADDED
|
@@ -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,28 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "picobuild"
|
|
7
|
+
description = "Building tools for CPython extensions"
|
|
8
|
+
readme = "README.md"
|
|
9
|
+
license = "BSD-3-Clause"
|
|
10
|
+
license-files = ["LICENSE"]
|
|
11
|
+
authors = [{ name = "ckirua", email = "aquipongoalgo.dsz@gmail.com" }]
|
|
12
|
+
requires-python = ">=3.12"
|
|
13
|
+
dynamic = ["version"]
|
|
14
|
+
dependencies = [
|
|
15
|
+
"setuptools>=80.9.0",
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
[project.optional-dependencies]
|
|
19
|
+
dev = ["black", "build", "flake8", "isort", "mypy"]
|
|
20
|
+
|
|
21
|
+
[tool.setuptools]
|
|
22
|
+
include-package-data = true
|
|
23
|
+
|
|
24
|
+
[tool.setuptools.package-data]
|
|
25
|
+
"picobuild" = ["**/*.pyx", "**/*.pxd", "**/*.pyi", "**/*.pxi", "**/*.h", "**/*.c", "**/*.hpp", "**/*.cpp"]
|
|
26
|
+
|
|
27
|
+
[tool.setuptools.dynamic]
|
|
28
|
+
version = { attr = "picobuild.__about__.__version__" }
|
picobuild-0.0.4/setup.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.0.4"
|
|
@@ -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,17 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
setup.py
|
|
5
|
+
src/picobuild/__about__.py
|
|
6
|
+
src/picobuild/__init__.py
|
|
7
|
+
src/picobuild/_setuptools.py
|
|
8
|
+
src/picobuild/cython_utils.py
|
|
9
|
+
src/picobuild/executable.py
|
|
10
|
+
src/picobuild.egg-info/PKG-INFO
|
|
11
|
+
src/picobuild.egg-info/SOURCES.txt
|
|
12
|
+
src/picobuild.egg-info/dependency_links.txt
|
|
13
|
+
src/picobuild.egg-info/requires.txt
|
|
14
|
+
src/picobuild.egg-info/top_level.txt
|
|
15
|
+
tests/test_cython_utils.py
|
|
16
|
+
tests/test_picobuild.py
|
|
17
|
+
tests/test_setuptools.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
picobuild
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import tempfile
|
|
3
|
+
import unittest
|
|
4
|
+
|
|
5
|
+
from picobuild import get_cython_build_dir, Extension, cythonize
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class TestCythonUtils(unittest.TestCase):
|
|
9
|
+
def test_get_cython_build_dir(self):
|
|
10
|
+
result = get_cython_build_dir()
|
|
11
|
+
self.assertIsInstance(result, str)
|
|
12
|
+
self.assertTrue(result.startswith("build/cython."))
|
|
13
|
+
|
|
14
|
+
def test_cythonize(self):
|
|
15
|
+
with tempfile.TemporaryDirectory() as tmpdir:
|
|
16
|
+
test_pyx = os.path.join(tmpdir, "test.pyx")
|
|
17
|
+
with open(test_pyx, "w") as f:
|
|
18
|
+
f.write("def hello(): pass\n")
|
|
19
|
+
result = cythonize([Extension("test", [test_pyx])])
|
|
20
|
+
self.assertIsInstance(result, list)
|
|
21
|
+
self.assertEqual(len(result), 1)
|
|
22
|
+
self.assertIsInstance(result[0], Extension)
|
|
23
|
+
self.assertEqual(result[0].name, "test")
|