-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
74 lines (61 loc) · 2.23 KB
/
Copy pathsetup.py
File metadata and controls
74 lines (61 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#
# Copyright (c) 2023 Rafał Kuźnia <rafal.kuznia@protonmail.com>
#
# SPDX-License-Identifier: GPL-3.0-or-later
#
from pathlib import Path
import setuptools
import setuptools.command.build
from setuptools import Command
from setuptools.errors import ExecError
class build_ksy(Command):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.build_lib = None
self.editable_mode = False
def initialize_options(self):
self.files = {}
self.package = []
self.compiler = None
def finalize_options(self):
self.set_undefined_options("build_py", ("build_lib", "build_lib"))
self.packages = self.distribution.packages
for package in self.packages:
package_path = Path(*(package.split(".")))
for source_file in Path(package_path, "specs").glob("*.ksy"):
build_file = Path(self.build_lib, package_path, source_file.name)
self.files[build_file] = source_file
def run(self):
for build, source in self.files.items():
target_path = (
Path(build.parent, "parsers")
if not self.editable_mode
else Path(source.parent.parent, "parsers")
)
args = [
"--outdir",
str(target_path),
"-t",
"python",
"--opaque-types=true",
"--python-package",
"speedtools.parsers",
str(source),
]
executables = ["ksc", "kaitai-struct-compiler", "kaitai-struct-compiler.bat"]
for executable in executables:
try:
self.spawn([executable] + args)
except ExecError:
pass
def get_output_mapping(self):
mapping = {}
for key, value in self.files.items():
mapping[str(key)] = str(value)
return mapping
def get_outputs(self):
return list(map(str, self.files.keys()))
def get_source_files(self):
return list(map(str, self.files.values()))
setuptools.command.build.build.sub_commands.append(("build_ksy", None))
setuptools.setup(cmdclass={"build_ksy": build_ksy})