Coverage for /Users/davegaeddert/Developer/dropseed/plain/plain/plain/runtime/__init__.py: 84%
25 statements
« prev ^ index » next coverage.py v7.6.9, created at 2024-12-23 11:16 -0600
« prev ^ index » next coverage.py v7.6.9, created at 2024-12-23 11:16 -0600
1import importlib.metadata
2import sys
3from importlib.metadata import entry_points
4from pathlib import Path
6from .user_settings import Settings
8try:
9 __version__ = importlib.metadata.version("plain")
10except importlib.metadata.PackageNotFoundError:
11 __version__ = "dev"
14# Made available without setup or settings
15APP_PATH = Path.cwd() / "app"
17# from plain.runtime import settings
18settings = Settings()
21class AppPathNotFound(RuntimeError):
22 pass
25def setup():
26 """
27 Configure the settings (this happens as a side effect of accessing the
28 first setting), configure logging and populate the app registry.
29 """
31 # Packages can hook into the setup process through an entrypoint.
32 for entry_point in entry_points().select(group="plain.setup"):
33 entry_point.load()()
35 from plain.logs import configure_logging
36 from plain.packages import packages
38 if not APP_PATH.exists():
39 raise AppPathNotFound(
40 "No app directory found. Are you sure you're in a Plain project?"
41 )
43 # Automatically put the project dir on the Python path
44 # which doesn't otherwise happen when you run `plain` commands.
45 # This makes "app.<module>" imports and relative imports work.
46 if APP_PATH.parent not in sys.path:
47 sys.path.insert(0, APP_PATH.parent.as_posix())
49 configure_logging(settings.LOGGING)
51 packages.populate(settings.INSTALLED_PACKAGES)
54__all__ = [
55 "setup",
56 "settings",
57 "APP_PATH",
58 "__version__",
59]