-
-
Notifications
You must be signed in to change notification settings - Fork 608
/
scope.py
61 lines (43 loc) · 1.9 KB
/
scope.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# Copyright 2015 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).
from dataclasses import dataclass
from typing import Optional, Type, cast
from pants.option.option_value_container import OptionValueContainer
GLOBAL_SCOPE = ""
GLOBAL_SCOPE_CONFIG_SECTION = "GLOBAL"
def normalize_scope(scope: str):
return scope.lower().replace("-", "_")
@dataclass(frozen=True)
class Scope:
"""An options scope."""
scope: str
@dataclass(frozen=True, order=True)
class ScopeInfo:
"""Information about a scope."""
scope: str
optionable_cls: Optional[Type] = None
# A ScopeInfo may have a deprecated_scope (from its associated optionable_cls), which represents a
# previous/deprecated name for a current/non-deprecated ScopeInfo. It may also be directly
# deprecated via this `removal_version`, which allows for the deprecation of an entire scope,
# including that of a SubsystemDependency (ie, deprecation of a dependency on a scoped Subsystem).
removal_version: Optional[str] = None
removal_hint: Optional[str] = None
@property
def description(self) -> str:
return cast(str, self._optionable_cls_attr("get_description", lambda: "")())
@property
def deprecated_scope(self) -> Optional[str]:
return cast(Optional[str], self._optionable_cls_attr("deprecated_options_scope"))
@property
def deprecated_scope_removal_version(self) -> Optional[str]:
return cast(
Optional[str],
self._optionable_cls_attr("deprecated_options_scope_removal_version"),
)
def _optionable_cls_attr(self, name: str, default=None):
return getattr(self.optionable_cls, name) if self.optionable_cls else default
@dataclass(frozen=True)
class ScopedOptions:
"""A wrapper around options selected for a particular Scope."""
scope: Scope
options: OptionValueContainer