'google' namespace package needs a boilerplate '__init__.py' for Python2 compatibility

18 views
Skip to first unread message

Tres Seaver

unread,
Mar 7, 2016, 6:03:59 PM3/7/16
to Google APIs
Otherwise, installing alongside another package using the google namespace can break (right now, protobuf).  The boilerplate can be just a one-liner:

__import__('pkg_resources').declare_namespace(__name__)

If you are trying to support a non-setuptools installation (Why?), then you need a bulkier version:

try:
    import pkg_resources
    pkg_resources.declare_namespace(__name__)
except ImportError:
    import pkgutil
    __path__ = pkgutil.extend_path(__path__, __name__)

Hong

unread,
Mar 16, 2016, 3:34:26 PM3/16/16
to Tres Seaver, Google APIs
Can you send a pull request?

Hong

--
You received this message because you are subscribed to the Google Groups "Google APIs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to googleapis+unsubscribe@googlegroups.com.
To post to this group, send email to googl...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/googleapis/cb15fd0f-5c80-43c5-99d2-f218d366d274%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tres Seaver

unread,
Mar 16, 2016, 4:37:14 PM3/16/16
to Hong, Google APIs
On 03/16/2016 03:34 PM, Hong wrote:
> Can you send a pull request?
>
> Hong
>
> On Mon, Mar 7, 2016 at 3:03 PM, Tres Seaver <tres....@gmail.com
> <mailto:tres....@gmail.com>> wrote:
>
> Otherwise, installing alongside another package using the google namespace
> can break (right now, protobuf). The boilerplate can be just a one-liner:
>
> __import__('pkg_resources').declare_namespace(__name__)
>
> If you are trying to support a non-setuptools installation (Why?), then you
> need a bulkier version:
>
> try: import pkg_resources pkg_resources.declare_namespace(__name__) except
> ImportError: import pkgutil __path__ = pkgutil.extend_path(__path__, __name__)


I already did:

https://github.com/googleapis/googleapis/pull/7


Tres.
--
===================================================================
Tres Seaver +1 540-429-0999 tse...@palladion.com
Palladion Software "Excellence by Design" http://palladion.com
Reply all
Reply to author
Forward
0 new messages