Skip to content

Commit 6faf161

Browse files
committed
Converting almost all packages to namespace packages.
As a result, the module objects for those packages can no longer contain members. Hence the following is no longer possible: >>> from google.cloud import storage >>> client = storage.Client() The "_generated" packages have not been converted to namespace packages and neither have "google.cloud.logging.handlers" nor "google.cloud.logging.handlers.transports". In addition, some members of "google.cloud.logging" have been moved into "google.cloud.logging.client" in order to be importable. Finally, the unit tests all pass at this commit, but `tox` fails to run them: the namespace imports appear broken to `tox` even though they aren't broken to the `virtualenv` for the given `tox` environment.
1 parent 0bb8303 commit 6faf161

File tree

27 files changed

+134
-129
lines changed

27 files changed

+134
-129
lines changed

google/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,10 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
15+
try:
16+
import pkg_resources
17+
pkg_resources.declare_namespace(__name__)
18+
except ImportError:
19+
import pkgutil
20+
__path__ = pkgutil.extend_path(__path__, __name__)

google/cloud/__init__.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414

1515
"""Google Cloud API access in idiomatic Python."""
1616

17-
from pkg_resources import get_distribution
18-
19-
__version__ = get_distribution('google-cloud').version
17+
try:
18+
import pkg_resources
19+
pkg_resources.declare_namespace(__name__)
20+
except ImportError:
21+
import pkgutil
22+
__path__ = pkgutil.extend_path(__path__, __name__)

google/cloud/bigquery/__init__.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,9 @@
2121
- :class:`google.cloud.bigquery.table.Table` represents a single "relation".
2222
"""
2323

24-
from google.cloud.bigquery.client import Client
25-
from google.cloud.bigquery.connection import Connection
26-
from google.cloud.bigquery.dataset import AccessGrant
27-
from google.cloud.bigquery.dataset import Dataset
28-
from google.cloud.bigquery.schema import SchemaField
29-
from google.cloud.bigquery.table import Table
30-
31-
32-
SCOPE = Connection.SCOPE
24+
try:
25+
import pkg_resources
26+
pkg_resources.declare_namespace(__name__)
27+
except ImportError:
28+
import pkgutil
29+
__path__ = pkgutil.extend_path(__path__, __name__)

google/cloud/bigtable/__init__.py

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,9 @@
1515
"""Google Cloud Bigtable API package."""
1616

1717

18-
from google.cloud.bigtable.client import Client
19-
20-
21-
_ERR_MSG = """\
22-
gRPC is required for using the Cloud Bigtable API, but
23-
importing the gRPC library (grpcio in PyPI) has failed.
24-
25-
As of June 2016, grpcio is only supported in Python 2.7,
26-
which unfortunately means the Cloud Bigtable API isn't
27-
available if you're using Python 3 or Python < 2.7.
28-
29-
If you're using Python 2.7 and importing / installing
30-
grpcio has failed, this likely means you have a non-standard version
31-
of Python installed. Check http://grpc.io if you're
32-
having trouble installing the grpcio package.
33-
"""
34-
3518
try:
36-
import grpc
37-
except ImportError as exc: # pragma: NO COVER
38-
raise ImportError(_ERR_MSG, exc)
19+
import pkg_resources
20+
pkg_resources.declare_namespace(__name__)
21+
except ImportError:
22+
import pkgutil
23+
__path__ = pkgutil.extend_path(__path__, __name__)

google/cloud/datastore/__init__.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,9 @@
5050
when race conditions may occur.
5151
"""
5252

53-
from google.cloud.datastore.batch import Batch
54-
from google.cloud.datastore.connection import Connection
55-
from google.cloud.datastore.client import Client
56-
from google.cloud.datastore.entity import Entity
57-
from google.cloud.datastore.key import Key
58-
from google.cloud.datastore.query import Query
59-
from google.cloud.datastore.transaction import Transaction
60-
61-
62-
SCOPE = Connection.SCOPE
53+
try:
54+
import pkg_resources
55+
pkg_resources.declare_namespace(__name__)
56+
except ImportError:
57+
import pkgutil
58+
__path__ = pkgutil.extend_path(__path__, __name__)

google/cloud/dns/__init__.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,9 @@
2323
deleting resource record sets) to a zone.
2424
"""
2525

26-
from google.cloud.dns.zone import Changes
27-
from google.cloud.dns.client import Client
28-
from google.cloud.dns.connection import Connection
29-
from google.cloud.dns.zone import ManagedZone
30-
from google.cloud.dns.resource_record_set import ResourceRecordSet
31-
32-
33-
SCOPE = Connection.SCOPE
26+
try:
27+
import pkg_resources
28+
pkg_resources.declare_namespace(__name__)
29+
except ImportError:
30+
import pkgutil
31+
__path__ = pkgutil.extend_path(__path__, __name__)

google/cloud/error_reporting/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,9 @@
1414

1515
"""Client library for Stackdriver Error Reporting"""
1616

17-
from google.cloud.error_reporting.client import Client
17+
try:
18+
import pkg_resources
19+
pkg_resources.declare_namespace(__name__)
20+
except ImportError:
21+
import pkgutil
22+
__path__ = pkgutil.extend_path(__path__, __name__)

google/cloud/language/__init__.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414

1515
"""Client library for Google Cloud Natural Language API."""
1616

17-
from google.cloud.language.client import Client
18-
from google.cloud.language.document import Document
19-
from google.cloud.language.document import Encoding
17+
try:
18+
import pkg_resources
19+
pkg_resources.declare_namespace(__name__)
20+
except ImportError:
21+
import pkgutil
22+
__path__ = pkgutil.extend_path(__path__, __name__)

google/cloud/logging/__init__.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@
1414

1515
"""Google Stackdriver Logging API wrapper."""
1616

17-
from google.cloud.logging.client import Client
18-
from google.cloud.logging.connection import Connection
19-
20-
21-
SCOPE = Connection.SCOPE
22-
ASCENDING = 'timestamp asc'
23-
DESCENDING = 'timestamp desc'
17+
try:
18+
import pkg_resources
19+
pkg_resources.declare_namespace(__name__)
20+
except ImportError:
21+
import pkgutil
22+
__path__ = pkgutil.extend_path(__path__, __name__)

google/cloud/logging/_gax.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ def list_entries(self, projects, filter_='', order_by='',
5656
https://cloud.google.com/logging/docs/view/advanced_filters
5757
5858
:type order_by: str
59-
:param order_by: One of :data:`google.cloud.logging.ASCENDING` or
60-
:data:`google.cloud.logging.DESCENDING`.
59+
:param order_by: One of :data:`~google.cloud.logging.client.ASCENDING`
60+
or :data:`~google.cloud.logging.client.DESCENDING`.
6161
6262
:type page_size: int
6363
:param page_size: maximum number of entries to return, If not passed,

0 commit comments

Comments
 (0)