7 from distutils
import sysconfig
9 from setuptools.command
import build_ext
12 HERE = os.path.dirname(os.path.abspath(__file__))
15 IS_WINDOWS = sys.platform.startswith(
"win")
19 """Parse the version string from __init__.py."""
21 os.path.join(HERE,
"bindings",
"python",
"google_benchmark",
"__init__.py")
25 line
for line
in init_file
if line.startswith(
"__version__")
28 raise ValueError(
"__version__ not defined in __init__.py")
31 exec(version_line, namespace)
32 return namespace[
"__version__"]
36 with open(os.path.join(HERE, path))
as requirements:
39 for line
in requirements
40 if not (line.isspace()
or line.startswith(
"#"))
45 """A C/C++ extension that is defined as a Bazel BUILD target."""
52 setuptools.Extension.__init__(self, name, sources=[])
56 """A command that runs Bazel to build a C/C++ extension."""
59 for ext
in self.extensions:
61 build_ext.build_ext.run(self)
64 """Runs the bazel build to create the package."""
65 with open(
"WORKSPACE",
"r")
as workspace:
66 workspace_contents = workspace.read()
68 with open(
"WORKSPACE",
"w")
as workspace:
71 r'(?<=path = ").*(?=", # May be overwritten by setup\.py\.)',
72 sysconfig.get_python_inc().replace(os.path.sep, posixpath.sep),
77 if not os.path.exists(self.build_temp):
78 os.makedirs(self.build_temp)
84 "--symlink_prefix=" + os.path.join(self.build_temp,
"bazel-"),
85 "--compilation_mode=" + (
"dbg" if self.debug
else "opt"),
90 for library_dir
in self.library_dirs:
91 bazel_argv.append(
"--linkopt=/LIBPATH:" + library_dir)
93 self.spawn(bazel_argv)
95 shared_lib_suffix =
'.dll' if IS_WINDOWS
else '.so'
96 ext_bazel_bin_path = os.path.join(
97 self.build_temp,
'bazel-bin',
98 ext.relpath, ext.target_name + shared_lib_suffix)
100 ext_dest_path = self.get_ext_fullpath(ext.name)
101 ext_dest_dir = os.path.dirname(ext_dest_path)
102 if not os.path.exists(ext_dest_dir):
103 os.makedirs(ext_dest_dir)
104 shutil.copyfile(ext_bazel_bin_path, ext_dest_path)
108 name=
"google_benchmark",
110 url=
"https://github.com/google/benchmark",
111 description=
"A library to benchmark code snippets.",
113 author_email=
"benchmark-py@google.com",
115 package_dir={
"":
"bindings/python"},
116 packages=setuptools.find_packages(
"bindings/python"),
118 cmdclass=dict(build_ext=BuildBazelExtension),
121 "google_benchmark._benchmark",
122 "//bindings/python/google_benchmark:_benchmark",
128 "Development Status :: 4 - Beta",
129 "Intended Audience :: Developers",
130 "Intended Audience :: Science/Research",
131 "License :: OSI Approved :: Apache Software License",
132 "Programming Language :: Python :: 3.6",
133 "Programming Language :: Python :: 3.7",
134 "Programming Language :: Python :: 3.8",
135 "Topic :: Software Development :: Testing",
136 "Topic :: System :: Benchmark",
138 license=
"Apache 2.0",
139 keywords=
"benchmark",