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

25 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-10-17 21:27 -0500

1import importlib.metadata 

2import sys 

3from importlib.metadata import entry_points 

4from pathlib import Path 

5 

6from .user_settings import Settings 

7 

8try: 

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

10except importlib.metadata.PackageNotFoundError: 

11 __version__ = "dev" 

12 

13 

14# Made available without setup or settings 

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

16 

17# from plain.runtime import settings 

18settings = Settings() 

19 

20 

21class AppPathNotFound(RuntimeError): 

22 pass 

23 

24 

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

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]