forked from OctoPrint/OctoPrint
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
73 lines (54 loc) · 2.14 KB
/
setup.py
File metadata and controls
73 lines (54 loc) · 2.14 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
import os
import setuptools # noqa: F401,E402
def copy_files_build_py_factory(files, baseclass):
class copy_files_build_py(baseclass):
files = {}
def run(self):
print("RUNNING copy_files_build_py")
if not self.dry_run:
import shutil
for directory, files in self.files.items():
target_dir = os.path.join(self.build_lib, directory)
self.mkpath(target_dir)
for entry in files:
if isinstance(entry, tuple):
if len(entry) != 2:
continue
source, dest = entry[0], os.path.join(target_dir, entry[1])
else:
source = entry
dest = os.path.join(target_dir, source)
print("Copying {} to {}".format(source, dest))
shutil.copy2(source, dest)
baseclass.run(self)
return type(copy_files_build_py)(
copy_files_build_py.__name__, (copy_files_build_py,), {"files": files}
)
def get_version_and_cmdclass(pkg_path):
import os
from importlib.util import module_from_spec, spec_from_file_location
spec = spec_from_file_location("version", os.path.join(pkg_path, "_version.py"))
module = module_from_spec(spec)
spec.loader.exec_module(module)
data = module.get_data()
return data["version"], module.get_cmdclass(pkg_path)
def get_cmdclass(cmdclass):
from setuptools.command.build_py import build_py as _build_py
cmdclass["build_py"] = copy_files_build_py_factory(
{
"octoprint/templates/_data": [
"AUTHORS.md",
"SUPPORTERS.md",
"THIRDPARTYLICENSES.md",
]
},
cmdclass.get("build_py", _build_py),
)
return cmdclass
if __name__ == "__main__":
version, cmdclass = get_version_and_cmdclass(os.path.join("src", "octoprint"))
setuptools.setup(
version=version,
license="AGPL-3.0-or-later",
cmdclass=get_cmdclass(cmdclass),
)