-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.py
114 lines (93 loc) · 3.63 KB
/
setup.py
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
from os.path import dirname, abspath
from platform import system
from setuptools import setup, Extension, find_packages
from subprocess import Popen, PIPE
osname = system()
debug = False
dir_name = dirname(abspath(__file__))
if osname == "Linux" or osname == "Darwin":
gradle_bin = "./gradlew"
else:
gradle_bin = ".\\gradlew.bat"
# Build the project
# I don't know why, but for some reason this may fail a few times before succeeding.
for i in range(10):
proc = Popen([gradle_bin, "build"])
if proc.wait() == 0:
break
else:
raise RuntimeError("Build failed")
# Fetch configuration from gradle task
proc = Popen([gradle_bin, "setupMetadata"], stdout=PIPE)
if proc.wait() != 0:
raise RuntimeError("Fetching metadata failed")
output = proc.stdout.read().decode()
real_output = output.split("===METADATA START===")[1].split("===METADATA END===")[0]
# Apply the configuration
exec(real_output, globals(), locals())
# props added:
has_stubs: bool
project_name: str
project_version: str
build_dir: str
root_dir: str
target: str
build_dir = build_dir[len(dir_name)+1:]
root_dir = root_dir[len(dir_name)+1:]
def snake_case(name):
return name.replace("-", "_").lower()
def extensions():
folder = "debugStatic" if debug else "releaseStatic"
prefix = "_" if has_stubs else ""
native = Extension(prefix + snake_case(project_name),
sources=[f"{build_dir}/generated/ksp/{target}/{target}Main/resources/entrypoint.cpp"],
# Temporary workaround for [KT-52303](https://youtrack.jetbrains.com/issue/KT-52303)
# When resolved, use `{build_dir}/` instead of `build/`
include_dirs=[f"build/bin/{target}/{folder}/"],
library_dirs=[f"build/bin/{target}/{folder}/"],
libraries=[snake_case(project_name)])
return [native]
with open("README.md", "r") as fp:
long_description = fp.read()
with open("requirements.txt", "r") as fp:
requirements = fp.read()
attrs = {}
if has_stubs:
stub_root = f"{build_dir}/generated/ksp/{target}/{target}Main/resources/"
attrs["packages"] = find_packages(where=stub_root) + ["kaudio.app"] + ["kaudio.app." + it for it in find_packages(where="src/main/kaudio/app")]
attrs["package_dir"] = {"": stub_root, "kaudio.app": "src/main/kaudio/app"}
else:
attrs["packages"] = ["kaudio.app"] + ["kaudio.app." + it for it in find_packages(where="src/main/kaudio/app")]
attrs["package_dir"] = {"kaudio.app": "src/main/kaudio/app"}
print(attrs)
setup(
name=snake_case(project_name),
version=project_version,
description=long_description,
author="Martmists",
author_email="[email protected]",
python_requires=">=3.10",
ext_modules=extensions(),
data_files=[
("share/applications", ["src/main/resources/com.martmists.kaudio.desktop"]),
],
entry_points={
"console_scripts": ["kaudio=kaudio.app.__main__:main"],
"kaudio.app.nodes": ["builtins=kaudio.app.metadata:load_builtins"]
},
extras_require={
"app": [*filter(lambda req: req != "" and not req.startswith("#"), requirements.split("\n"))],
},
classifiers=[
"Development Status :: 5 - Production/Stable",
"Environment :: X11 Applications :: Qt",
"Programming Language :: Kotlin",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: Implementation :: CPython",
"Topic :: Multimedia :: Sound/Audio :: Mixers",
"Intended Audience :: End Users/Desktop",
"Intended Audience :: Developers",
"License :: OSI Approved :: BSD License",
],
**attrs
)