scons-xo-exts-lib 1.4.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.
Files changed (26) hide show
  1. scons_xo_exts_lib-1.4.0/PKG-INFO +39 -0
  2. scons_xo_exts_lib-1.4.0/README.md +25 -0
  3. scons_xo_exts_lib-1.4.0/pyproject.toml +28 -0
  4. scons_xo_exts_lib-1.4.0/src/scons_xo_exts_lib/Actions/Uv.py +58 -0
  5. scons_xo_exts_lib-1.4.0/src/scons_xo_exts_lib/Actions/__init__.py +1 -0
  6. scons_xo_exts_lib-1.4.0/src/scons_xo_exts_lib/BuildSupport/Make.py +18 -0
  7. scons_xo_exts_lib-1.4.0/src/scons_xo_exts_lib/BuildSupport/NodeMangling.py +34 -0
  8. scons_xo_exts_lib-1.4.0/src/scons_xo_exts_lib/BuildSupport/__init__.py +1 -0
  9. scons_xo_exts_lib-1.4.0/src/scons_xo_exts_lib/Builders/__init__.py +1 -0
  10. scons_xo_exts_lib-1.4.0/src/scons_xo_exts_lib/Builders/bazel.py +39 -0
  11. scons_xo_exts_lib-1.4.0/src/scons_xo_exts_lib/Builders/cmake.py +39 -0
  12. scons_xo_exts_lib-1.4.0/src/scons_xo_exts_lib/Builders/dotnet.py +304 -0
  13. scons_xo_exts_lib-1.4.0/src/scons_xo_exts_lib/Builders/dune.py +110 -0
  14. scons_xo_exts_lib-1.4.0/src/scons_xo_exts_lib/Builders/elisp.py +128 -0
  15. scons_xo_exts_lib-1.4.0/src/scons_xo_exts_lib/Builders/elixir.py +67 -0
  16. scons_xo_exts_lib-1.4.0/src/scons_xo_exts_lib/Builders/make.py +39 -0
  17. scons_xo_exts_lib-1.4.0/src/scons_xo_exts_lib/Builders/meson.py +44 -0
  18. scons_xo_exts_lib-1.4.0/src/scons_xo_exts_lib/Builders/ninjabuild.py +48 -0
  19. scons_xo_exts_lib-1.4.0/src/scons_xo_exts_lib/Builders/orgmode.py +109 -0
  20. scons_xo_exts_lib-1.4.0/src/scons_xo_exts_lib/Builders/pandoc.py +42 -0
  21. scons_xo_exts_lib-1.4.0/src/scons_xo_exts_lib/Builders/racket.py +123 -0
  22. scons_xo_exts_lib-1.4.0/src/scons_xo_exts_lib/Builders/tar_image.py +40 -0
  23. scons_xo_exts_lib-1.4.0/src/scons_xo_exts_lib/Find.py +32 -0
  24. scons_xo_exts_lib-1.4.0/src/scons_xo_exts_lib/GenericExtensions.py +38 -0
  25. scons_xo_exts_lib-1.4.0/src/scons_xo_exts_lib/Read.py +53 -0
  26. scons_xo_exts_lib-1.4.0/src/scons_xo_exts_lib/__init__.py +8 -0
@@ -0,0 +1,39 @@
1
+ Metadata-Version: 2.4
2
+ Name: scons-xo-exts-lib
3
+ Version: 1.4.0
4
+ Summary: Scons extensions library by XGQT.
5
+ Author-email: Maciej Barć <xgqt@xgqt.org>
6
+ Requires-Python: >=3.12
7
+ Description-Content-Type: text/markdown
8
+ Classifier: Environment :: Console
9
+ Classifier: Operating System :: POSIX
10
+ Classifier: Programming Language :: Python :: 3 :: Only
11
+ Requires-Dist: scons>=4.8.1
12
+ Project-URL: Home, https://gitlab.com/xgqt/xgqt-python-lib-scons-xo-exts/
13
+
14
+ # SCons X.O Exts
15
+
16
+ SCons extensions
17
+
18
+ ## About
19
+
20
+ Extensions for SCons, includes Python libraries and builders.
21
+
22
+ ## Repository
23
+
24
+ Upstream repository is <https://gitlab.com/xgqt/xgqt-python-lib-scons-xo-exts/>.
25
+
26
+ ## Package
27
+
28
+ Download from PYPI: <https://pypi.org/project/scons-xo-exts-lib/>.
29
+
30
+ ## License
31
+
32
+ ### Code
33
+
34
+ Code in this project is licensed under the MPL, version 2.0.
35
+
36
+ This Source Code Form is subject to the terms of the Mozilla Public
37
+ License, v. 2.0. If a copy of the MPL was not distributed with this
38
+ file, You can obtain one at http://mozilla.org/MPL/2.0/.
39
+
@@ -0,0 +1,25 @@
1
+ # SCons X.O Exts
2
+
3
+ SCons extensions
4
+
5
+ ## About
6
+
7
+ Extensions for SCons, includes Python libraries and builders.
8
+
9
+ ## Repository
10
+
11
+ Upstream repository is <https://gitlab.com/xgqt/xgqt-python-lib-scons-xo-exts/>.
12
+
13
+ ## Package
14
+
15
+ Download from PYPI: <https://pypi.org/project/scons-xo-exts-lib/>.
16
+
17
+ ## License
18
+
19
+ ### Code
20
+
21
+ Code in this project is licensed under the MPL, version 2.0.
22
+
23
+ This Source Code Form is subject to the terms of the Mozilla Public
24
+ License, v. 2.0. If a copy of the MPL was not distributed with this
25
+ file, You can obtain one at http://mozilla.org/MPL/2.0/.
@@ -0,0 +1,28 @@
1
+ [project]
2
+ name = "scons-xo-exts-lib"
3
+ dynamic = [
4
+ "description",
5
+ "version",
6
+ ]
7
+ authors = [
8
+ {name = "Maciej Barć", email = "xgqt@xgqt.org"},
9
+ ]
10
+ readme = "README.md"
11
+ classifiers = [
12
+ "Environment :: Console",
13
+ "Operating System :: POSIX",
14
+ "Programming Language :: Python :: 3 :: Only",
15
+ ]
16
+ requires-python = ">=3.12"
17
+ dependencies = [
18
+ "scons>=4.8.1",
19
+ ]
20
+
21
+ [project.urls]
22
+ Home = "https://gitlab.com/xgqt/xgqt-python-lib-scons-xo-exts/"
23
+
24
+ [build-system]
25
+ build-backend = "flit_core.buildapi"
26
+ requires = [
27
+ "flit_core >=3.2,<4",
28
+ ]
@@ -0,0 +1,58 @@
1
+ #!/usr/bin/env python
2
+
3
+ # This Source Code Form is subject to the terms of the Mozilla Public
4
+ # License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ # file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
+
7
+
8
+ import os
9
+
10
+ from SCons.Script import Environment
11
+
12
+ from ..GenericExtensions import execute_command
13
+
14
+
15
+ def uv_venv_action(target, source, env):
16
+ if os.path.exists(".venv"):
17
+ return
18
+ else:
19
+ execute_command(env, "${UV_EXE} venv")
20
+
21
+
22
+ def uv_sync_action(target, source, env):
23
+ execute_command(env, "${UV_EXE} sync --all-packages")
24
+
25
+
26
+ def uv_pip(env, cmd):
27
+ execute_command(env, "${UV_EXE} pip " + cmd)
28
+
29
+
30
+ def uv_pip_freeze_action(target, source, env):
31
+ output_file = str(target[0])
32
+
33
+ uv_pip(env, f"freeze --exclude-editable > {output_file}")
34
+
35
+
36
+ def uv_build_pkg_action(target, source, env):
37
+ if source and isinstance(source, list):
38
+ pkgs = []
39
+
40
+ for a_source in source:
41
+ a_source_str = str(a_source)
42
+
43
+ if "pyproject.toml" in a_source_str:
44
+ pkg_dir = os.path.dirname(a_source_str)
45
+
46
+ pkgs.append(pkg_dir)
47
+
48
+ for pkg in pkgs:
49
+ if pkg:
50
+ execute_command(env, "${UV_EXE} build " + pkg)
51
+ else:
52
+ execute_command(env, "${UV_EXE} build --all-packages")
53
+
54
+
55
+ def uv_pytest_action(target, source, env):
56
+ pytest_exec_flags = env.get("PYTEST_FLAGS", "--capture=no")
57
+
58
+ execute_command(env, f"${{UV_EXE}} run -- pytest {pytest_exec_flags}")
@@ -0,0 +1 @@
1
+ #!/usr/bin/env python
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env python
2
+
3
+ # This Source Code Form is subject to the terms of the Mozilla Public
4
+ # License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ # file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
+
7
+
8
+ from typing import List
9
+
10
+ from SCons.Script import Environment
11
+
12
+ from .GenericExtensions import execute_command
13
+
14
+
15
+ def execute_make(env: Environment, args: List[str]) -> None:
16
+ make_cmd = "make" + " ".join(args)
17
+
18
+ execute_command(env, make_cmd)
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env python
2
+
3
+ # This Source Code Form is subject to the terms of the Mozilla Public
4
+ # License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ # file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
+
7
+
8
+ import os
9
+ import re
10
+
11
+
12
+ def get_first_node(nodes):
13
+ if isinstance(nodes, list):
14
+ return nodes[0]
15
+
16
+ return nodes
17
+
18
+
19
+ def get_first_directory(nodes):
20
+ node = get_first_node(nodes=nodes)
21
+ path = node.abspath
22
+
23
+ if os.path.isdir(path):
24
+ return path
25
+
26
+ return os.path.dirname(path)
27
+
28
+
29
+ def regex_find_node(regex, nodes):
30
+ for node in nodes:
31
+ if re.match(pattern=regex, string=str(node.abspath)):
32
+ return node
33
+
34
+ raise RuntimeError("No file was matched using the specified regex")
@@ -0,0 +1 @@
1
+ #!/usr/bin/env python
@@ -0,0 +1 @@
1
+ #!/usr/bin/env python
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env python
2
+
3
+ # This Source Code Form is subject to the terms of the Mozilla Public
4
+ # License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ # file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
+
7
+
8
+ import subprocess
9
+
10
+ from SCons.Script import Builder
11
+
12
+
13
+ def bazel_action(target, source, env):
14
+ bazel_pkgs = " ".join(str(s) for s in source)
15
+
16
+ bazel_exe = env.get("BAZEL_EXE", "bazelisk")
17
+ bazel_flags = env.get("BAZEL_FLAGS", "")
18
+
19
+ cmd = f"{bazel_exe} build {bazel_flags} {bazel_pkgs}"
20
+ print(cmd)
21
+
22
+ result = subprocess.run(
23
+ args=cmd,
24
+ capture_output=False,
25
+ check=False,
26
+ shell=True,
27
+ )
28
+
29
+ return result.returncode
30
+
31
+
32
+ def generate(env):
33
+ bazel_binary_builder = Builder(action=bazel_action)
34
+
35
+ env.Append(BUILDERS={"BazelBinary": bazel_binary_builder})
36
+
37
+
38
+ def exists(env):
39
+ return env.Detect("bazel")
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env python
2
+
3
+ # This Source Code Form is subject to the terms of the Mozilla Public
4
+ # License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ # file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
+
7
+
8
+ import subprocess
9
+
10
+ from SCons.Script import Builder
11
+
12
+
13
+ def cmake_action(target, source, env):
14
+ cmake_targets = " ".join(str(t) for t in target)
15
+
16
+ cmake_exe = env.get("CMAKE_EXE", "cmake")
17
+ cmake_flags = env.get("CMAKE_FLAGS", "")
18
+
19
+ cmd = f"{cmake_exe} {cmake_flags} {cmake_targets}"
20
+ print(cmd)
21
+
22
+ result = subprocess.run(
23
+ args=cmd,
24
+ capture_output=False,
25
+ check=False,
26
+ shell=True,
27
+ )
28
+
29
+ return result.returncode
30
+
31
+
32
+ def generate(env):
33
+ cmake_binary_builder = Builder(action=cmake_action)
34
+
35
+ env.Append(BUILDERS={"CmakeBinary": cmake_binary_builder})
36
+
37
+
38
+ def exists(env):
39
+ return env.Detect("cmake")
@@ -0,0 +1,304 @@
1
+ #!/usr/bin/env python
2
+
3
+ # This Source Code Form is subject to the terms of the Mozilla Public
4
+ # License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ # file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
+
7
+
8
+ import os
9
+ import platform
10
+ import subprocess
11
+
12
+ from typing import List
13
+
14
+ from SCons.Script import Builder
15
+ from SCons.Script import Environment
16
+
17
+ from scons_xo_exts_lib.BuildSupport import NodeMangling
18
+
19
+
20
+ def _dotnet_get_dotnet_exe(env: Environment) -> str:
21
+ dotnet_exe = env.get("DOTNET_EXE")
22
+
23
+ if dotnet_exe:
24
+ return dotnet_exe
25
+
26
+ try:
27
+ return os.path.join(env["DOTNET_ROOT"], "dotnet")
28
+ except KeyError:
29
+ return "dotnet"
30
+
31
+
32
+ def _dotnet_get_project(source) -> str:
33
+ regex = ".*\\.(cs|fs|vb|)proj$"
34
+
35
+ try:
36
+ node = NodeMangling.regex_find_node(regex=regex, nodes=source)
37
+
38
+ return str(node.abspath)
39
+ except Exception as exception:
40
+ raise RuntimeError("No dotnet project file found", exception)
41
+
42
+
43
+ def _dotnet_command(env: Environment, source, args: List[str]) -> None:
44
+ project_file = _dotnet_get_project(source=source)
45
+ source_directory = os.path.dirname(project_file)
46
+
47
+ extra_variables = {
48
+ "DOTNET_CLI_TELEMETRY_OPTOUT": "1",
49
+ "DOTNET_NOLOGO": "1",
50
+ "DOTNET_SKIP_FIRST_TIME_EXPERIENCE": "1",
51
+ "MSBUILDTERMINALLOGGER": "off",
52
+ }
53
+
54
+ subprocess_env = env.Clone()["ENV"]
55
+ subprocess_env.update(extra_variables)
56
+
57
+ dotnet_exe = _dotnet_get_dotnet_exe(env=env)
58
+
59
+ cmd = [dotnet_exe] + args
60
+ print(cmd)
61
+
62
+ result = subprocess.run(
63
+ args=cmd,
64
+ capture_output=False,
65
+ check=False,
66
+ cwd=source_directory,
67
+ env=subprocess_env,
68
+ )
69
+
70
+ if result.returncode == 0:
71
+ return
72
+
73
+ raise RuntimeError("Dotnet command failed")
74
+
75
+
76
+ def _dotnet_detect_rid() -> str:
77
+ """
78
+ Returns a dotnet runtime identifier string in the format "{os}-{arch}".
79
+
80
+ OS values: linux, linux-musl, windows, osx
81
+ Arch values: x64, x86, arm, arm64
82
+ """
83
+
84
+ os_name = "unknownos"
85
+ os_arch = "unknownarch"
86
+
87
+ py_os_name = platform.system().lower()
88
+ py_os_arch = platform.machine().lower()
89
+
90
+ match py_os_name:
91
+ case "linux":
92
+ if platform.libc_ver()[0] == "glibc":
93
+ os_name = "linux"
94
+ else:
95
+ os_name = "linux-musl"
96
+ case "darwin":
97
+ os_name = "osx"
98
+ case "windows":
99
+ os_name = "win"
100
+ case _:
101
+ os_name = py_os_name
102
+
103
+ match py_os_arch:
104
+ case "x86_64" | "amd64":
105
+ os_arch = "x64"
106
+ case "i386" | "i686":
107
+ os_arch = "x86"
108
+ case "aarch64":
109
+ os_arch = "arm64"
110
+ case _:
111
+ os_arch = py_os_arch
112
+
113
+ return f"{os_name}-{os_arch}"
114
+
115
+
116
+ def _dotnet_get_rid(env: Environment) -> str:
117
+ key = "DOTNET_RUNTIME"
118
+
119
+ if key in env:
120
+ return env[key]
121
+
122
+ return _dotnet_detect_rid()
123
+
124
+
125
+ def _dotnet_get_configuration(env: Environment) -> str:
126
+ key = "DOTNET_CONFIGURATION"
127
+
128
+ if key in env:
129
+ return env[key]
130
+
131
+ return "Release"
132
+
133
+
134
+ def _dotnet_restore(env: Environment, source) -> None:
135
+ runtime = _dotnet_get_rid(env=env)
136
+
137
+ _dotnet_command(
138
+ env=env,
139
+ source=source,
140
+ args=[
141
+ "restore",
142
+ "--force-evaluate",
143
+ f"--runtime={runtime}",
144
+ ],
145
+ )
146
+
147
+
148
+ def _dotnet_blazor_restore(env: Environment, source) -> None:
149
+ _dotnet_command(
150
+ env=env,
151
+ source=source,
152
+ args=[
153
+ "restore",
154
+ "--force-evaluate",
155
+ ],
156
+ )
157
+
158
+
159
+ def _dotnet_build(env: Environment, source) -> None:
160
+ runtime = _dotnet_get_rid(env=env)
161
+ configuration = _dotnet_get_configuration(env=env)
162
+
163
+ _dotnet_command(
164
+ env=env,
165
+ source=source,
166
+ args=[
167
+ "build",
168
+ "--no-restore",
169
+ f"--runtime={runtime}",
170
+ f"--configuration={configuration}",
171
+ ],
172
+ )
173
+
174
+
175
+ def _dotnet_blazor_build(env: Environment, source) -> None:
176
+ configuration = _dotnet_get_configuration(env=env)
177
+
178
+ _dotnet_command(
179
+ env=env,
180
+ source=source,
181
+ args=[
182
+ "build",
183
+ "--no-restore",
184
+ f"--configuration={configuration}",
185
+ ],
186
+ )
187
+
188
+
189
+ def _dotnet_compile(*args, **kwargs) -> None:
190
+ _dotnet_restore(*args, **kwargs)
191
+ _dotnet_build(*args, **kwargs)
192
+
193
+
194
+ def _dotnet_blazor_compile(*args, **kwargs) -> None:
195
+ _dotnet_blazor_restore(*args, **kwargs)
196
+ _dotnet_blazor_build(*args, **kwargs)
197
+
198
+
199
+ def _dotnet_pack(env: Environment, source, target) -> None:
200
+ runtime = _dotnet_get_rid(env=env)
201
+ configuration = _dotnet_get_configuration(env=env)
202
+
203
+ target_directory = NodeMangling.get_first_directory(nodes=target)
204
+
205
+ _dotnet_command(
206
+ env=env,
207
+ source=source,
208
+ args=[
209
+ "pack",
210
+ "--no-restore",
211
+ f"--runtime={runtime}",
212
+ f"--configuration={configuration}",
213
+ f"--output={target_directory}",
214
+ ],
215
+ )
216
+
217
+
218
+ def _dotnet_compile_binary(env: Environment, source, target) -> None:
219
+ runtime = _dotnet_get_rid(env=env)
220
+ configuration = _dotnet_get_configuration(env=env)
221
+
222
+ target_directory = NodeMangling.get_first_directory(nodes=target)
223
+
224
+ _dotnet_command(
225
+ env=env,
226
+ source=source,
227
+ args=[
228
+ "publish",
229
+ "--no-restore",
230
+ "--self-contained",
231
+ "-p:PublishSingleFile=true",
232
+ f"--runtime={runtime}",
233
+ f"--configuration={configuration}",
234
+ f"--output={target_directory}",
235
+ ],
236
+ )
237
+
238
+
239
+ def _dotnet_blazor_compile_binary(env: Environment, source, target) -> None:
240
+ configuration = _dotnet_get_configuration(env=env)
241
+
242
+ # Assume we have "target/wwwroot/index.html" as "target".
243
+ # We have to 1st resolve "wwwroot" path and then resolve it's parent path.
244
+ wwwroot_directory = NodeMangling.get_first_directory(nodes=target)
245
+ target_directory = os.path.dirname(wwwroot_directory)
246
+
247
+ _dotnet_command(
248
+ env=env,
249
+ source=source,
250
+ args=[
251
+ "publish",
252
+ "--no-restore",
253
+ f"--configuration={configuration}",
254
+ f"--output={target_directory}",
255
+ ],
256
+ )
257
+
258
+
259
+ def dotnet_package_build_action(target, source, env: Environment) -> int:
260
+ try:
261
+ _dotnet_compile(env=env, source=source)
262
+ _dotnet_pack(env=env, source=source, target=target)
263
+ except RuntimeError:
264
+ return 1
265
+
266
+ return 0
267
+
268
+
269
+ def dotnet_binary_build_action(target, source, env) -> int:
270
+ try:
271
+ _dotnet_compile(env=env, source=source)
272
+ _dotnet_compile_binary(env=env, source=source, target=target)
273
+ except RuntimeError:
274
+ return 1
275
+
276
+ return 0
277
+
278
+
279
+ def dotnet_blazor_binary_build_action(target, source, env) -> int:
280
+ try:
281
+ _dotnet_blazor_compile(env=env, source=source)
282
+ _dotnet_blazor_compile_binary(env=env, source=source, target=target)
283
+ except RuntimeError:
284
+ return 1
285
+
286
+ return 0
287
+
288
+
289
+ def generate(env: Environment) -> None:
290
+ dotnet_package_builder = Builder(action=dotnet_package_build_action)
291
+ dotnet_binary_builder = Builder(action=dotnet_binary_build_action)
292
+ dotnet_blazor_binary_builder = Builder(action=dotnet_blazor_binary_build_action)
293
+
294
+ env.Append(
295
+ BUILDERS={
296
+ "DotnetPackage": dotnet_package_builder,
297
+ "DotnetBinary": dotnet_binary_builder,
298
+ "DotnetBlazorBinary": dotnet_blazor_binary_builder,
299
+ }
300
+ )
301
+
302
+
303
+ def exists(env: Environment):
304
+ return env.Detect("dotnet")