@@ -28,22 +28,14 @@ class AppConfig:
2828 Stores basic configuration Information about the application.
2929 """
3030
31+ app_dir : Path
32+ """Path to the application directory."""
33+
3134 root_dir : Path
3235 """The root directory (as in Python import root)."""
3336
34- app_dir_name : str
35- """The name of the application directory/package."""
36-
3737 app_url_prefix_length : int
38- """The length of the application URL prefix to remove (`len(app_dir_name) + 1`)."""
39-
40- app_dir : Path
41- """Path to the application directory."""
42-
43- # Overriding __init__ and calculating inferred values automatically would serve the
44- # default case well, but it would complicate things if we ever need to support
45- # different application structures (for example an app in tests). So we use
46- # alternative initializers instead.
38+ """The length of the application URL prefix to remove."""
4739
4840 @classmethod
4941 def default (cls ) -> AppConfig :
@@ -53,22 +45,23 @@ def default(cls) -> AppConfig:
5345 Raises:
5446 ValueError: If the application package cannot be determined.
5547 """
48+ # The application directory and the root directory may be different.
5649 caller_package , caller_package_path = cls ._find_app_root ()
50+ root_dir = caller_package_path
5751
5852 if caller_package not in _no_app_package_roots :
59- # Walk up the package hierarchy until we reach the root.
53+ # Walk up the package hierarchy until we reach the actual root directory .
6054 for _ in range (len (caller_package .split ("." ))):
61- caller_package_path = caller_package_path .parent
55+ root_dir = root_dir .parent
6256
6357 len_caller_package = len (caller_package )
6458
6559 result = cls (
66- root_dir = caller_package_path ,
67- app_dir_name = caller_package ,
60+ app_dir = caller_package_path ,
61+ root_dir = root_dir ,
6862 # Support applications that are not wrapped in a Python package.
69- # In that case app_dir_name is "" .
63+ # In that case caller package is an empty string .
7064 app_url_prefix_length = len_caller_package + 1 if len_caller_package > 0 else 0 ,
71- app_dir = caller_package_path / caller_package ,
7265 )
7366 return result
7467
0 commit comments