This repository has been archived by the owner on Oct 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.py
66 lines (48 loc) · 2.07 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
import os
import pathlib
import sys
from glob import glob
from typing import List, Tuple
from setuptools import Distribution, setup
sys.path.insert(0, pathlib.Path(__file__).parent.joinpath("mlflow_go").as_posix())
from lib import build_lib
def _prune_go_files(path: str):
for root, dirnames, filenames in os.walk(path, topdown=False):
for filename in filenames:
if filename.endswith(".go"):
os.unlink(os.path.join(root, filename))
for dirname in dirnames:
try:
os.rmdir(os.path.join(root, dirname))
except OSError:
pass
def finalize_distribution_options(dist: Distribution) -> None:
dist.has_ext_modules = lambda: True
# this allows us to set the tag for the wheel without the python version
bdist_wheel_base_class = dist.get_command_class("bdist_wheel")
class bdist_wheel_go(bdist_wheel_base_class):
def get_tag(self) -> Tuple[str, str, str]:
_, _, plat = super().get_tag()
return "py3", "none", plat
dist.cmdclass["bdist_wheel"] = bdist_wheel_go
# this allows us to build the go binary and add the Go source files to the sdist
build_base_class = dist.get_command_class("build")
class build_go(build_base_class):
def initialize_options(self) -> None:
self.editable_mode = False
self.build_lib = None
def finalize_options(self) -> None:
self.set_undefined_options("build_py", ("build_lib", "build_lib"))
def run(self) -> None:
if not self.editable_mode:
_prune_go_files(self.build_lib)
build_lib(
pathlib.Path("."),
pathlib.Path(self.build_lib).joinpath("mlflow_go"),
)
def get_source_files(self) -> List[str]:
return ["go.mod", "go.sum", *glob("pkg/**/*.go", recursive=True)]
dist.cmdclass["build_go"] = build_go
build_base_class.sub_commands.append(("build_go", None))
Distribution.finalize_options = finalize_distribution_options
setup()