Coverage for /Users/davegaeddert/Development/dropseed/plain/plain/plain/runtime/__init__.py: 84%

1 import importlib.metadata

2 import sys

3 from importlib.metadata import entry_points

4 from pathlib import Path

5

6 from .user_settings import Settings

7

8 try:

9 __version__ = importlib.metadata.version("plain")

10 except importlib.metadata.PackageNotFoundError:

11 __version__ = "dev"

12

13

14# Made available without setup or settings

15 APP_PATH = Path.cwd() / "app"

16

17# from plain.runtime import settings

18 settings = Settings()

19

20

21 class AppPathNotFound(RuntimeError):

22 pass

23

24

25 def 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 """

30

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()()

34

35 from plain.logs import configure_logging

36 from plain.packages import packages

37

38 if not APP_PATH.exists():

39 raise AppPathNotFound(

40 "No app directory found. Are you sure you're in a Plain project?"

41 )

42

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())

48

49 configure_logging(settings.LOGGING)

50

51 packages.populate(settings.INSTALLED_PACKAGES)

52

53

54 __all__ = [

55 "setup",

56 "settings",

57 "APP_PATH",

58 "__version__",

59]