Fix issues in api_client's setup.py.
@@ -6,8 +6,10 @@ import os
import shutil
import subprocess
+from distutils.command.build_py import build_py
+
+from setuptools import find_packages
from setuptools import setup
-from setuptools.command.develop import develop
from setuptools.command.sdist import sdist
THIS_DIRECTORY = os.path.dirname(os.path.realpath(__file__))
@@ -31,6 +33,11 @@ def get_config():
return config
+# TODO(user): instead of being tightly coupled with the source files of the
+# rest of GRR, we should introduce a separate package with compiled protobufs,
+# that we can reuse (i.e. grr-response-proto). Compiling the protos here
+# and doing the create_package_file() trickery and grr_api_client/__init__.py
+# hack will all be unneeded then.
def compile_protos():
"""Builds necessary assets from sources.
@@ -60,6 +67,13 @@ def compile_protos():
See grr_api_client/__init__.py for the sys.path modification code.
"""
+ # Only compile protobufs if we're inside GRR source tree.
+ if (not os.path.exists(
+ os.path.join(THIS_DIRECTORY, "..", "..", "makefile.py")) or
+ not os.path.exists(
+ os.path.join(THIS_DIRECTORY, "..", "..", "..", "grr"))):
+ return
+
# Clean and recompile the protobufs.
protos_out = os.path.join(THIS_DIRECTORY, "grr_api_client", "proto")
try:
@@ -90,6 +104,14 @@ def create_package_file(*dest):
pass
+class Build(build_py):
+
+ def find_all_modules(self):
+ compile_protos()
+ self.packages = find_packages()
+ return build_py.find_all_modules(self)
+
+
class Sdist(sdist):
"""Build sdist."""
@@ -102,17 +124,6 @@ class Sdist(sdist):
shutil.copy(
os.path.join(THIS_DIRECTORY, "../../version.ini"), sdist_version_ini)
- def run(self):
- compile_protos()
- sdist.run(self)
-
-
-class Develop(develop):
-
- def run(self):
- compile_protos()
- develop.run(self)
-
VERSION = get_config()
@@ -123,25 +134,10 @@ setup_args = dict(
license="Apache License, Version 2.0",
url="https://github.com/google/grr/tree/master/api_client/python",
cmdclass={
- "develop": Develop,
+ "build_py": Build,
"sdist": Sdist,
},
- packages=[
- # TODO(user): this is error-prone, as we have to keep this list
- # in sync with the proto files we have. Unfortunately at this point
- # in setup.py there's no way for us to know what packages will be
- # generated by the proto compiler.
- "grr_api_client",
- "grr_api_client.connectors",
- "grr_api_client.proto",
- "grr_api_client.proto.grr",
- "grr_api_client.proto.grr.client",
- "grr_api_client.proto.grr.proto",
- "grr_api_client.proto.grr.client.components",
- "grr_api_client.proto.grr.client.components.chipsec_support",
- "grr_api_client.proto.grr.client.components.rekall_support",
- "grr_api_client.proto.grr.client.components.chipsec_support.actions"
- ],
+ packages=find_packages(),
entry_points={
"console_scripts": [
"grr_api_shell = grr_api_client.api_shell:main",
