Skip to content

Commit fc4a452

Browse files
committed
Finish implementation
1 parent 713b104 commit fc4a452

2 files changed

Lines changed: 25 additions & 48 deletions

File tree

setup.py

Lines changed: 12 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -13,66 +13,32 @@
1313
# limitations under the License.
1414
"""Package Setup script for tf.Metadata."""
1515

16-
import os
16+
import pathlib
1717
import platform
1818
import shutil
1919
import subprocess
2020

21-
# pylint: disable=g-bad-import-order
22-
# It is recommended to import setuptools prior to importing distutils to avoid
23-
# using legacy behavior from distutils.
24-
# https://setuptools.readthedocs.io/en/latest/history.html#v48-0-0
25-
from distutils.command import build
26-
27-
import setuptools
2821
from setuptools import find_packages, setup
22+
from setuptools.command import build_py
2923

30-
# pylint: enable=g-bad-import-order
31-
32-
33-
class _BuildCommand(build.build):
34-
"""Build everything that is needed to install.
35-
36-
This overrides the original distutils "build" command to to run bazel_build
37-
command before any sub_commands.
38-
39-
build command is also invoked from bdist_wheel and install command, therefore
40-
this implementation covers the following commands:
41-
- pip install . (which invokes bdist_wheel)
42-
- python setup.py install (which invokes install command)
43-
- python setup.py bdist_wheel (which invokes bdist_wheel command)
44-
"""
45-
46-
def _build_cc_extensions(self):
47-
return True
48-
49-
# Add "bazel_build" command as the first sub_command of "build". Each
50-
# sub_command of "build" (e.g. "build_py", "build_ext", etc.) is executed
51-
# sequentially when running a "build" command, if the second item in the tuple
52-
# (predicate method) is evaluated to true.
53-
sub_commands = [
54-
("bazel_build", _build_cc_extensions),
55-
] + build.build.sub_commands
5624

57-
58-
class _BazelBuildCommand(setuptools.Command):
59-
"""Build Bazel artifacts and move generated files to the ."""
25+
class _BazelBuildCommand(build_py.build_py):
26+
"""Build Bazel artifacts and move generated files to the source directory."""
6027

6128
def initialize_options(self):
62-
pass
63-
64-
def finalize_options(self):
29+
super().initialize_options()
6530
self._bazel_cmd = shutil.which("bazel")
6631
if not self._bazel_cmd:
6732
raise RuntimeError(
6833
'Could not find "bazel" binary. Please visit '
6934
"https://docs.bazel.build/versions/master/install.html for "
7035
"installation instruction."
7136
)
37+
38+
self._additional_build_options = []
7239
if platform.system() == "Windows":
7340
self._additional_build_options = ["--copt=-DWIN32_LEAN_AND_MEAN"]
74-
else:
75-
self._additional_build_options = []
41+
7642

7743
def run(self):
7844
subprocess.check_call(
@@ -86,9 +52,11 @@ def run(self):
8652
],
8753
# Bazel should be invoked in a directory containing bazel WORKSPACE
8854
# file, which is the root directory.
89-
cwd=os.path.dirname(os.path.realpath(__file__)),
55+
cwd=str(pathlib.Path(__file__).parent),
9056
)
9157

58+
super().run()
59+
9260

9361
with open("tensorflow_metadata/version.py") as fp:
9462
globals_dict = {}
@@ -117,7 +85,6 @@ def run(self):
11785
"Intended Audience :: Developers",
11886
"Intended Audience :: Education",
11987
"Intended Audience :: Science/Research",
120-
"License :: OSI Approved :: Apache Software License",
12188
"Operating System :: OS Independent",
12289
"Programming Language :: Python",
12390
"Programming Language :: Python :: 3",
@@ -152,10 +119,7 @@ def run(self):
152119
keywords="tensorflow metadata tfx",
153120
download_url="https://github.com/tensorflow/metadata/tags",
154121
requires=[],
155-
cmdclass={
156-
"build": _BuildCommand,
157-
"bazel_build": _BazelBuildCommand,
158-
},
122+
cmdclass={"build_py": _BazelBuildCommand},
159123
package_data={
160124
"tensorflow_metadata.proto.v0": ["*.proto"]
161125
}

tensorflow_metadata/proto/v0/__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,16 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414
"""Init module for tf.Metadata v0 protos."""
15+
16+
import pathlib
17+
18+
19+
def get_protocol_buffer_path() -> pathlib.Path:
20+
"""Get the path to the directory containing the protocol buffers.
21+
22+
Returns
23+
-------
24+
pathlib.Path
25+
Path to the directory containing *.proto files
26+
"""
27+
return pathlib.Path(__file__).parent

0 commit comments

Comments
 (0)