From 61d9db9e7255d3eb45fc13e5e88780aa51991237 Mon Sep 17 00:00:00 2001 From: Dmitri Bogomolov <4glitch@gmail.com> Date: Mon, 15 Nov 2021 16:37:02 +0200 Subject: [PATCH] Remove import from outer package in messagetypes, use dotted imports --- src/messagetypes/__init__.py | 25 +++++++++++-------------- src/messagetypes/message.py | 8 ++++++-- src/messagetypes/vote.py | 2 +- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/messagetypes/__init__.py b/src/messagetypes/__init__.py index 774f8932..b9ddd1e9 100644 --- a/src/messagetypes/__init__.py +++ b/src/messagetypes/__init__.py @@ -1,18 +1,10 @@ import logging -from importlib import import_module -from os import listdir, path -from pybitmessage import paths +from importlib import import_module logger = logging.getLogger('default') -class MsgBase(object): # pylint: disable=too-few-public-methods - """Base class for message types""" - def __init__(self): - self.data = {"": type(self).__name__.lower()} - - def constructObject(data): """Constructing an object""" whitelist = ["message"] @@ -40,14 +32,19 @@ def constructObject(data): return returnObj -if paths.frozen is not None: - import message # noqa : F401 flake8: disable=unused-import - import vote # noqa : F401 flake8: disable=unused-import +try: + from pybitmessage import paths +except ImportError: + paths = None + +if paths and paths.frozen is not None: + from . import message, vote # noqa: F401 flake8: disable=unused-import else: - for mod in listdir(path.dirname(__file__)): + import os + for mod in os.listdir(os.path.dirname(__file__)): if mod == "__init__.py": continue - splitted = path.splitext(mod) + splitted = os.path.splitext(mod) if splitted[1] != ".py": continue try: diff --git a/src/messagetypes/message.py b/src/messagetypes/message.py index a3ceafe5..245c753f 100644 --- a/src/messagetypes/message.py +++ b/src/messagetypes/message.py @@ -1,10 +1,14 @@ import logging -from pybitmessage.messagetypes import MsgBase - logger = logging.getLogger('default') +class MsgBase(object): # pylint: disable=too-few-public-methods + """Base class for message types""" + def __init__(self): + self.data = {"": type(self).__name__.lower()} + + class Message(MsgBase): """Encapsulate a message""" # pylint: disable=attribute-defined-outside-init diff --git a/src/messagetypes/vote.py b/src/messagetypes/vote.py index b494c15d..b3e96513 100644 --- a/src/messagetypes/vote.py +++ b/src/messagetypes/vote.py @@ -1,6 +1,6 @@ import logging -from pybitmessage.messagetypes import MsgBase +from .message import MsgBase logger = logging.getLogger('default')