chiklisp-builder 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.
@@ -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,37 @@
1
+ Metadata-Version: 2.1
2
+ Name: chiklisp_builder
3
+ Version: 0.1.0
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
+
23
+ # Chiklisp Builder
24
+
25
+ Use this wheel in conjunction with `runtime_builder` to manage building of chiklisp at build time or during development.
26
+
27
+ # Use
28
+
29
+ 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.
30
+
31
+ 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.)
32
+
33
+ # FAQ
34
+
35
+ Why isn't this included as part of `runtime_builder`?
36
+
37
+ 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,15 @@
1
+ # Chiklisp Builder
2
+
3
+ Use this wheel in conjunction with `runtime_builder` to manage building of chiklisp at build time or during development.
4
+
5
+ # Use
6
+
7
+ 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.
8
+
9
+ 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.)
10
+
11
+ # FAQ
12
+
13
+ Why isn't this included as part of `runtime_builder`?
14
+
15
+ 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,37 @@
1
+ Metadata-Version: 2.1
2
+ Name: chiklisp-builder
3
+ Version: 0.1.0
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
+
23
+ # Chiklisp Builder
24
+
25
+ Use this wheel in conjunction with `runtime_builder` to manage building of chiklisp at build time or during development.
26
+
27
+ # Use
28
+
29
+ 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.
30
+
31
+ 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.)
32
+
33
+ # FAQ
34
+
35
+ Why isn't this included as part of `runtime_builder`?
36
+
37
+ 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,14 @@
1
+ LICENSE
2
+ README.md
3
+ chiklisp_builder.py
4
+ pyproject.toml
5
+ setup.py
6
+ chiklisp_builder.egg-info/PKG-INFO
7
+ chiklisp_builder.egg-info/SOURCES.txt
8
+ chiklisp_builder.egg-info/dependency_links.txt
9
+ chiklisp_builder.egg-info/requires.txt
10
+ chiklisp_builder.egg-info/top_level.txt
11
+ tests/a.clib
12
+ tests/b.clib
13
+ tests/mod.clsp
14
+ tests/test_chiklisp_build.py
@@ -0,0 +1,2 @@
1
+ klvm_tools_rs
2
+ runtime_builder>=0.1.0
@@ -0,0 +1 @@
1
+ chiklisp_builder
@@ -0,0 +1,59 @@
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
+ return included
20
+
21
+
22
+ def calculate_dependencies(source_path: Path, include_paths: List[Path]) -> List[Path]:
23
+ include_paths = [Path(_) for _ in include_paths]
24
+ dependencies = set()
25
+ to_check = [source_path]
26
+ while len(to_check):
27
+ item = to_check.pop()
28
+ if item in dependencies:
29
+ continue
30
+ dependencies.add(item)
31
+ included_items = find_included_items(item)
32
+ for include_item in included_items:
33
+ for include_path in include_paths:
34
+ p = include_path / include_item
35
+ if p.exists():
36
+ to_check.append(p)
37
+ return dependencies
38
+
39
+
40
+ class ChiklispBuild:
41
+ def __init__(self, include_paths: List[Path] = []):
42
+ self.include_paths = include_paths
43
+ self.include_paths_as_str = [str(_) for _ in include_paths]
44
+
45
+ def __call__(self, target_path: Path):
46
+ source_path = target_path.with_suffix(".clsp")
47
+
48
+ dependencies = calculate_dependencies(source_path, self.include_paths)
49
+ latest_date = max(_.stat().st_mtime for _ in dependencies)
50
+
51
+ if not target_path.exists() or target_path.stat().st_mtime < latest_date:
52
+ # we need to rebuild
53
+ if target_path.exists():
54
+ # `compile_klvm` doesn't always replace existing files as of 0.1.34
55
+ target_path.unlink()
56
+ source_path_str, target_path_str = str(source_path), str(target_path)
57
+ klvm_tools_rs.compile_klvm(
58
+ source_path_str, target_path_str, self.include_paths_as_str
59
+ )
@@ -0,0 +1,12 @@
1
+ [project]
2
+ name = "chiklisp_builder"
3
+ description = "Allow on-demand builds of chiklisp with recursive dependency checking."
4
+ authors = [{name = "Richard Kiss", email = "him@richardkiss.com"}]
5
+ license = {file = "LICENSE"}
6
+ readme = "README.md"
7
+ version = "0.1.0"
8
+ dependencies = ["klvm_tools_rs", "runtime_builder>=0.1.0"]
9
+
10
+ [build-system]
11
+ requires = ["setuptools>=42", "wheel"]
12
+ build-backend = "setuptools.build_meta"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,5 @@
1
+ from setuptools import setup
2
+
3
+ setup(
4
+ py_modules=["chiklisp_builder"],
5
+ )
@@ -0,0 +1,4 @@
1
+ (
2
+ (include "b.clib")
3
+ (defconstant CONST_A 100)
4
+ )
@@ -0,0 +1,3 @@
1
+ (
2
+ (defconstant CONST_B 200)
3
+ )
@@ -0,0 +1,4 @@
1
+ (mod (X)
2
+ (include "a.clib")
3
+ (+ X (+ CONST_A CONST_B))
4
+ )
@@ -0,0 +1,47 @@
1
+ from pathlib import Path
2
+
3
+ import shutil
4
+ import tempfile
5
+
6
+ from chiklisp_builder import ChiklispBuild
7
+
8
+
9
+ def test_chiklisp_build():
10
+ here = Path(__file__).parent
11
+ with tempfile.TemporaryDirectory() as tmpdir:
12
+ tmpdir = Path(tmpdir)
13
+
14
+ # copy files to temporary directory
15
+ shutil.copytree(here, tmpdir, dirs_exist_ok=True)
16
+
17
+ # create builder
18
+ mod_file = tmpdir / "mod.clsp"
19
+ artifact_f = ChiklispBuild(include_paths=[tmpdir])
20
+ target_path = tmpdir / "mod.hex"
21
+
22
+ artifact_f(target_path)
23
+ output = target_path.read_text()
24
+ assert output == "ff10ff02ffff0182012c80\n"
25
+
26
+ # change `b.clib`
27
+ blib = tmpdir / "b.clib"
28
+ blib.write_text("((defconstant CONST_B 400))")
29
+
30
+ artifact_f(target_path)
31
+ output = target_path.read_text()
32
+ assert output == "ff10ff02ffff018201f480\n"
33
+
34
+ # change `b.clib` but rewrite target file so we trick `ChiklispBuild` into not rebuilding
35
+ blib.write_text("((defconstant CONST_B 500))")
36
+ target_path.write_text(output)
37
+
38
+ artifact_f(target_path)
39
+ output = target_path.read_text()
40
+ assert output == "ff10ff02ffff018201f480\n"
41
+
42
+ # touch `b.clib` and try again
43
+ blib.write_text("((defconstant CONST_B 500))")
44
+
45
+ artifact_f(target_path)
46
+ output = target_path.read_text()
47
+ assert output == "ff10ff02ffff0182025880\n"