From f109b0eab890409832954815119b326bcd8f544a Mon Sep 17 00:00:00 2001 From: Danny Hermes Date: Fri, 16 Sep 2016 10:45:00 -0700 Subject: [PATCH] Removing pubsub and logging as namespace packages. Fixes #2258. --- google/cloud/logging/__init__.py | 16 ++++++++++------ google/cloud/logging/_gax.py | 4 ++-- google/cloud/logging/client.py | 8 ++------ google/cloud/logging/connection.py | 4 ++-- google/cloud/logging/logger.py | 4 ++-- google/cloud/pubsub/__init__.py | 14 ++++++++------ setup.py | 2 -- unit_tests/logging/test__gax.py | 3 ++- unit_tests/logging/test_client.py | 3 ++- unit_tests/logging/test_connection.py | 3 ++- unit_tests/logging/test_logger.py | 3 ++- 11 files changed, 34 insertions(+), 30 deletions(-) diff --git a/google/cloud/logging/__init__.py b/google/cloud/logging/__init__.py index 62075824f6378..fd1214fc11e90 100644 --- a/google/cloud/logging/__init__.py +++ b/google/cloud/logging/__init__.py @@ -14,9 +14,13 @@ """Google Stackdriver Logging API wrapper.""" -try: - import pkg_resources - pkg_resources.declare_namespace(__name__) -except ImportError: - import pkgutil - __path__ = pkgutil.extend_path(__path__, __name__) + +from google.cloud.logging.client import Client +from google.cloud.logging.connection import Connection + + +SCOPE = Connection.SCOPE +ASCENDING = 'timestamp asc' +"""Query string to order by ascending timestamps.""" +DESCENDING = 'timestamp desc' +"""Query string to order by decending timestamps.""" diff --git a/google/cloud/logging/_gax.py b/google/cloud/logging/_gax.py index d84a58047ca38..8f6c76572cf10 100644 --- a/google/cloud/logging/_gax.py +++ b/google/cloud/logging/_gax.py @@ -58,8 +58,8 @@ def list_entries(self, projects, filter_='', order_by='', https://cloud.google.com/logging/docs/view/advanced_filters :type order_by: str - :param order_by: One of :data:`~google.cloud.logging.client.ASCENDING` - or :data:`~google.cloud.logging.client.DESCENDING`. + :param order_by: One of :data:`~google.cloud.logging.ASCENDING` + or :data:`~google.cloud.logging.DESCENDING`. :type page_size: int :param page_size: maximum number of entries to return, If not passed, diff --git a/google/cloud/logging/client.py b/google/cloud/logging/client.py index 50476f74959ac..487b406bf92e3 100644 --- a/google/cloud/logging/client.py +++ b/google/cloud/logging/client.py @@ -50,10 +50,6 @@ _DISABLE_GAX = os.getenv(DISABLE_GRPC, False) _USE_GAX = _HAVE_GAX and not _DISABLE_GAX -ASCENDING = 'timestamp asc' -"""Query string to order by ascending timestamps.""" -DESCENDING = 'timestamp desc' -"""Query string to order by decending timestamps.""" class Client(JSONClient): @@ -177,8 +173,8 @@ def list_entries(self, projects=None, filter_=None, order_by=None, https://cloud.google.com/logging/docs/view/advanced_filters :type order_by: str - :param order_by: One of :data:`~google.cloud.logging.client.ASCENDING` - or :data:`~google.cloud.logging.client.DESCENDING`. + :param order_by: One of :data:`~google.cloud.logging.ASCENDING` + or :data:`~google.cloud.logging.DESCENDING`. :type page_size: int :param page_size: maximum number of entries to return, If not passed, diff --git a/google/cloud/logging/connection.py b/google/cloud/logging/connection.py index dc0c95a0a976e..fcfc0d13054cc 100644 --- a/google/cloud/logging/connection.py +++ b/google/cloud/logging/connection.py @@ -77,8 +77,8 @@ def list_entries(self, projects, filter_=None, order_by=None, https://cloud.google.com/logging/docs/view/advanced_filters :type order_by: str - :param order_by: One of :data:`~google.cloud.logging.client.ASCENDING` - or :data:`~google.cloud.logging.client.DESCENDING`. + :param order_by: One of :data:`~google.cloud.logging.ASCENDING` + or :data:`~google.cloud.logging.DESCENDING`. :type page_size: int :param page_size: maximum number of entries to return, If not passed, diff --git a/google/cloud/logging/logger.py b/google/cloud/logging/logger.py index 031a21053ff27..28c9ae293329c 100644 --- a/google/cloud/logging/logger.py +++ b/google/cloud/logging/logger.py @@ -289,8 +289,8 @@ def list_entries(self, projects=None, filter_=None, order_by=None, https://cloud.google.com/logging/docs/view/advanced_filters :type order_by: string - :param order_by: One of :data:`~google.cloud.logging.client.ASCENDING` - or :data:`~google.cloud.logging.client.DESCENDING`. + :param order_by: One of :data:`~google.cloud.logging.ASCENDING` + or :data:`~google.cloud.logging.DESCENDING`. :type page_size: int :param page_size: maximum number of entries to return, If not passed, diff --git a/google/cloud/pubsub/__init__.py b/google/cloud/pubsub/__init__.py index 16e8df626462c..7eebf9a5f8825 100644 --- a/google/cloud/pubsub/__init__.py +++ b/google/cloud/pubsub/__init__.py @@ -23,9 +23,11 @@ subscription (either pull or push) to a topic. """ -try: - import pkg_resources - pkg_resources.declare_namespace(__name__) -except ImportError: - import pkgutil - __path__ = pkgutil.extend_path(__path__, __name__) + +from google.cloud.pubsub.client import Client +from google.cloud.pubsub.connection import Connection +from google.cloud.pubsub.subscription import Subscription +from google.cloud.pubsub.topic import Topic + + +SCOPE = Connection.SCOPE diff --git a/setup.py b/setup.py index 7010d87b06859..e7d265b362df3 100644 --- a/setup.py +++ b/setup.py @@ -44,8 +44,6 @@ namespace_packages=[ 'google', 'google.cloud', - 'google.cloud.logging', - 'google.cloud.pubsub', ], packages=find_packages(), license='Apache 2.0', diff --git a/unit_tests/logging/test__gax.py b/unit_tests/logging/test__gax.py index a9e519bf5b4e4..13880bfed1b1b 100644 --- a/unit_tests/logging/test__gax.py +++ b/unit_tests/logging/test__gax.py @@ -51,8 +51,9 @@ def test_ctor(self): def test_list_entries_no_paging(self): from google.gax import INITIAL_PAGE - from google.cloud.logging.client import DESCENDING + from google.cloud.logging import DESCENDING from unit_tests._testing import _GAXPageIterator + TOKEN = 'TOKEN' TEXT = 'TEXT' response = _GAXPageIterator( diff --git a/unit_tests/logging/test_client.py b/unit_tests/logging/test_client.py index 5f938436efa92..dfb75ef70ef78 100644 --- a/unit_tests/logging/test_client.py +++ b/unit_tests/logging/test_client.py @@ -234,10 +234,11 @@ def test_list_entries_defaults(self): ([self.PROJECT], None, None, None, None)) def test_list_entries_explicit(self): - from google.cloud.logging.client import DESCENDING + from google.cloud.logging import DESCENDING from google.cloud.logging.entries import ProtobufEntry from google.cloud.logging.entries import StructEntry from google.cloud.logging.logger import Logger + PROJECT1 = 'PROJECT1' PROJECT2 = 'PROJECT2' FILTER = 'logName:LOGNAME' diff --git a/unit_tests/logging/test_connection.py b/unit_tests/logging/test_connection.py index cd6668370049c..ed8c14c42a072 100644 --- a/unit_tests/logging/test_connection.py +++ b/unit_tests/logging/test_connection.py @@ -97,7 +97,8 @@ def test_list_entries_no_paging(self): self.assertEqual(conn._called_with['data'], SENT) def test_list_entries_w_paging(self): - from google.cloud.logging.client import DESCENDING + from google.cloud.logging import DESCENDING + PROJECT1 = 'PROJECT1' PROJECT2 = 'PROJECT2' TIMESTAMP = self._make_timestamp() diff --git a/unit_tests/logging/test_logger.py b/unit_tests/logging/test_logger.py index 3e3c3e25a8ade..1f882d85add87 100644 --- a/unit_tests/logging/test_logger.py +++ b/unit_tests/logging/test_logger.py @@ -364,7 +364,8 @@ def test_list_entries_defaults(self): self.assertEqual(client._listed, LISTED) def test_list_entries_explicit(self): - from google.cloud.logging.client import DESCENDING + from google.cloud.logging import DESCENDING + PROJECT1 = 'PROJECT1' PROJECT2 = 'PROJECT2' FILTER = 'resource.type:global'