Skip to content

Commit

Permalink
Introduce new setup command to consolidate artifacts to a namespace
Browse files Browse the repository at this point in the history
Introduce a new `restructure` command that mangles the repo. This moves
the protobufs to directories inside the min_tfs_client namespace and
then does a string replace on all the protobuf imports to reflect the
new top level namespace.

This allows the package to provide the same, lightweight python runtime
as it was originally intended, while still being used in an image with
tensorflow installed.
  • Loading branch information
quantumfusion committed Feb 20, 2021
1 parent 8079e14 commit 3b10879
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ dist/
# Minified Tensorflow / Tensor Serving Folders
tensor_serving_client/tensorflow
tensor_serving_client/tensorflow_serving
tensor_serving_client/min_tfs_client/tensorflow
tensor_serving_client/min_tfs_client/tensorflow_serving

4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
![repo-checks](https://github.com/zendesk/min-tfs-client/workflows/repo-checks/badge.svg)
A modified version of min-tf-client where it is in its own isolated namespace, allowing for use alongside a Tensorflow install.
Introduces a new setup comand: `python setup.py restructure`, which mangles the imports and moves the tensorflow and tensorflow_serving protobufs inside the min_tfs_client namespace.

# Minimal Tensor Serving Python Client
A lightweight python client to communicate with Tensor Serving.

Expand Down
35 changes: 33 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from contextlib import contextmanager
from distutils.cmd import Command
from pathlib import Path
from shutil import copy2
from shutil import copy2, rmtree
from subprocess import check_output
from typing import Any, List

Expand Down Expand Up @@ -73,12 +73,42 @@ def run(self):
copy2(model_service_stub, destination)


class RestructureProtos(Command):
description = '''
Rearrange the repository and modify protobuf imports so that protobufs nested inside min_tfs_client namespace
'''
user_options: List[Any] = []

def initialize_options(self):
...

def finalize_options(self):
...

def run(self):
with cd(str(OUTPUT_PATH)):
# Move the protos inside of the min_tfs_client namespace
if os.path.isdir('min_tfs_client/tensorflow'):
rmtree('min_tfs_client/tensorflow')
os.rename('tensorflow', 'min_tfs_client/tensorflow')
if os.path.isdir('min_tfs_client/tensorflow_serving'):
rmtree('min_tfs_client/tensorflow_serving')
os.rename('tensorflow_serving', 'min_tfs_client/tensorflow_serving')
for file_path in OUTPUT_PATH.rglob('*.py'):
filename = str(file_path)
with open(filename, 'r') as f:
new_text = f.read().replace('from tensorflow', 'from min_tfs_client.tensorflow')
with open(filename, 'w') as f:
f.write(new_text)


class BuildPyCommand(build_py):
"""Custom build command."""

def run(self):
self.run_command("compile_pb")
self.run_command("copy_grpc")
self.run_command("restructure")
build_py.run(self)


Expand All @@ -88,13 +118,14 @@ def run(self):

setup(
name="min_tfs_client",
version="1.0.2",
version="1.0.2-abacus",
description="A minified Tensor Serving Client for Python",
long_description=long_description,
long_description_content_type="text/markdown",
cmdclass={
"compile_pb": CompileProtobufs,
"copy_grpc": CopyGRPCStubs,
"restructure": RestructureProtos,
"build_py": BuildPyCommand,
},
package_dir={"": "tensor_serving_client"},
Expand Down

0 comments on commit 3b10879

Please sign in to comment.