Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7.6.1
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Ignore bazel build artifacts
MODULE.bazel
MODULE.bazel.lock
bazel-bin
bazel-metadata
bazel-out
bazel-testlogs
build/
tensorflow_metadata.egg-info/
tensorflow_metadata/proto/v0/*_pb2.py
1 change: 1 addition & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ ignore = [
"D105", # Missing docstring in magic method
"D203", # 1 blank line before after class docstring
"D204", # 1 blank line required after class docstring
"D213", # Make docstrings start on second line
"D413", # 1 blank line after parameters
"SIM108", # Simplify if/else to one line; not always clearer
"D206", # Docstrings should be indented with spaces; unnecessary when running ruff-format
Expand Down
61 changes: 12 additions & 49 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,66 +13,31 @@
# limitations under the License.
"""Package Setup script for tf.Metadata."""

import os
import pathlib
import platform
import shutil
import subprocess

# pylint: disable=g-bad-import-order
# It is recommended to import setuptools prior to importing distutils to avoid
# using legacy behavior from distutils.
# https://setuptools.readthedocs.io/en/latest/history.html#v48-0-0
from distutils.command import build

import setuptools
from setuptools import find_packages, setup
from setuptools.command import build_py

# pylint: enable=g-bad-import-order


class _BuildCommand(build.build):
"""Build everything that is needed to install.

This overrides the original distutils "build" command to to run bazel_build
command before any sub_commands.

build command is also invoked from bdist_wheel and install command, therefore
this implementation covers the following commands:
- pip install . (which invokes bdist_wheel)
- python setup.py install (which invokes install command)
- python setup.py bdist_wheel (which invokes bdist_wheel command)
"""

def _build_cc_extensions(self):
return True

# Add "bazel_build" command as the first sub_command of "build". Each
# sub_command of "build" (e.g. "build_py", "build_ext", etc.) is executed
# sequentially when running a "build" command, if the second item in the tuple
# (predicate method) is evaluated to true.
sub_commands = [
("bazel_build", _build_cc_extensions),
] + build.build.sub_commands


class _BazelBuildCommand(setuptools.Command):
"""Build Bazel artifacts and move generated files to the ."""
class _BazelBuildCommand(build_py.build_py):
"""Build Bazel artifacts and move generated files to the source directory."""

def initialize_options(self):
pass

def finalize_options(self):
super().initialize_options()
self._bazel_cmd = shutil.which("bazel")
if not self._bazel_cmd:
raise RuntimeError(
'Could not find "bazel" binary. Please visit '
"https://docs.bazel.build/versions/master/install.html for "
"installation instruction."
)

self._additional_build_options = []
if platform.system() == "Windows":
self._additional_build_options = ["--copt=-DWIN32_LEAN_AND_MEAN"]
else:
self._additional_build_options = []

def run(self):
subprocess.check_call(
Expand All @@ -86,9 +51,11 @@ def run(self):
],
# Bazel should be invoked in a directory containing bazel WORKSPACE
# file, which is the root directory.
cwd=os.path.dirname(os.path.realpath(__file__)),
cwd=str(pathlib.Path(__file__).parent),
)

super().run()


with open("tensorflow_metadata/version.py") as fp:
globals_dict = {}
Expand Down Expand Up @@ -117,7 +84,6 @@ def run(self):
"Intended Audience :: Developers",
"Intended Audience :: Education",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: Apache Software License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
Expand Down Expand Up @@ -146,15 +112,12 @@ def run(self):
"pytest>=8,<9",
],
},
include_package_data=True,
description="Library and standards for schema and statistics.",
long_description=_LONG_DESCRIPTION,
long_description_content_type="text/markdown",
keywords="tensorflow metadata tfx",
download_url="https://github.com/tensorflow/metadata/tags",
requires=[],
cmdclass={
"build": _BuildCommand,
"bazel_build": _BazelBuildCommand,
},
cmdclass={"build_py": _BazelBuildCommand},
package_data={"tensorflow_metadata.proto.v0": ["*.proto"]},
)
13 changes: 13 additions & 0 deletions tensorflow_metadata/proto/v0/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,16 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Init module for tf.Metadata v0 protos."""

import pathlib


def get_protocol_buffer_path() -> pathlib.Path:
"""Get the path to the directory containing the protocol buffers.

Returns
-------
pathlib.Path
Path to the directory containing *.proto files
"""
return pathlib.Path(__file__).parent
Loading