Skip to content

Commit

Permalink
Un-namespace Python packages
Browse files Browse the repository at this point in the history
Setuptools was updated and our hacky namespace-package-chickens came
back to roost. This removes the unsupported namespace package hacks.
  • Loading branch information
soltanmm-google committed Dec 12, 2016
1 parent 4603a1c commit fb261bf
Show file tree
Hide file tree
Showing 27 changed files with 29 additions and 122 deletions.
2 changes: 1 addition & 1 deletion examples/python/multiplex/run_codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

"""Generates protocol messages and gRPC stubs."""

from grpc.tools import protoc
from grpc_tools import protoc

protoc.main(
(
Expand Down
2 changes: 1 addition & 1 deletion examples/python/route_guide/run_codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

"""Runs protoc with the gRPC plugin to generate messages and gRPC stubs."""

from grpc.tools import protoc
from grpc_tools import protoc

protoc.main(
(
Expand Down
30 changes: 0 additions & 30 deletions src/python/grpcio_health_checking/grpc/__init__.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

import grpc

from grpc.health.v1 import health_pb2
from grpc_health.v1 import health_pb2


class HealthServicer(health_pb2.HealthServicer):
Expand Down
4 changes: 2 additions & 2 deletions src/python/grpcio_health_checking/health_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def run(self):
if os.path.isfile(HEALTH_PROTO):
shutil.copyfile(
HEALTH_PROTO,
os.path.join(ROOT_DIR, 'grpc/health/v1/health.proto'))
os.path.join(ROOT_DIR, 'grpc_health/v1/health.proto'))


class BuildPackageProtos(setuptools.Command):
Expand All @@ -74,5 +74,5 @@ def run(self):
# directory is provided as an 'include' directory. We assume it's the '' key
# to `self.distribution.package_dir` (and get a key error if it's not
# there).
from grpc.tools import command
from grpc_tools import command
command.build_package_protos(self.distribution.package_dir[''])
1 change: 0 additions & 1 deletion src/python/grpcio_health_checking/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
license='3-clause BSD',
package_dir=PACKAGE_DIRECTORIES,
packages=setuptools.find_packages('.'),
namespace_packages=['grpc'],
install_requires=INSTALL_REQUIRES,
setup_requires=SETUP_REQUIRES,
cmdclass=COMMAND_CLASS
Expand Down
30 changes: 0 additions & 30 deletions src/python/grpcio_reflection/grpc/__init__.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
from google.protobuf import descriptor_pb2
from google.protobuf import descriptor_pool

from grpc.reflection.v1alpha import reflection_pb2
from grpc_reflection.v1alpha import reflection_pb2

_POOL = descriptor_pool.Default()

Expand Down
4 changes: 2 additions & 2 deletions src/python/grpcio_reflection/reflection_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def run(self):
if os.path.isfile(HEALTH_PROTO):
shutil.copyfile(
HEALTH_PROTO,
os.path.join(ROOT_DIR, 'grpc/reflection/v1alpha/reflection.proto'))
os.path.join(ROOT_DIR, 'grpc_reflection/v1alpha/reflection.proto'))


class BuildPackageProtos(setuptools.Command):
Expand All @@ -74,5 +74,5 @@ def run(self):
# directory is provided as an 'include' directory. We assume it's the '' key
# to `self.distribution.package_dir` (and get a key error if it's not
# there).
from grpc.tools import command
from grpc_tools import command
command.build_package_protos(self.distribution.package_dir[''])
1 change: 0 additions & 1 deletion src/python/grpcio_reflection/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
license='3-clause BSD',
package_dir=PACKAGE_DIRECTORIES,
packages=setuptools.find_packages('.'),
namespace_packages=['grpc'],
install_requires=INSTALL_REQUIRES,
setup_requires=SETUP_REQUIRES,
cmdclass=COMMAND_CLASS
Expand Down
4 changes: 2 additions & 2 deletions src/python/grpcio_tests/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def finalize_options(self):
pass

def run(self):
import grpc.tools.protoc as protoc
import grpc_tools.protoc as protoc

include_regex = re.compile(self.include)
exclude_regex = re.compile(self.exclude) if self.exclude else None
Expand All @@ -116,7 +116,7 @@ def run(self):
# but we currently have name conflicts in src/proto
for path in paths:
command = [
'grpc.tools.protoc',
'grpc_tools.protoc',
'-I {}'.format(PROTO_STEM),
'--python_out={}'.format(PROTO_STEM),
'--grpc_python_out={}'.format(PROTO_STEM),
Expand Down
4 changes: 2 additions & 2 deletions src/python/grpcio_tests/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

import setuptools

import grpc.tools.command
import grpc_tools.command

PY3 = sys.version_info.major == 3

Expand Down Expand Up @@ -68,7 +68,7 @@
# Run `preprocess` *before* doing any packaging!
'preprocess': commands.GatherProto,

'build_package_protos': grpc.tools.command.BuildPackageProtos,
'build_package_protos': grpc_tools.command.BuildPackageProtos,
'build_py': commands.BuildPy,
'run_interop': commands.RunInterop,
'test_lite': commands.TestLite
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

"""Tests of grpc.health.v1.health."""
"""Tests of grpc_health.v1.health."""

import unittest

import grpc
from grpc.framework.foundation import logging_pool
from grpc.health.v1 import health
from grpc.health.v1 import health_pb2
from grpc_health.v1 import health
from grpc_health.v1 import health_pb2

from tests.unit.framework.common import test_constants

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import unittest

import grpc
from grpc.tools import protoc
from grpc_tools import protoc
from tests.unit.framework.common import test_constants

_MESSAGES_IMPORT = b'import "messages.proto";'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

"""Tests of grpc.reflection.v1alpha.reflection."""
"""Tests of grpc_reflection.v1alpha.reflection."""

import unittest

import grpc
from grpc.framework.foundation import logging_pool
from grpc.reflection.v1alpha import reflection
from grpc.reflection.v1alpha import reflection_pb2
from grpc_reflection.v1alpha import reflection
from grpc_reflection.v1alpha import reflection_pb2

from google.protobuf import descriptor_pool
from google.protobuf import descriptor_pb2
Expand Down
30 changes: 0 additions & 30 deletions tools/distrib/python/grpcio_tools/grpc/__init__.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

from libc cimport stdlib

cdef extern from "grpc/tools/main.h":
cdef extern from "grpc_tools/main.h":
int protoc_main(int argc, char *argv[])

def run_main(list args not None):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

import setuptools

from grpc.tools import protoc
from grpc_tools import protoc


def build_package_protos(package_root):
Expand All @@ -45,7 +45,7 @@ def build_package_protos(package_root):
proto_files.append(os.path.abspath(os.path.join(root, filename)))

well_known_protos_include = pkg_resources.resource_filename(
'grpc.tools', '_proto')
'grpc_tools', '_proto')

for proto_file in proto_files:
command = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

#include "src/compiler/python_generator.h"

#include "grpc/tools/main.h"
#include "grpc_tools/main.h"

int protoc_main(int argc, char* argv[]) {
google::protobuf::compiler::CommandLineInterface cli;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import pkg_resources
import sys

from grpc.tools import _protoc_compiler
from grpc_tools import _protoc_compiler

def main(command_arguments):
"""Run the protocol buffer compiler with the given command-line arguments.
Expand Down
11 changes: 5 additions & 6 deletions tools/distrib/python/grpcio_tools/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
CC_INCLUDE = os.path.normpath(protoc_lib_deps.CC_INCLUDE)
PROTO_INCLUDE = os.path.normpath(protoc_lib_deps.PROTO_INCLUDE)

GRPC_PYTHON_TOOLS_PACKAGE = 'grpc.tools'
GRPC_PYTHON_TOOLS_PACKAGE = 'grpc_tools'
GRPC_PYTHON_PROTO_RESOURCES_NAME = '_proto'

DEFINE_MACROS = ()
Expand Down Expand Up @@ -154,16 +154,16 @@ def package_data():

def extension_modules():
if BUILD_WITH_CYTHON:
plugin_sources = [os.path.join('grpc', 'tools', '_protoc_compiler.pyx')]
plugin_sources = [os.path.join('grpc_tools', '_protoc_compiler.pyx')]
else:
plugin_sources = [os.path.join('grpc', 'tools', '_protoc_compiler.cpp')]
plugin_sources = [os.path.join('grpc_tools', '_protoc_compiler.cpp')]
plugin_sources += [
os.path.join('grpc', 'tools', 'main.cc'),
os.path.join('grpc_tools', 'main.cc'),
os.path.join('grpc_root', 'src', 'compiler', 'python_generator.cc')] + [
os.path.join(CC_INCLUDE, cc_file)
for cc_file in CC_FILES]
plugin_ext = extension.Extension(
name='grpc.tools._protoc_compiler',
name='grpc_tools._protoc_compiler',
sources=plugin_sources,
include_dirs=[
'.',
Expand All @@ -189,7 +189,6 @@ def extension_modules():
license='3-clause BSD',
ext_modules=extension_modules(),
packages=setuptools.find_packages('.'),
namespace_packages=['grpc'],
install_requires=[
'protobuf>=3.0.0',
'grpcio>={version}'.format(version=grpc_version.VERSION),
Expand Down

0 comments on commit fb261bf

Please sign in to comment.