chiklisp-builder 0.1.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.
@@ -0,0 +1,13 @@
1
+ Copyright 2023 by Richard Kiss
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
@@ -0,0 +1,39 @@
1
+ Metadata-Version: 2.1
2
+ Name: chiklisp-builder
3
+ Version: 0.1.2
4
+ Summary: Allow on-demand builds of chiklisp with recursive dependency checking.
5
+ Author-email: Richard Kiss <him@richardkiss.com>
6
+ License: Copyright 2023 by Richard Kiss
7
+
8
+ Licensed under the Apache License, Version 2.0 (the "License");
9
+ you may not use this file except in compliance with the License.
10
+ You may obtain a copy of the License at
11
+
12
+ http://www.apache.org/licenses/LICENSE-2.0
13
+
14
+ Unless required by applicable law or agreed to in writing, software
15
+ distributed under the License is distributed on an "AS IS" BASIS,
16
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ See the License for the specific language governing permissions and
18
+ limitations under the License.
19
+
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: klvm-tools-rs
23
+ Requires-Dist: runtime-builder >=0.1.3
24
+
25
+ # Chiklisp Builder
26
+
27
+ Use this wheel in conjunction with `runtime_builder` to manage building of chiklisp at build time or during development.
28
+
29
+ # Use
30
+
31
+ Add `chiklisp_builder` as a buildtime dependency and a development-time dependency. Don't add it as a runtime dependency, as the klvm `.hex` files should be built and included with the wheel. The source does not need to be.
32
+
33
+ Add `chiklisp_loader` as a runtime dependency to get the `load_program` function, which will call the building function if present (as it should be at development time.)
34
+
35
+ # FAQ
36
+
37
+ Why isn't this included as part of `runtime_builder`?
38
+
39
+ The `runtime_builder` wheel is intended to provide a general solution for non-python artifacts. Although Chiklisp build was the inspiration for `runtime_builder`, it's just one potential use. This wheel is the specific implementation of chiklisp builds for use with `runtime_builder`.
@@ -0,0 +1,6 @@
1
+ chiklisp_builder.py,sha256=EHk5la-dbzg-q0Y7x8VYW1fRbcz7ccFs7JKJz8SI0wg,2082
2
+ chiklisp_builder-0.1.2.dist-info/LICENSE,sha256=00kOn1m1EWQNdeglrohVzVOfeB8_J9QzNWLnwDlwbTY,569
3
+ chiklisp_builder-0.1.2.dist-info/METADATA,sha256=0xppbe_LRo5ZVsILQ8XUBqPTkhu8XsRE2XXf9nBUbus,1921
4
+ chiklisp_builder-0.1.2.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
5
+ chiklisp_builder-0.1.2.dist-info/top_level.txt,sha256=g-Fv6ObJdN6ZWyaMagbdvAjC4XG8mgQNNu-I3MqXMCg,17
6
+ chiklisp_builder-0.1.2.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: bdist_wheel (0.43.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ chiklisp_builder
chiklisp_builder.py ADDED
@@ -0,0 +1,61 @@
1
+ from pathlib import Path
2
+ from typing import List
3
+
4
+ import re
5
+
6
+ import klvm_tools_rs
7
+
8
+ CRE = re.compile(r"\((\s)*include(\s)+(.+)\)")
9
+
10
+
11
+ def find_included_items(item: Path) -> List[Path]:
12
+ contents = item.read_text()
13
+ matches = CRE.findall(contents)
14
+ included = []
15
+ for match in matches:
16
+ s = match[-1]
17
+ if len(s) > 1 and s[0] == s[-1] and s[0] in "'\"":
18
+ included.append(s[1:-1])
19
+ else:
20
+ included.append(s)
21
+ return included
22
+
23
+
24
+ def calculate_dependencies(source_path: Path, include_paths: List[Path]) -> List[Path]:
25
+ include_paths = [Path(_) for _ in include_paths]
26
+ dependencies = set()
27
+ to_check = [source_path]
28
+ while len(to_check):
29
+ item = to_check.pop()
30
+ if item in dependencies:
31
+ continue
32
+ dependencies.add(item)
33
+ included_items = find_included_items(item)
34
+ for include_item in included_items:
35
+ for include_path in include_paths:
36
+ p = include_path / include_item
37
+ if p.exists():
38
+ to_check.append(p)
39
+ return dependencies
40
+
41
+
42
+ class ChiklispBuild:
43
+ def __init__(self, include_paths: List[Path] = []):
44
+ self.include_paths = include_paths
45
+ self.include_paths_as_str = [str(_) for _ in include_paths]
46
+
47
+ def __call__(self, target_path: Path):
48
+ source_path = target_path.with_suffix(".clsp")
49
+
50
+ dependencies = calculate_dependencies(source_path, self.include_paths)
51
+ latest_date = max(_.stat().st_mtime for _ in dependencies)
52
+
53
+ if not target_path.exists() or target_path.stat().st_mtime < latest_date:
54
+ # we need to rebuild
55
+ if target_path.exists():
56
+ # `compile_klvm` doesn't always replace existing files as of 0.1.34
57
+ target_path.unlink()
58
+ source_path_str, target_path_str = str(source_path), str(target_path)
59
+ klvm_tools_rs.compile_klvm(
60
+ source_path_str, target_path_str, self.include_paths_as_str
61
+ )