Simplify public symbol exports

Inspired by tulip, have every module define a __all__ list and import *
from the top-level module.

Rename transport.set_defaults() since we don't want this to be a
top-level set_defaults() function as there may be multiple.

Also, rather than configuring flake8 to allow star imports, just exclude
the __init__.py files from flake8 checks.
This commit is contained in:
Mark McLoughlin 2013-06-23 16:41:50 +01:00
parent d31ae442ca
commit 03aafcb49c
11 changed files with 59 additions and 44 deletions

View File

@ -13,43 +13,9 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from oslo.messaging import exceptions from .exceptions import *
from oslo.messaging.rpc import client from .rpc import *
from oslo.messaging.rpc import dispatcher as rpc_dispatcher from .serializer import *
from oslo.messaging.rpc import server as rpc_server from .server import *
from oslo.messaging import serializer from .target import *
from oslo.messaging import server from .transport import *
from oslo.messaging import target
from oslo.messaging import transport
get_transport = transport.get_transport
Target = target.Target
RPCClient = client.RPCClient
MessageHandlingServer = server.MessageHandlingServer
get_rpc_server = rpc_server.get_rpc_server
RPCDispatcher = rpc_dispatcher.RPCDispatcher
Serializer = serializer.Serializer
#
# Exceptions
#
MessagingException = exceptions.MessagingException
MessagingTimeout = exceptions.MessagingTimeout
DriverLoadFailure = transport.DriverLoadFailure
InvalidTransportURL = transport.InvalidTransportURL
RPCVersionCapError = client.RPCVersionCapError
ClientSendError = client.ClientSendError
MessagingServerError = server.MessagingServerError
ExecutorLoadFailure = server.ExecutorLoadFailure
ServerListenError = server.ServerListenError
RPCDispatcherError = rpc_dispatcher.RPCDispatcherError
NoSuchMethod = rpc_dispatcher.NoSuchMethod
UnsupportedVersion = rpc_dispatcher.UnsupportedVersion

View File

@ -13,6 +13,8 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
__all__ = ['MessagingException', 'MessagingTimeout']
class MessagingException(Exception): class MessagingException(Exception):
"""Base class for exceptions.""" """Base class for exceptions."""

View File

@ -12,3 +12,18 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
__all__ = [
'ClientSendError',
'NoSuchMethod',
'RPCClient',
'RPCDispatcher',
'RPCDispatcherError',
'RPCVersionCapError',
'UnsupportedVersion',
'get_rpc_server',
]
from client import *
from dispatcher import *
from server import *

View File

@ -16,6 +16,12 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
__all__ = [
'ClientSendError',
'RPCClient',
'RPCVersionCapError',
]
import inspect import inspect
import logging import logging

View File

@ -16,6 +16,13 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
__all__ = [
'NoSuchMethod',
'RPCDispatcher',
'RPCDispatcherError',
'UnsupportedVersion',
]
import logging import logging
from oslo.messaging import _utils as utils from oslo.messaging import _utils as utils

View File

@ -13,6 +13,8 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
__all__ = ['get_rpc_server']
from oslo.messaging.rpc import dispatcher as rpc_dispatcher from oslo.messaging.rpc import dispatcher as rpc_dispatcher
from oslo.messaging import server as msg_server from oslo.messaging import server as msg_server

View File

@ -12,6 +12,8 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
__all__ = ['Serializer', 'NoOpSerializer']
"""Provides the definition of a message serialization handler""" """Provides the definition of a message serialization handler"""
import abc import abc

View File

@ -16,6 +16,13 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
__all__ = [
'ExecutorLoadFailure',
'MessageHandlingServer',
'MessagingServerError',
'ServerListenError',
]
import logging import logging
from stevedore import driver from stevedore import driver

View File

@ -16,6 +16,14 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
__all__ = [
'DriverLoadFailure',
'InvalidTransportURL',
'Transport',
'get_transport',
'set_transport_defaults',
]
import urlparse import urlparse
from oslo.config import cfg from oslo.config import cfg
@ -42,7 +50,7 @@ _transport_opts = [
] ]
def set_defaults(control_exchange): def set_transport_defaults(control_exchange):
"""Set defaults for messaging transport configuration options. """Set defaults for messaging transport configuration options.
:param control_exchange: the default exchange under which topics are scoped :param control_exchange: the default exchange under which topics are scoped

View File

@ -209,12 +209,12 @@ class TestSetDefaults(test_utils.BaseTestCase):
def setUp(self): def setUp(self):
super(TestSetDefaults, self).setUp(conf=cfg.ConfigOpts()) super(TestSetDefaults, self).setUp(conf=cfg.ConfigOpts())
self.useFixture(_SetDefaultsFixture(transport.set_defaults, self.useFixture(_SetDefaultsFixture(messaging.set_transport_defaults,
transport._transport_opts, transport._transport_opts,
'control_exchange')) 'control_exchange'))
def test_set_default_control_exchange(self): def test_set_default_control_exchange(self):
transport.set_defaults(control_exchange='foo') messaging.set_transport_defaults(control_exchange='foo')
self.mox.StubOutWithMock(driver, 'DriverManager') self.mox.StubOutWithMock(driver, 'DriverManager')
invoke_kwds = mox.ContainsKeyValue('default_exchange', 'foo') invoke_kwds = mox.ContainsKeyValue('default_exchange', 'foo')

View File

@ -20,5 +20,5 @@ commands = {posargs}
[flake8] [flake8]
show-source = True show-source = True
exclude = .tox,dist,doc,*.egg,build exclude = .tox,dist,doc,*.egg,build,__init__.py
builtins = _ builtins = _