-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.py
104 lines (86 loc) · 3.26 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
import os
import posixpath
import re
import shutil
from distutils import sysconfig
import setuptools
from setuptools.command import build_ext
class BazelExtension(setuptools.Extension):
"""A C/C++ extension that is defined as a Bazel BUILD target."""
def __init__(self, name, bazel_target):
self.bazel_target = bazel_target
self.relpath, self.target_name = posixpath.relpath(bazel_target, "//").split(":")
setuptools.Extension.__init__(self, name, sources=[])
class BuildBazelExtension(build_ext.build_ext):
"""A command that runs Bazel to build a C/C++ extension."""
def run(self):
for ext in self.extensions:
self.bazel_build(ext)
build_ext.build_ext.run(self)
def bazel_build(self, ext):
with open("WORKSPACE", "r") as f:
workspace_contents = f.read()
with open("WORKSPACE", "w") as f:
f.write(
re.sub(
r'(?<=path = ").*(?=", # May be overwritten by setup\.py\.)',
sysconfig.get_python_inc().replace(os.path.sep, posixpath.sep),
workspace_contents,
)
)
if not os.path.exists(self.build_temp):
os.makedirs(self.build_temp)
bazel_argv = [
"bazel",
"build",
ext.bazel_target,
"--symlink_prefix=" + os.path.join(self.build_temp, "bazel-"),
"--compilation_mode=" + ("dbg" if self.debug else "opt"),
]
self.spawn(bazel_argv)
if not ext.name.startswith("_"):
ext.name = "_" + ext.name
shared_lib_ext = ".so"
shared_lib = ext.name + shared_lib_ext
ext_bazel_bin_path = os.path.join(self.build_temp, "bazel-bin", ext.relpath, shared_lib)
ext_dest_path = self.get_ext_fullpath(ext.name)
ext_dest_dir = os.path.dirname(ext_dest_path)
if not os.path.exists(ext_dest_dir):
os.makedirs(ext_dest_dir)
shutil.copyfile(ext_bazel_bin_path, ext_dest_path)
package_dir = os.path.join(ext_dest_dir, "galaxy_py")
if not os.path.exists(package_dir):
os.makedirs(package_dir)
shutil.copyfile(
"python/__init__.py", os.path.join(package_dir, "__init__.py")
)
shutil.copyfile(
"python/logging.py", os.path.join(package_dir, "logging.py")
)
setuptools.setup(
name="galaxy_py",
version="1.0.0",
description="Simple distributed file system based on gRPC.",
long_description="README.md",
keywords="distributed system, gRPC",
url="https://github.com/kfrancischen/galaxy",
python_requires=">=3.6",
package_dir={"": "python"},
cmdclass=dict(build_ext=BuildBazelExtension),
packages=setuptools.find_packages(where="python"),
include_package_data=True,
ext_modules=[
BazelExtension("gclient", "//python:gclient",)
],
zip_safe=False,
author="Francis Chen",
author_email="[email protected]",
classifiers=[
"Programming Language :: Python :: 3",
"Operating System :: OS Independent",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: System :: Distributed Computing"
],
install_requires=[],
license="Apache 2.0",
)