scons-xo-exts-lib 1.3.0__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,67 @@
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 subprocess
10
+
11
+ from SCons.Script import Builder
12
+ from SCons.Script import Environment
13
+
14
+
15
+ def _get_mix_project(source: list):
16
+ for source_node in source:
17
+ path = source_node.abspath
18
+
19
+ if "mix.exs" in path:
20
+ return path
21
+
22
+ raise RuntimeError("No mix-project in specified sources")
23
+
24
+
25
+ def _mix_command(env: Environment, args_string: str, cwd: str) -> int:
26
+ mix_exe = env.get(key="MIX_EXE", default="mix")
27
+ mix_flags = env.get(key="MIX_FLAGS", default="")
28
+
29
+ cmd = f"{mix_exe} {args_string} {mix_flags}"
30
+ print(cmd)
31
+
32
+ result = subprocess.run(
33
+ args=cmd,
34
+ capture_output=False,
35
+ check=False,
36
+ cwd=cwd,
37
+ shell=True,
38
+ )
39
+
40
+ return result.returncode
41
+
42
+
43
+ def elixir_build_action(target, source, env) -> int:
44
+ elixir_project = _get_mix_project(source=source)
45
+ elixir_base_dir = os.path.dirname(elixir_project)
46
+
47
+ result = _mix_command(
48
+ env=env,
49
+ args_string="escript.build",
50
+ cwd=elixir_base_dir,
51
+ )
52
+
53
+ return result
54
+
55
+
56
+ def generate(env: Environment) -> None:
57
+ elixir_binary_builder = Builder(action=elixir_build_action)
58
+
59
+ env.Append(
60
+ BUILDERS={
61
+ "ElixirBinary": elixir_binary_builder,
62
+ },
63
+ )
64
+
65
+
66
+ def exists(env: Environment):
67
+ return env.Detect("elixir")
@@ -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 make_action(target, source, env):
14
+ make_targets = " ".join(str(t) for t in target)
15
+
16
+ make_exe = env.get("MAKE_EXE", "make")
17
+ make_flags = env.get("MAKE_FLAGS", "")
18
+
19
+ cmd = f"{make_exe} {make_flags} {make_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
+ make_binary_builder = Builder(action=make_action)
34
+
35
+ env.Append(BUILDERS={"MakeBinary": make_binary_builder})
36
+
37
+
38
+ def exists(env):
39
+ return env.Detect("make")
@@ -0,0 +1,44 @@
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 subprocess
10
+
11
+ from SCons.Script import Builder
12
+
13
+ from scons_xo_exts_lib.BuildSupport import NodeMangling
14
+
15
+
16
+ def meson_action(target, source, env):
17
+ source_dir = NodeMangling.get_first_directory(nodes=source)
18
+ builddir = NodeMangling.get_first_directory(nodes=target)
19
+
20
+ meson_exe = env.get("MESON_EXE", "meson")
21
+ meson_flags = env.get("MESON_FLAGS", "")
22
+
23
+ cmd = f"{meson_exe} setup --reconfigure {meson_flags} {builddir}"
24
+ print(cmd)
25
+
26
+ result = subprocess.run(
27
+ args=cmd,
28
+ cwd=source_dir,
29
+ capture_output=False,
30
+ check=False,
31
+ shell=True,
32
+ )
33
+
34
+ return result.returncode
35
+
36
+
37
+ def generate(env):
38
+ meson_builddir_builder = Builder(action=meson_action)
39
+
40
+ env.Append(BUILDERS={"MesonBuilddir": meson_builddir_builder})
41
+
42
+
43
+ def exists(env):
44
+ return env.Detect("meson")
@@ -0,0 +1,42 @@
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
+ from scons_xo_exts_lib.BuildSupport import NodeMangling
13
+
14
+
15
+ def ninja_action(target, source, env):
16
+ source_dir = NodeMangling.get_first_directory(nodes=source)
17
+
18
+ ninja_exe = env.get("NINJA_EXE", "ninja")
19
+ ninja_flags = env.get("NINJA_FLAGS", "")
20
+
21
+ cmd = f"{ninja_exe} {ninja_flags} -C ."
22
+ print(cmd)
23
+
24
+ result = subprocess.run(
25
+ args=cmd,
26
+ cwd=source_dir,
27
+ capture_output=False,
28
+ check=False,
29
+ shell=True,
30
+ )
31
+
32
+ return result.returncode
33
+
34
+
35
+ def generate(env):
36
+ ninja_binary_builder = Builder(action=ninja_action)
37
+
38
+ env.Append(BUILDERS={"NinjaBinary": ninja_binary_builder})
39
+
40
+
41
+ def exists(env):
42
+ return env.Detect("ninja")
@@ -0,0 +1,109 @@
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 subprocess
10
+
11
+ from shutil import move
12
+
13
+ from SCons.Script import Builder
14
+
15
+ from scons_xo_exts_lib.BuildSupport import NodeMangling
16
+
17
+
18
+ def _orgmode_extension_to_backend(file_extension: str) -> str:
19
+ match file_extension:
20
+ case "info":
21
+ return "texinfo"
22
+ case "markdown":
23
+ return "md"
24
+ case "pdf":
25
+ return "latex"
26
+ case "texi":
27
+ return "texinfo"
28
+ case _:
29
+ return file_extension
30
+
31
+
32
+ def _orgmode_extension_to_libraries(file_extension: str) -> list[str]:
33
+ elisp_libs: list[str] = []
34
+
35
+ backend: str = _orgmode_extension_to_backend(file_extension=file_extension)
36
+
37
+ if backend != file_extension:
38
+ elisp_libs.append(f"ox-{backend}")
39
+
40
+ return elisp_libs
41
+
42
+
43
+ def _orgmode_get_export_flags(target_file: str, source_file: str) -> str:
44
+ file_extension = os.path.splitext(target_file)[1][1:]
45
+ backend = _orgmode_extension_to_backend(file_extension=file_extension)
46
+
47
+ if file_extension == "texi":
48
+ fun = "org-texinfo-export-to-texinfo"
49
+ else:
50
+ fun = f"org-{backend}-export-to-{file_extension}"
51
+
52
+ load_elisp_libs = [
53
+ "org",
54
+ "ox-latex",
55
+ ]
56
+
57
+ extension_libs = _orgmode_extension_to_libraries(file_extension=file_extension)
58
+
59
+ load_elisp_libs.extend(extension_libs)
60
+
61
+ load_flags = " ".join([f"-l {s}" for s in load_elisp_libs])
62
+ flags = f"{load_flags} {source_file} -f {fun}"
63
+
64
+ return flags
65
+
66
+
67
+ def orgmode_action(target, source, env):
68
+ emacs_exe = env.get("EMACS_EXE", "emacs")
69
+ emacs_exec_flags = env.get("EMACS_EXEC_FLAGS", "-batch -q --no-site-file")
70
+
71
+ cwd = NodeMangling.get_first_directory(source)
72
+
73
+ inp = NodeMangling.get_first_node(source).abspath
74
+ out = NodeMangling.get_first_node(target).abspath
75
+
76
+ orgmode_flags = _orgmode_get_export_flags(target_file=out, source_file=inp)
77
+ flags = f"{emacs_exec_flags} {orgmode_flags}"
78
+
79
+ cmd = f"{emacs_exe} {flags}"
80
+
81
+ print(cmd)
82
+
83
+ result = subprocess.run(
84
+ args=cmd,
85
+ capture_output=False,
86
+ check=False,
87
+ shell=True,
88
+ cwd=cwd,
89
+ )
90
+
91
+ # When the target basename is different than export basename we have to do
92
+ # a file move.
93
+ if not os.path.exists(out):
94
+ out_extension = os.path.splitext(out)[1]
95
+ inp_basename = os.path.splitext(inp)[0]
96
+
97
+ move(f"{inp_basename}{out_extension}", out)
98
+
99
+ return result.returncode
100
+
101
+
102
+ def generate(env):
103
+ orgmode_file_builder = Builder(action=orgmode_action)
104
+
105
+ env.Append(BUILDERS={"OrgmodeFile": orgmode_file_builder})
106
+
107
+
108
+ def exists(env):
109
+ return env.Detect("orgmode")
@@ -0,0 +1,42 @@
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
+ from scons_xo_exts_lib.BuildSupport import NodeMangling
13
+
14
+
15
+ def pandoc_action(target, source, env):
16
+ pandoc_exe = env.get("PANDOC_EXE", "pandoc")
17
+ pandoc_flags = env.get("PANDOC_FLAGS", "")
18
+
19
+ inp = NodeMangling.get_first_node(source).abspath
20
+ out = NodeMangling.get_first_node(target).abspath
21
+
22
+ cmd = f"{pandoc_exe} {pandoc_flags} -o {out} {inp}"
23
+ print(cmd)
24
+
25
+ result = subprocess.run(
26
+ args=cmd,
27
+ capture_output=False,
28
+ check=False,
29
+ shell=True,
30
+ )
31
+
32
+ return result.returncode
33
+
34
+
35
+ def generate(env):
36
+ pandoc_file_builder = Builder(action=pandoc_action)
37
+
38
+ env.Append(BUILDERS={"PandocFile": pandoc_file_builder})
39
+
40
+
41
+ def exists(env):
42
+ return env.Detect("pandoc")
@@ -0,0 +1,123 @@
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 subprocess
10
+
11
+ from SCons.Script import Builder
12
+ from SCons.Script import Environment
13
+
14
+ from scons_xo_exts_lib.BuildSupport import NodeMangling
15
+
16
+
17
+ def _racket_get_plt_user_home(env: Environment) -> str:
18
+ try:
19
+ return env["PLTUSERHOME"]
20
+ except Exception:
21
+ raise RuntimeError("PLTUSERHOME is unset, please set it in SCons")
22
+
23
+
24
+ def _racket_get_raco_exe(env: Environment) -> str:
25
+ racket_exe: str = env.get(key="RACKET_EXE", default="racket")
26
+ raco_exe: str = f"{racket_exe} -l raco --"
27
+
28
+ return raco_exe
29
+
30
+
31
+ def _racket_raco(env: Environment, source_node, args: str) -> None:
32
+ plt_user_home: str = _racket_get_plt_user_home(env=env)
33
+ raco: str = _racket_get_raco_exe(env=env)
34
+
35
+ extra_variables = {
36
+ "PLTUSERHOME": plt_user_home,
37
+ }
38
+
39
+ subprocess_env = env.Clone()["ENV"]
40
+ subprocess_env.update(extra_variables)
41
+
42
+ directory: str = NodeMangling.get_first_directory(source_node)
43
+ cmd = f"{raco} {args}"
44
+ print(cmd)
45
+
46
+ result = subprocess.run(
47
+ args=cmd,
48
+ capture_output=False,
49
+ check=False,
50
+ cwd=directory,
51
+ shell=True,
52
+ )
53
+
54
+ if result.returncode == 0:
55
+ return
56
+
57
+ raise RuntimeError(f"Raco command failed, ran: {cmd}")
58
+
59
+
60
+ def _racket_install_package(env: Environment, source: list) -> None:
61
+ for source_node in source:
62
+ _racket_raco(
63
+ env=env,
64
+ source_node=source_node,
65
+ args="pkg install --auto --skip-installed --no-docs",
66
+ )
67
+
68
+
69
+ def _racket_setup_package(env: Environment, source: list) -> None:
70
+ for source_node in source:
71
+ _racket_raco(
72
+ env=env,
73
+ source_node=source_node,
74
+ args="setup --tidy --avoid-main --no-docs",
75
+ )
76
+
77
+
78
+ def _racket_create_exe(env: Environment, target, source) -> None:
79
+ for target_node, source_node in zip(target, source):
80
+ out: str = target_node.abspath
81
+ inp: str = source_node.abspath
82
+
83
+ _racket_raco(
84
+ env=env,
85
+ source_node=source_node,
86
+ args=f"exe -v --orig-exe -o {out} {inp}",
87
+ )
88
+
89
+
90
+ def racket_library_action(target, source, env) -> int:
91
+ try:
92
+ _racket_install_package(env=env, source=source)
93
+ except RuntimeError:
94
+ return 1
95
+
96
+ return 0
97
+
98
+
99
+ def racket_binary_action(target, source, env) -> int:
100
+ try:
101
+ _racket_install_package(env=env, source=source)
102
+ _racket_setup_package(env=env, source=source)
103
+ _racket_create_exe(env=env, target=target, source=source)
104
+ except RuntimeError:
105
+ return 1
106
+
107
+ return 0
108
+
109
+
110
+ def generate(env: Environment) -> None:
111
+ racket_binary_builder = Builder(action=racket_binary_action)
112
+ racket_library_builder = Builder(action=racket_library_action)
113
+
114
+ env.Append(
115
+ BUILDERS={
116
+ "RacketBinary": racket_binary_builder,
117
+ "RacketLibrary": racket_library_builder,
118
+ }
119
+ )
120
+
121
+
122
+ def exists(env: Environment):
123
+ return env.Detect(progs="racket")
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env python
2
+
3
+
4
+ # This Source Code Form is subject to the terms of the Mozilla Public
5
+ # License, v. 2.0. If a copy of the MPL was not distributed with this
6
+ # file, You can obtain one at http://mozilla.org/MPL/2.0/.
7
+
8
+
9
+ import subprocess
10
+
11
+ from SCons.Script import Builder
12
+
13
+ from scons_xo_exts_lib.BuildSupport import NodeMangling
14
+
15
+
16
+ def tar_image_action(target, source, env):
17
+ target_tar = NodeMangling.get_first_node(target)
18
+ directory = NodeMangling.get_first_directory(source)
19
+
20
+ cmd = f"tar --auto-compress --create --file {target_tar.abspath} ."
21
+
22
+ result = subprocess.run(
23
+ args=cmd,
24
+ capture_output=False,
25
+ check=False,
26
+ shell=True,
27
+ cwd=directory,
28
+ )
29
+
30
+ return result.returncode
31
+
32
+
33
+ def generate(env) -> None:
34
+ tar_image_builder = Builder(action=tar_image_action)
35
+
36
+ env.Append(BUILDERS={"TarImage": tar_image_builder})
37
+
38
+
39
+ def exists(env):
40
+ return env.Detect("tar_image")
@@ -0,0 +1,32 @@
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 typing import List
11
+
12
+
13
+ def find_files(path: str) -> List[str]:
14
+ if not os.path.exists(path):
15
+ return []
16
+
17
+ abs_path = os.path.abspath(path)
18
+ files = os.listdir(abs_path)
19
+
20
+ return list(map(lambda f: os.path.join(abs_path, f), files))
21
+
22
+
23
+ def find_last_directory(path: str) -> str:
24
+ files = find_files(path)
25
+
26
+ dirs = (d for d in files if os.path.isdir(d))
27
+ dirs = sorted(dirs, reverse=True)
28
+
29
+ if not dirs:
30
+ raise RuntimeError("No files found and so also no latest directory")
31
+
32
+ return dirs[0]
@@ -0,0 +1,38 @@
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 shutil import rmtree
11
+
12
+ from SCons.Script import Environment
13
+
14
+
15
+ def execute_command(env: Environment, command: str) -> None:
16
+ result = env.Execute(command)
17
+
18
+ if result:
19
+ raise RuntimeError(f"Command failed, given: {command}")
20
+
21
+
22
+ def remove(path: str, *args, **kwargs):
23
+ pwd = os.getcwd()
24
+
25
+ rmtree(os.path.join(pwd, path), *args, **kwargs)
26
+
27
+
28
+ def find_remove(env: Environment, file_name: str):
29
+ find_exe = env.get("FIND_EXE", "find")
30
+
31
+ rm_exe = env.get("RM_EXE", "rm")
32
+ rm_flags = env.get("RM_FLAGS", "-f -r")
33
+ rm_cmd = f"{rm_exe} {rm_flags}"
34
+
35
+ execute_command(
36
+ env,
37
+ f"{find_exe} . -name '{file_name}' -exec {rm_cmd} {{}} +",
38
+ )
@@ -0,0 +1,53 @@
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 typing import List
11
+
12
+
13
+ def read_lines(file_path: str) -> List[str]:
14
+ """
15
+ Return all file lines.
16
+ """
17
+
18
+ lines = []
19
+
20
+ with open(file_path) as file:
21
+ lines = file.readlines()
22
+
23
+ return lines
24
+
25
+
26
+ def read_line(file_path: str) -> str:
27
+ """
28
+ Return 1st file line.
29
+ """
30
+
31
+ lines = read_lines(file_path)
32
+
33
+ return lines[0].strip()
34
+
35
+
36
+ def read_version(base_path: str) -> str:
37
+ """
38
+ Return content of a "VERSION" file found at the "base_path".
39
+ """
40
+
41
+ version_file = os.path.join(base_path, "VERSION")
42
+
43
+ return read_line(version_file)
44
+
45
+
46
+ def read_python_version(base_path: str) -> str:
47
+ """
48
+ Return content of a ".python-version" file found at the "base_path".
49
+ """
50
+
51
+ version_file = os.path.join(base_path, ".python-version")
52
+
53
+ return read_line(version_file)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env python
2
+
3
+ """
4
+ Scons extensions library by XGQT.
5
+ """
6
+
7
+ __version__ = "1.3.0"
8
+ __description__ = "Scons extensions library by XGQT"
@@ -0,0 +1,39 @@
1
+ Metadata-Version: 2.4
2
+ Name: scons-xo-exts-lib
3
+ Version: 1.3.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 XO 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
+