The imports/lifestream/__init__.py file has late imports that trigger flake8 E402 warnings.
Current situation
The imports at the bottom of __init__.py must come after the testing mode check:
if not os.environ.get('LIFESTREAM_TESTING'):
setup_logging()
# These trigger E402
from .db import EntryStore
from .foursquare_api import FoursquareAPI
from .utils import ...
These are currently suppressed with # noqa: F401, E402 comments.
Why it's this way
The re-exports provide backward compatibility - scripts do from lifestream import EntryStore etc.
The testing check needs to run before any submodule imports to prevent logging setup during tests.
Potential solutions
- Lazy imports: Use
__getattr__ to defer imports until accessed
- Explicit imports in scripts: Update all scripts to import from submodules directly (
from lifestream.db import EntryStore)
- Separate testing setup: Move testing detection to a separate bootstrap module
Impact
- Low priority - current solution works
- Would improve code structure and remove noqa comments
The
imports/lifestream/__init__.pyfile has late imports that trigger flake8 E402 warnings.Current situation
The imports at the bottom of
__init__.pymust come after the testing mode check:These are currently suppressed with
# noqa: F401, E402comments.Why it's this way
The re-exports provide backward compatibility - scripts do
from lifestream import EntryStoreetc.The testing check needs to run before any submodule imports to prevent logging setup during tests.
Potential solutions
__getattr__to defer imports until accessedfrom lifestream.db import EntryStore)Impact