bakery-build 0.1.0__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.
- bakery_build-0.1.0/PKG-INFO +20 -0
- bakery_build-0.1.0/README.md +7 -0
- bakery_build-0.1.0/bake/__init__.py +1 -0
- bakery_build-0.1.0/bake/bake_cli.py +17 -0
- bakery_build-0.1.0/bake/core.py +136 -0
- bakery_build-0.1.0/bakery_build.egg-info/PKG-INFO +20 -0
- bakery_build-0.1.0/bakery_build.egg-info/SOURCES.txt +11 -0
- bakery_build-0.1.0/bakery_build.egg-info/dependency_links.txt +1 -0
- bakery_build-0.1.0/bakery_build.egg-info/entry_points.txt +2 -0
- bakery_build-0.1.0/bakery_build.egg-info/top_level.txt +1 -0
- bakery_build-0.1.0/pyproject.toml +20 -0
- bakery_build-0.1.0/setup.cfg +4 -0
- bakery_build-0.1.0/setup.py +22 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: bakery-build
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: a simple build automation library and CLI tool
|
|
5
|
+
Author: Bradley Hutchings
|
|
6
|
+
Author-email: Bradley Hutchings <bkhnapa@gmail.com>
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: Development Status :: 2 - Pre-Alpha
|
|
9
|
+
Requires-Python: >=3.10
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
Dynamic: author
|
|
12
|
+
Dynamic: requires-python
|
|
13
|
+
|
|
14
|
+
# bake (cli tool)
|
|
15
|
+
|
|
16
|
+
`bake` is a cli build tool to replace most simple use cases of GNU
|
|
17
|
+
`make`. It was not build with things like cache, speed, etc in mind. It was
|
|
18
|
+
created to simplify `Makefile` systems with a lot of `bash` conditional
|
|
19
|
+
statements. Most of the complex functions of a `Makefile` are deferred to the
|
|
20
|
+
shell, therefore it should be capable of the same things `make` can do.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# bake (cli tool)
|
|
2
|
+
|
|
3
|
+
`bake` is a cli build tool to replace most simple use cases of GNU
|
|
4
|
+
`make`. It was not build with things like cache, speed, etc in mind. It was
|
|
5
|
+
created to simplify `Makefile` systems with a lot of `bash` conditional
|
|
6
|
+
statements. Most of the complex functions of a `Makefile` are deferred to the
|
|
7
|
+
shell, therefore it should be capable of the same things `make` can do.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .core import Bakery
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import sys
|
|
3
|
+
import runpy
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def main():
|
|
7
|
+
make_file = "Bakery.py"
|
|
8
|
+
if os.path.exists(make_file):
|
|
9
|
+
sys.argv = [make_file] + sys.argv[1:]
|
|
10
|
+
runpy.run_path(make_file, run_name="__main__")
|
|
11
|
+
else:
|
|
12
|
+
print(f"Error: Could not find '{make_file}' in the current directory.")
|
|
13
|
+
exit(1)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
if __name__ == "__main__":
|
|
17
|
+
main()
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
from typing import Callable, Dict
|
|
2
|
+
from inspect import signature
|
|
3
|
+
from sys import argv, stderr, stdout
|
|
4
|
+
from subprocess import CalledProcessError, Popen
|
|
5
|
+
from select import select
|
|
6
|
+
from pty import openpty
|
|
7
|
+
from os import close, read
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class Bakery:
|
|
11
|
+
class Target:
|
|
12
|
+
def __init__(self, func: Callable[[], bool]):
|
|
13
|
+
self.func = func
|
|
14
|
+
self.docs = (func.__doc__ or "no documentation").strip()
|
|
15
|
+
|
|
16
|
+
def __repr__(self):
|
|
17
|
+
return f"Target({self.func}/{self.docs})"
|
|
18
|
+
|
|
19
|
+
builtin_functions = [
|
|
20
|
+
"help",
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
def __init__(self):
|
|
24
|
+
self.targets: Dict[str, Bakery.Target] = {}
|
|
25
|
+
self.__default: str = "help"
|
|
26
|
+
|
|
27
|
+
def help() -> bool:
|
|
28
|
+
"""autogenerated help command"""
|
|
29
|
+
print(f"usage: bake (target [optional])")
|
|
30
|
+
print("targets:")
|
|
31
|
+
|
|
32
|
+
longest_name = len(max(self.targets.keys(), key=len))
|
|
33
|
+
for name, target in self.targets.items():
|
|
34
|
+
default = "(default)"
|
|
35
|
+
if name != self.__default:
|
|
36
|
+
default = " " * len(default)
|
|
37
|
+
print(default, name.ljust(longest_name), "-", target.docs)
|
|
38
|
+
|
|
39
|
+
return True
|
|
40
|
+
|
|
41
|
+
self.targets.setdefault("help", Bakery.Target(help))
|
|
42
|
+
|
|
43
|
+
def target(self, f: Callable[[], bool]):
|
|
44
|
+
f_signat = signature(f)
|
|
45
|
+
|
|
46
|
+
# ensure correct number of parameters
|
|
47
|
+
f_params = f_signat.parameters
|
|
48
|
+
assert len(f_params) == 0, "targets cannot have arguments"
|
|
49
|
+
|
|
50
|
+
# ensure correct return type
|
|
51
|
+
f_return = f_signat.return_annotation
|
|
52
|
+
assert f_return is bool, "targets must return bool"
|
|
53
|
+
|
|
54
|
+
# ensure target name is not builtin function
|
|
55
|
+
assert (
|
|
56
|
+
f.__name__ not in Bakery.builtin_functions
|
|
57
|
+
), f"target name: {f.__name__} is taken by a built in function"
|
|
58
|
+
|
|
59
|
+
# set target and set default if not set
|
|
60
|
+
self.targets.setdefault(f.__name__, Bakery.Target(f))
|
|
61
|
+
if not self.__default:
|
|
62
|
+
self.__default = f.__name__
|
|
63
|
+
|
|
64
|
+
def default(self, name):
|
|
65
|
+
assert name in self.targets.keys(), "default target must be a valid target"
|
|
66
|
+
self.__default = name
|
|
67
|
+
|
|
68
|
+
def run(self, name):
|
|
69
|
+
target = self.targets.get(name, None)
|
|
70
|
+
assert target, f"invalid target name: {name}"
|
|
71
|
+
if not target.func():
|
|
72
|
+
print(f"target: {target.func.__name__} failed")
|
|
73
|
+
exit(1)
|
|
74
|
+
|
|
75
|
+
def _run_and_print(self, command: str, check: bool) -> str:
|
|
76
|
+
print(f"$ {command}", file=stderr)
|
|
77
|
+
|
|
78
|
+
parent_fd, child_fd = openpty()
|
|
79
|
+
p = Popen(
|
|
80
|
+
command,
|
|
81
|
+
shell=True,
|
|
82
|
+
stdin=child_fd,
|
|
83
|
+
stdout=child_fd,
|
|
84
|
+
stderr=child_fd,
|
|
85
|
+
close_fds=True,
|
|
86
|
+
)
|
|
87
|
+
close(child_fd)
|
|
88
|
+
|
|
89
|
+
buffer = bytearray()
|
|
90
|
+
try:
|
|
91
|
+
while True:
|
|
92
|
+
r, _, _ = select([parent_fd], [], [])
|
|
93
|
+
if parent_fd in r:
|
|
94
|
+
data = read(parent_fd, 1024)
|
|
95
|
+
if not data:
|
|
96
|
+
break
|
|
97
|
+
buffer.extend(data)
|
|
98
|
+
stdout.buffer.write(data)
|
|
99
|
+
stdout.buffer.flush()
|
|
100
|
+
finally:
|
|
101
|
+
close(parent_fd)
|
|
102
|
+
|
|
103
|
+
ret = p.wait()
|
|
104
|
+
if check and ret != 0:
|
|
105
|
+
raise CalledProcessError(ret, command)
|
|
106
|
+
return buffer.decode("utf-8", errors="replace").rstrip()
|
|
107
|
+
|
|
108
|
+
def shell_pass(self, command: str) -> str:
|
|
109
|
+
try:
|
|
110
|
+
return self._run_and_print(command, check=False)
|
|
111
|
+
except CalledProcessError:
|
|
112
|
+
return ""
|
|
113
|
+
|
|
114
|
+
def shell(self, command: str) -> str:
|
|
115
|
+
return self._run_and_print(command, check=False)
|
|
116
|
+
|
|
117
|
+
def shell_strict(self, command: str) -> str:
|
|
118
|
+
try:
|
|
119
|
+
return self._run_and_print(command, check=True)
|
|
120
|
+
except CalledProcessError as ex:
|
|
121
|
+
exit(ex.returncode)
|
|
122
|
+
|
|
123
|
+
def compile(self):
|
|
124
|
+
match len(argv) - 1:
|
|
125
|
+
case 0: # run the default target
|
|
126
|
+
self.run(self.__default)
|
|
127
|
+
case 1: # run the user defined target
|
|
128
|
+
self.run(argv[1])
|
|
129
|
+
case _:
|
|
130
|
+
print(f"usage: {argv[0]} [target]")
|
|
131
|
+
print("targets:")
|
|
132
|
+
print(self.targets)
|
|
133
|
+
exit(1)
|
|
134
|
+
|
|
135
|
+
def __repr__(self):
|
|
136
|
+
return str(self.targets)
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: bakery-build
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: a simple build automation library and CLI tool
|
|
5
|
+
Author: Bradley Hutchings
|
|
6
|
+
Author-email: Bradley Hutchings <bkhnapa@gmail.com>
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: Development Status :: 2 - Pre-Alpha
|
|
9
|
+
Requires-Python: >=3.10
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
Dynamic: author
|
|
12
|
+
Dynamic: requires-python
|
|
13
|
+
|
|
14
|
+
# bake (cli tool)
|
|
15
|
+
|
|
16
|
+
`bake` is a cli build tool to replace most simple use cases of GNU
|
|
17
|
+
`make`. It was not build with things like cache, speed, etc in mind. It was
|
|
18
|
+
created to simplify `Makefile` systems with a lot of `bash` conditional
|
|
19
|
+
statements. Most of the complex functions of a `Makefile` are deferred to the
|
|
20
|
+
shell, therefore it should be capable of the same things `make` can do.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
setup.py
|
|
4
|
+
bake/__init__.py
|
|
5
|
+
bake/bake_cli.py
|
|
6
|
+
bake/core.py
|
|
7
|
+
bakery_build.egg-info/PKG-INFO
|
|
8
|
+
bakery_build.egg-info/SOURCES.txt
|
|
9
|
+
bakery_build.egg-info/dependency_links.txt
|
|
10
|
+
bakery_build.egg-info/entry_points.txt
|
|
11
|
+
bakery_build.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
bake
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=79.0.1", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "bakery-build"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "a simple build automation library and CLI tool"
|
|
9
|
+
authors = [
|
|
10
|
+
{ name="Bradley Hutchings", email="bkhnapa@gmail.com" }
|
|
11
|
+
]
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
requires-python = ">=3.10"
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"Development Status :: 2 - Pre-Alpha",
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
[project.scripts]
|
|
20
|
+
bake = "bake.bake_cli:main"
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
|
|
3
|
+
setup(
|
|
4
|
+
name="bakery-build",
|
|
5
|
+
version="0.1.0",
|
|
6
|
+
author="Bradley Hutchings",
|
|
7
|
+
author_email="bkhnapa@gmail.com",
|
|
8
|
+
description="a simple build automation library and CLI tool",
|
|
9
|
+
long_description=open("README.md").read(),
|
|
10
|
+
long_description_content_type="text/markdown",
|
|
11
|
+
packages=find_packages(where="."),
|
|
12
|
+
python_requires=">=3.10",
|
|
13
|
+
classifiers=[
|
|
14
|
+
"Programming Language :: Python :: 3",
|
|
15
|
+
"Development Status :: 2 - Pre-Alpha",
|
|
16
|
+
],
|
|
17
|
+
entry_points={
|
|
18
|
+
"console_scripts": [
|
|
19
|
+
"bake=bake.bake_cli:main",
|
|
20
|
+
],
|
|
21
|
+
},
|
|
22
|
+
)
|