hyperlight-cocoa 0.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (152) hide show
  1. hyperlight_cocoa-0.1.1/LICENSE +21 -0
  2. hyperlight_cocoa-0.1.1/PKG-INFO +43 -0
  3. hyperlight_cocoa-0.1.1/README.md +4 -0
  4. hyperlight_cocoa-0.1.1/cocoa/cli/__init__.py +14 -0
  5. hyperlight_cocoa-0.1.1/cocoa/cli/arg_types/__init__.py +18 -0
  6. hyperlight_cocoa-0.1.1/cocoa/cli/arg_types/base/__init__.py +8 -0
  7. hyperlight_cocoa-0.1.1/cocoa/cli/arg_types/base/keyword_arg.py +249 -0
  8. hyperlight_cocoa-0.1.1/cocoa/cli/arg_types/base/positional_arg.py +143 -0
  9. hyperlight_cocoa-0.1.1/cocoa/cli/arg_types/data_types/__init__.py +9 -0
  10. hyperlight_cocoa-0.1.1/cocoa/cli/arg_types/data_types/assert_set.py +49 -0
  11. hyperlight_cocoa-0.1.1/cocoa/cli/arg_types/data_types/context.py +16 -0
  12. hyperlight_cocoa-0.1.1/cocoa/cli/arg_types/data_types/env.py +76 -0
  13. hyperlight_cocoa-0.1.1/cocoa/cli/arg_types/data_types/import_file.py +107 -0
  14. hyperlight_cocoa-0.1.1/cocoa/cli/arg_types/data_types/json_data.py +63 -0
  15. hyperlight_cocoa-0.1.1/cocoa/cli/arg_types/data_types/json_file.py +102 -0
  16. hyperlight_cocoa-0.1.1/cocoa/cli/arg_types/data_types/paths.py +124 -0
  17. hyperlight_cocoa-0.1.1/cocoa/cli/arg_types/data_types/pattern.py +129 -0
  18. hyperlight_cocoa-0.1.1/cocoa/cli/arg_types/data_types/raw_file.py +92 -0
  19. hyperlight_cocoa-0.1.1/cocoa/cli/arg_types/data_types/reduce_pattern_type.py +30 -0
  20. hyperlight_cocoa-0.1.1/cocoa/cli/arg_types/operators/__init__.py +3 -0
  21. hyperlight_cocoa-0.1.1/cocoa/cli/arg_types/operators/chain.py +83 -0
  22. hyperlight_cocoa-0.1.1/cocoa/cli/arg_types/operators/map.py +90 -0
  23. hyperlight_cocoa-0.1.1/cocoa/cli/arg_types/operators/operator.py +63 -0
  24. hyperlight_cocoa-0.1.1/cocoa/cli/cli.py +138 -0
  25. hyperlight_cocoa-0.1.1/cocoa/cli/cli_protocol.py +20 -0
  26. hyperlight_cocoa-0.1.1/cocoa/cli/command.py +449 -0
  27. hyperlight_cocoa-0.1.1/cocoa/cli/group.py +578 -0
  28. hyperlight_cocoa-0.1.1/cocoa/cli/help_message/__init__.py +3 -0
  29. hyperlight_cocoa-0.1.1/cocoa/cli/help_message/cli_style.py +97 -0
  30. hyperlight_cocoa-0.1.1/cocoa/cli/help_message/create_help_string.py +49 -0
  31. hyperlight_cocoa-0.1.1/cocoa/cli/help_message/description_help_message.py +76 -0
  32. hyperlight_cocoa-0.1.1/cocoa/cli/help_message/help_message.py +208 -0
  33. hyperlight_cocoa-0.1.1/cocoa/cli/help_message/line_parsing.py +3 -0
  34. hyperlight_cocoa-0.1.1/cocoa/cli/help_message/options_help_message.py +242 -0
  35. hyperlight_cocoa-0.1.1/cocoa/cli/help_message/title_help_message.py +129 -0
  36. hyperlight_cocoa-0.1.1/cocoa/cli/inspect_wrapped.py +139 -0
  37. hyperlight_cocoa-0.1.1/cocoa/ui/__init__.py +28 -0
  38. hyperlight_cocoa-0.1.1/cocoa/ui/components/__init__.py +28 -0
  39. hyperlight_cocoa-0.1.1/cocoa/ui/components/animated_status_bar/__init__.py +4 -0
  40. hyperlight_cocoa-0.1.1/cocoa/ui/components/animated_status_bar/animated_status_bar.py +935 -0
  41. hyperlight_cocoa-0.1.1/cocoa/ui/components/animated_status_bar/animated_status_bar_config.py +55 -0
  42. hyperlight_cocoa-0.1.1/cocoa/ui/components/counter/__init__.py +2 -0
  43. hyperlight_cocoa-0.1.1/cocoa/ui/components/counter/counter.py +238 -0
  44. hyperlight_cocoa-0.1.1/cocoa/ui/components/counter/counter_config.py +22 -0
  45. hyperlight_cocoa-0.1.1/cocoa/ui/components/empty/__init__.py +1 -0
  46. hyperlight_cocoa-0.1.1/cocoa/ui/components/empty/empty.py +9 -0
  47. hyperlight_cocoa-0.1.1/cocoa/ui/components/header/__init__.py +2 -0
  48. hyperlight_cocoa-0.1.1/cocoa/ui/components/header/font/__init__.py +4 -0
  49. hyperlight_cocoa-0.1.1/cocoa/ui/components/header/font/formatted_letter.py +8 -0
  50. hyperlight_cocoa-0.1.1/cocoa/ui/components/header/font/formatted_word.py +10 -0
  51. hyperlight_cocoa-0.1.1/cocoa/ui/components/header/font/letters.py +286 -0
  52. hyperlight_cocoa-0.1.1/cocoa/ui/components/header/font/word.py +87 -0
  53. hyperlight_cocoa-0.1.1/cocoa/ui/components/header/header.py +182 -0
  54. hyperlight_cocoa-0.1.1/cocoa/ui/components/header/header_config.py +21 -0
  55. hyperlight_cocoa-0.1.1/cocoa/ui/components/link/__init__.py +2 -0
  56. hyperlight_cocoa-0.1.1/cocoa/ui/components/link/link.py +178 -0
  57. hyperlight_cocoa-0.1.1/cocoa/ui/components/link/link_config.py +14 -0
  58. hyperlight_cocoa-0.1.1/cocoa/ui/components/link/link_validator.py +5 -0
  59. hyperlight_cocoa-0.1.1/cocoa/ui/components/multiline_text/__init__.py +2 -0
  60. hyperlight_cocoa-0.1.1/cocoa/ui/components/multiline_text/multiline_text.py +216 -0
  61. hyperlight_cocoa-0.1.1/cocoa/ui/components/multiline_text/multiline_text_config.py +23 -0
  62. hyperlight_cocoa-0.1.1/cocoa/ui/components/progress_bar/__init__.py +2 -0
  63. hyperlight_cocoa-0.1.1/cocoa/ui/components/progress_bar/background_char.py +72 -0
  64. hyperlight_cocoa-0.1.1/cocoa/ui/components/progress_bar/end_char.py +54 -0
  65. hyperlight_cocoa-0.1.1/cocoa/ui/components/progress_bar/fill_char.py +80 -0
  66. hyperlight_cocoa-0.1.1/cocoa/ui/components/progress_bar/progress_bar.py +374 -0
  67. hyperlight_cocoa-0.1.1/cocoa/ui/components/progress_bar/progress_bar_config.py +65 -0
  68. hyperlight_cocoa-0.1.1/cocoa/ui/components/progress_bar/progress_bar_status.py +8 -0
  69. hyperlight_cocoa-0.1.1/cocoa/ui/components/progress_bar/start_char.py +54 -0
  70. hyperlight_cocoa-0.1.1/cocoa/ui/components/scatter_plot/__init__.py +2 -0
  71. hyperlight_cocoa-0.1.1/cocoa/ui/components/scatter_plot/plot_config.py +29 -0
  72. hyperlight_cocoa-0.1.1/cocoa/ui/components/scatter_plot/plot_point.py +6 -0
  73. hyperlight_cocoa-0.1.1/cocoa/ui/components/scatter_plot/plotille/__init__.py +31 -0
  74. hyperlight_cocoa-0.1.1/cocoa/ui/components/scatter_plot/plotille/_canvas.py +401 -0
  75. hyperlight_cocoa-0.1.1/cocoa/ui/components/scatter_plot/plotille/_cmaps.py +121 -0
  76. hyperlight_cocoa-0.1.1/cocoa/ui/components/scatter_plot/plotille/_cmaps_data.py +1604 -0
  77. hyperlight_cocoa-0.1.1/cocoa/ui/components/scatter_plot/plotille/_colors.py +324 -0
  78. hyperlight_cocoa-0.1.1/cocoa/ui/components/scatter_plot/plotille/_dots.py +190 -0
  79. hyperlight_cocoa-0.1.1/cocoa/ui/components/scatter_plot/plotille/_figure.py +621 -0
  80. hyperlight_cocoa-0.1.1/cocoa/ui/components/scatter_plot/plotille/_figure_data.py +229 -0
  81. hyperlight_cocoa-0.1.1/cocoa/ui/components/scatter_plot/plotille/_graphs.py +335 -0
  82. hyperlight_cocoa-0.1.1/cocoa/ui/components/scatter_plot/plotille/_input_formatter.py +234 -0
  83. hyperlight_cocoa-0.1.1/cocoa/ui/components/scatter_plot/plotille/_util.py +119 -0
  84. hyperlight_cocoa-0.1.1/cocoa/ui/components/scatter_plot/point_char.py +64 -0
  85. hyperlight_cocoa-0.1.1/cocoa/ui/components/scatter_plot/scatter_plot.py +311 -0
  86. hyperlight_cocoa-0.1.1/cocoa/ui/components/spinner/__init__.py +2 -0
  87. hyperlight_cocoa-0.1.1/cocoa/ui/components/spinner/spinner.py +159 -0
  88. hyperlight_cocoa-0.1.1/cocoa/ui/components/spinner/spinner_config.py +23 -0
  89. hyperlight_cocoa-0.1.1/cocoa/ui/components/spinner/spinner_data.py +1109 -0
  90. hyperlight_cocoa-0.1.1/cocoa/ui/components/spinner/spinner_factory.py +1199 -0
  91. hyperlight_cocoa-0.1.1/cocoa/ui/components/spinner/spinner_frames_set.py +12 -0
  92. hyperlight_cocoa-0.1.1/cocoa/ui/components/spinner/spinner_status.py +8 -0
  93. hyperlight_cocoa-0.1.1/cocoa/ui/components/spinner/spinner_types.py +175 -0
  94. hyperlight_cocoa-0.1.1/cocoa/ui/components/status_bar/__init__.py +2 -0
  95. hyperlight_cocoa-0.1.1/cocoa/ui/components/status_bar/status_bar.py +174 -0
  96. hyperlight_cocoa-0.1.1/cocoa/ui/components/status_bar/status_bar_config.py +24 -0
  97. hyperlight_cocoa-0.1.1/cocoa/ui/components/table/__init__.py +2 -0
  98. hyperlight_cocoa-0.1.1/cocoa/ui/components/table/table.py +328 -0
  99. hyperlight_cocoa-0.1.1/cocoa/ui/components/table/table_config.py +40 -0
  100. hyperlight_cocoa-0.1.1/cocoa/ui/components/table/tabulate/__init__.py +4 -0
  101. hyperlight_cocoa-0.1.1/cocoa/ui/components/table/tabulate/cell_alignment.py +32 -0
  102. hyperlight_cocoa-0.1.1/cocoa/ui/components/table/tabulate/charset_position_type.py +29 -0
  103. hyperlight_cocoa-0.1.1/cocoa/ui/components/table/tabulate/table_assembler.py +1506 -0
  104. hyperlight_cocoa-0.1.1/cocoa/ui/components/table/tabulate/table_border_lines.py +45 -0
  105. hyperlight_cocoa-0.1.1/cocoa/ui/components/terminal/__init__.py +6 -0
  106. hyperlight_cocoa-0.1.1/cocoa/ui/components/terminal/action.py +11 -0
  107. hyperlight_cocoa-0.1.1/cocoa/ui/components/terminal/canvas.py +254 -0
  108. hyperlight_cocoa-0.1.1/cocoa/ui/components/terminal/engine_config.py +9 -0
  109. hyperlight_cocoa-0.1.1/cocoa/ui/components/terminal/refresh_rate.py +24 -0
  110. hyperlight_cocoa-0.1.1/cocoa/ui/components/terminal/section.py +466 -0
  111. hyperlight_cocoa-0.1.1/cocoa/ui/components/terminal/section_config.py +55 -0
  112. hyperlight_cocoa-0.1.1/cocoa/ui/components/terminal/terminal.py +540 -0
  113. hyperlight_cocoa-0.1.1/cocoa/ui/components/terminal/terminal_protocol.py +20 -0
  114. hyperlight_cocoa-0.1.1/cocoa/ui/components/text/__init__.py +2 -0
  115. hyperlight_cocoa-0.1.1/cocoa/ui/components/text/text.py +155 -0
  116. hyperlight_cocoa-0.1.1/cocoa/ui/components/text/text_config.py +22 -0
  117. hyperlight_cocoa-0.1.1/cocoa/ui/components/timer/__init__.py +2 -0
  118. hyperlight_cocoa-0.1.1/cocoa/ui/components/timer/timer.py +344 -0
  119. hyperlight_cocoa-0.1.1/cocoa/ui/components/timer/timer_config.py +21 -0
  120. hyperlight_cocoa-0.1.1/cocoa/ui/components/timer/timer_status.py +8 -0
  121. hyperlight_cocoa-0.1.1/cocoa/ui/components/total_rate/__init__.py +2 -0
  122. hyperlight_cocoa-0.1.1/cocoa/ui/components/total_rate/total_rate.py +293 -0
  123. hyperlight_cocoa-0.1.1/cocoa/ui/components/total_rate/total_rate_config.py +23 -0
  124. hyperlight_cocoa-0.1.1/cocoa/ui/components/total_rate/total_rate_status.py +7 -0
  125. hyperlight_cocoa-0.1.1/cocoa/ui/components/windowed_rate/__init__.py +2 -0
  126. hyperlight_cocoa-0.1.1/cocoa/ui/components/windowed_rate/windowed_rate.py +256 -0
  127. hyperlight_cocoa-0.1.1/cocoa/ui/components/windowed_rate/windowed_rate_config.py +22 -0
  128. hyperlight_cocoa-0.1.1/cocoa/ui/config/__init__.py +0 -0
  129. hyperlight_cocoa-0.1.1/cocoa/ui/config/mode.py +15 -0
  130. hyperlight_cocoa-0.1.1/cocoa/ui/config/widget_fit_dimensions.py +25 -0
  131. hyperlight_cocoa-0.1.1/cocoa/ui/state/__init__.py +4 -0
  132. hyperlight_cocoa-0.1.1/cocoa/ui/state/observe.py +56 -0
  133. hyperlight_cocoa-0.1.1/cocoa/ui/state/state_types.py +27 -0
  134. hyperlight_cocoa-0.1.1/cocoa/ui/state/subscription_set.py +70 -0
  135. hyperlight_cocoa-0.1.1/cocoa/ui/styling/__init__.py +2 -0
  136. hyperlight_cocoa-0.1.1/cocoa/ui/styling/attributes/__init__.py +4 -0
  137. hyperlight_cocoa-0.1.1/cocoa/ui/styling/attributes/attribute.py +45 -0
  138. hyperlight_cocoa-0.1.1/cocoa/ui/styling/attributes/attributizer.py +17 -0
  139. hyperlight_cocoa-0.1.1/cocoa/ui/styling/colors/__init__.py +10 -0
  140. hyperlight_cocoa-0.1.1/cocoa/ui/styling/colors/color.py +107 -0
  141. hyperlight_cocoa-0.1.1/cocoa/ui/styling/colors/colorizer.py +36 -0
  142. hyperlight_cocoa-0.1.1/cocoa/ui/styling/colors/extended_color.py +521 -0
  143. hyperlight_cocoa-0.1.1/cocoa/ui/styling/colors/highlight.py +107 -0
  144. hyperlight_cocoa-0.1.1/cocoa/ui/styling/stylize.py +101 -0
  145. hyperlight_cocoa-0.1.1/cocoa/ui/styling/stylizer.py +21 -0
  146. hyperlight_cocoa-0.1.1/hyperlight_cocoa.egg-info/PKG-INFO +43 -0
  147. hyperlight_cocoa-0.1.1/hyperlight_cocoa.egg-info/SOURCES.txt +150 -0
  148. hyperlight_cocoa-0.1.1/hyperlight_cocoa.egg-info/dependency_links.txt +1 -0
  149. hyperlight_cocoa-0.1.1/hyperlight_cocoa.egg-info/requires.txt +1 -0
  150. hyperlight_cocoa-0.1.1/hyperlight_cocoa.egg-info/top_level.txt +2 -0
  151. hyperlight_cocoa-0.1.1/pyproject.toml +40 -0
  152. hyperlight_cocoa-0.1.1/setup.cfg +4 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Hyperlight
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,43 @@
1
+ Metadata-Version: 2.2
2
+ Name: hyperlight-cocoa
3
+ Version: 0.1.1
4
+ Summary: Create beautiful, performant terminal UI and CLI apps.
5
+ Author-email: Ada Lundhe <adalundhe@lundhe.audio>
6
+ License: MIT License
7
+
8
+ Copyright (c) 2025 Hyperlight
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Project-URL: Homepage, https://github.com/hyper-light/cocoa
29
+ Keywords: ui,terminal,ascii,graphics
30
+ Classifier: Programming Language :: Python :: 3.11
31
+ Classifier: Programming Language :: Python :: 3.12
32
+ Classifier: Programming Language :: Python :: 3.13
33
+ Classifier: License :: OSI Approved :: MIT License
34
+ Classifier: Operating System :: OS Independent
35
+ Requires-Python: >=3.11
36
+ Description-Content-Type: text/markdown
37
+ License-File: LICENSE
38
+ Requires-Dist: pydantic
39
+
40
+ # Cocoa
41
+ ### A framework for building beautiful and performant terminal and CLI apps
42
+
43
+ Coca is a first-of-its-kind async-first framework for building fully modern Python terminal and CLI applications. Its use of typehints to facilitate complex runtime reflection-based behaviors, multi-file CLI apps, decoupled state and rendering layers, and component-driven architecture make it easy to give your programs both pizzaz and rich functionality while remaining efficient.
@@ -0,0 +1,4 @@
1
+ # Cocoa
2
+ ### A framework for building beautiful and performant terminal and CLI apps
3
+
4
+ Coca is a first-of-its-kind async-first framework for building fully modern Python terminal and CLI applications. Its use of typehints to facilitate complex runtime reflection-based behaviors, multi-file CLI apps, decoupled state and rendering layers, and component-driven architecture make it easy to give your programs both pizzaz and rich functionality while remaining efficient.
@@ -0,0 +1,14 @@
1
+ from .cli import CLI as CLI
2
+ from .arg_types import AssertSet as AssertSet
3
+ from .arg_types import Chain as Chain
4
+ from .arg_types import Context as Context
5
+ from .arg_types import Env as Env
6
+ from .arg_types import ImportFile as ImportFile
7
+ from .arg_types import JsonData as JsonData
8
+ from .arg_types import JsonFile as JsonFile
9
+ from .arg_types import Map as Map
10
+ from .arg_types import Operator as Operator
11
+ from .arg_types import Paths as Paths
12
+ from .arg_types import Pattern as Pattern
13
+ from .arg_types import RawFile as RawFile
14
+ from .help_message import CLIStyle as CLIStyle
@@ -0,0 +1,18 @@
1
+ from .base import KeywordArg as KeywordArg
2
+ from .base import is_defaultable as is_defaultable
3
+ from .base import is_env_defaultable as is_env_defaultable
4
+ from .base import is_required_missing_keyword_arg as is_required_missing_keyword_arg
5
+ from .base import is_unsupported_keyword_arg as is_unsupported_keyword_arg
6
+ from .base import PositionalArg as PositionalArg
7
+ from .data_types import AssertSet as AssertSet
8
+ from .data_types import Context as Context
9
+ from .data_types import Env as Env
10
+ from .data_types import ImportFile as ImportFile
11
+ from .data_types import JsonData as JsonData
12
+ from .data_types import JsonFile as JsonFile
13
+ from .data_types import Paths as Paths
14
+ from .data_types import Pattern as Pattern
15
+ from .data_types import RawFile as RawFile
16
+ from .operators import Chain as Chain
17
+ from .operators import Map as Map
18
+ from .operators import Operator as Operator
@@ -0,0 +1,8 @@
1
+ from .keyword_arg import KeywordArg as KeywordArg
2
+ from .keyword_arg import is_defaultable as is_defaultable
3
+ from .keyword_arg import is_env_defaultable as is_env_defaultable
4
+ from .keyword_arg import (
5
+ is_required_missing_keyword_arg as is_required_missing_keyword_arg,
6
+ )
7
+ from .keyword_arg import is_unsupported_keyword_arg as is_unsupported_keyword_arg
8
+ from .positional_arg import PositionalArg as PositionalArg
@@ -0,0 +1,249 @@
1
+ import inspect
2
+ from cocoa.cli.arg_types.data_types import (
3
+ AssertSet,
4
+ Context,
5
+ Env,
6
+ ImportFile,
7
+ JsonData,
8
+ JsonFile,
9
+ Paths,
10
+ Pattern,
11
+ RawFile,
12
+ )
13
+ from cocoa.cli.arg_types.data_types.reduce_pattern_type import reduce_pattern_type
14
+ from cocoa.cli.arg_types.operators import Operator
15
+ from typing import (
16
+ Literal,
17
+ Generic,
18
+ TypeVar,
19
+ Any,
20
+ Callable,
21
+ get_args,
22
+ get_origin,
23
+ )
24
+
25
+
26
+ KeywordArgType = Literal["keyword", "flag"]
27
+
28
+
29
+ T = TypeVar("T")
30
+
31
+
32
+ class KeywordArg(Generic[T]):
33
+ def __init__(
34
+ self,
35
+ name: str,
36
+ data_type: type[T],
37
+ short_name: str | None = None,
38
+ default: T | None = None,
39
+ group: str | None = None,
40
+ required: bool = True,
41
+ arg_type: KeywordArgType = "keyword",
42
+ description: str | None = None,
43
+ is_context_arg: bool = False,
44
+ ):
45
+ if short_name is None:
46
+ short_name = name[:1]
47
+
48
+ self.name = name
49
+ self.short_name = short_name
50
+ self.is_context_arg = is_context_arg
51
+
52
+ full_flag = "-".join(name.split("_"))
53
+
54
+ self.full_flag = f"--{full_flag}"
55
+ self.short_flag = f"-{short_name}"
56
+
57
+ args = get_args(data_type)
58
+ self._complex_types: dict[
59
+ AssertSet
60
+ | Context
61
+ | Env
62
+ | ImportFile
63
+ | JsonData
64
+ | JsonData
65
+ | Operator
66
+ | Paths
67
+ | Pattern
68
+ | RawFile,
69
+ Callable[
70
+ [str, type[Any]],
71
+ AssertSet
72
+ | Context
73
+ | Env
74
+ | ImportFile
75
+ | JsonData
76
+ | JsonData
77
+ | Operator
78
+ | Paths
79
+ | Pattern
80
+ | RawFile,
81
+ ],
82
+ ] = {
83
+ AssertSet: lambda name, subtype: AssertSet(name, subtype),
84
+ Context: lambda _, __: Context(),
85
+ Env: lambda envar, subtype: Env(envar, subtype),
86
+ ImportFile: lambda _, subtype: ImportFile(subtype),
87
+ JsonFile: lambda _, subtype: JsonFile(subtype),
88
+ JsonData: lambda _, subtype: JsonData(subtype),
89
+ Operator: lambda name, subtype: Operator(name, subtype),
90
+ Paths: lambda _, subtype: Paths(subtype),
91
+ Pattern: lambda _, subtype: Pattern(subtype),
92
+ RawFile: lambda _, subtype: RawFile(subtype),
93
+ }
94
+
95
+ self._is_complex_type = (
96
+ get_origin(
97
+ data_type,
98
+ )
99
+ in self._complex_types.keys()
100
+ )
101
+
102
+ if len(args) > 0 and self._is_complex_type is False:
103
+ self._value_type = args
104
+
105
+ else:
106
+ self._value_type = tuple([data_type])
107
+
108
+ self.loads_from_envar = (
109
+ len([subtype for subtype in self._value_type if get_origin(subtype) == Env])
110
+ > 0
111
+ )
112
+
113
+ self.required = required
114
+
115
+ self.default_is_awaitable = False
116
+ if inspect.isawaitable(default) or inspect.iscoroutinefunction(default):
117
+ self.default_is_awaitable = True
118
+
119
+ self.default_is_callable = False
120
+ if inspect.isfunction(default) or inspect.ismethod(default):
121
+ self.default_is_callable = True
122
+
123
+ base_type = [data_type]
124
+ if self._is_complex_type:
125
+ base_type = reduce_pattern_type(data_type)
126
+
127
+ self.default = default
128
+ self.group = group
129
+ self.arg_type: KeywordArgType = arg_type
130
+ self._data_type = [
131
+ subtype_type.__name__
132
+ if hasattr(subtype_type, '__name__')
133
+ else subtype_type
134
+ for subtype_type in base_type
135
+ ]
136
+
137
+ self.description = description
138
+
139
+ self.consumed_next_positions_count = 1 if arg_type == "keyword" else 0
140
+
141
+ @property
142
+ def data_type(self):
143
+ return ", ".join(self._data_type)
144
+
145
+ @property
146
+ def data_type_list(self):
147
+ return self._data_type
148
+
149
+ @property
150
+ def value_type(self):
151
+ return (
152
+ self._value_type
153
+ if self._is_complex_type is False
154
+ else tuple([get_origin(data_type) for data_type in self._value_type])
155
+ )
156
+
157
+ async def to_default(self):
158
+ if self.default_is_awaitable:
159
+ default_value = await self.default()
160
+
161
+ elif self.default_is_callable:
162
+ default_value = self.default()
163
+
164
+ else:
165
+ default_value = self.default
166
+
167
+ for subtype in self._value_type:
168
+ if complex_type_factory := self._complex_types.get(get_origin(subtype)):
169
+ complex_type = complex_type_factory(self.name, subtype)
170
+
171
+ complex_type.data = default_value
172
+
173
+ return complex_type
174
+
175
+ return default_value
176
+
177
+ def to_flag(self):
178
+ return f"--{self.name}"
179
+
180
+ async def parse(self, value: str | None = None):
181
+ parse_error: Exception | None = None
182
+
183
+ for subtype in self._value_type:
184
+ try:
185
+ if complex_type_factory := self._complex_types.get(get_origin(subtype)):
186
+ complex_type = complex_type_factory(self.name, subtype)
187
+
188
+ return await complex_type.parse(value)
189
+
190
+ elif subtype == bytes:
191
+ return bytes(value, encoding="utf-8")
192
+
193
+ return subtype(value)
194
+
195
+ except Exception as e:
196
+ parse_error = e
197
+
198
+ return parse_error
199
+
200
+
201
+ def is_required_missing_keyword_arg(
202
+ flag: str, keyword_arg: KeywordArg, keyword_args: dict[str, KeywordArg]
203
+ ):
204
+ if keyword_args.get(keyword_arg.name):
205
+ return False
206
+
207
+ if flag != keyword_arg.full_flag:
208
+ return False
209
+
210
+ if keyword_arg.arg_type == "flag":
211
+ return False
212
+
213
+ return keyword_arg.required
214
+
215
+
216
+ def is_defaultable(
217
+ flag: str, keyword_arg: KeywordArg, keyword_args: dict[str, KeywordArg]
218
+ ):
219
+ if keyword_args.get(keyword_arg.name):
220
+ return False
221
+
222
+ if flag == keyword_arg.short_flag:
223
+ return False
224
+
225
+ if keyword_arg.arg_type == "flag":
226
+ return False
227
+
228
+ return keyword_arg.required is False and keyword_arg.loads_from_envar is False
229
+
230
+
231
+ def is_env_defaultable(
232
+ flag: str, keyword_arg: KeywordArg, keyword_args: dict[str, KeywordArg]
233
+ ):
234
+ if keyword_args.get(keyword_arg.name):
235
+ return False
236
+
237
+ if flag == keyword_arg.short_flag:
238
+ return False
239
+
240
+ if keyword_arg.arg_type == "flag":
241
+ return False
242
+
243
+ return keyword_arg.loads_from_envar
244
+
245
+
246
+ def is_unsupported_keyword_arg(arg: str, keyword_args: dict[str, KeywordArg]):
247
+ return (arg.startswith("--") or arg.startswith("-")) and arg.replace(
248
+ "-", ""
249
+ ) not in keyword_args
@@ -0,0 +1,143 @@
1
+ from cocoa.cli.arg_types.data_types import (
2
+ AssertSet,
3
+ Context,
4
+ Env,
5
+ ImportFile,
6
+ JsonData,
7
+ JsonFile,
8
+ Paths,
9
+ Pattern,
10
+ RawFile,
11
+ )
12
+ from cocoa.cli.arg_types.operators import Operator
13
+ from typing import (
14
+ Literal,
15
+ Generic,
16
+ TypeVar,
17
+ Any,
18
+ Callable,
19
+ get_args,
20
+ get_origin,
21
+ )
22
+
23
+
24
+ T = TypeVar("T")
25
+
26
+
27
+ class PositionalArg(Generic[T]):
28
+ def __init__(
29
+ self,
30
+ name: str,
31
+ index: int,
32
+ data_type: type[T],
33
+ description: str | None = None,
34
+ is_context_arg: bool = False,
35
+ ):
36
+ self.name = name
37
+ self.index = index
38
+ self.is_context_arg = is_context_arg
39
+
40
+ self.is_envar: bool = False
41
+
42
+ args = get_args(data_type)
43
+ self._complex_types: dict[
44
+ AssertSet
45
+ | Context
46
+ | Env
47
+ | ImportFile
48
+ | JsonData
49
+ | JsonData
50
+ | Operator
51
+ | Paths
52
+ | Pattern
53
+ | RawFile,
54
+ Callable[
55
+ [str, type[Any]],
56
+ AssertSet
57
+ | Context
58
+ | Env
59
+ | ImportFile
60
+ | JsonData
61
+ | JsonData
62
+ | Operator
63
+ | Paths
64
+ | Pattern
65
+ | RawFile,
66
+ ],
67
+ ] = {
68
+ AssertSet: lambda name, subtype: AssertSet(name, subtype),
69
+ Context: lambda _, __: Context(),
70
+ Env: lambda envar, subtype: Env(envar, subtype),
71
+ ImportFile: lambda _, subtype: ImportFile(subtype),
72
+ JsonFile: lambda _, subtype: JsonFile(subtype),
73
+ JsonData: lambda _, subtype: JsonData(subtype),
74
+ Operator: lambda name, subtype: Operator(name, subtype),
75
+ Paths: lambda _, subtype: Paths(subtype),
76
+ Pattern: lambda _, subtype: Pattern(subtype),
77
+ RawFile: lambda _, subtype: RawFile(subtype),
78
+ }
79
+
80
+ self._is_complex_type = (
81
+ get_origin(
82
+ data_type,
83
+ )
84
+ in self._complex_types.keys()
85
+ )
86
+
87
+ if len(args) > 0 and self._is_complex_type is False:
88
+ self._value_type = args
89
+
90
+ elif self._is_complex_type:
91
+ self._value_type = tuple([data_type])
92
+
93
+ else:
94
+ self._value_type = tuple([data_type])
95
+
96
+ self.loads_from_envar = (
97
+ len([subtype for subtype in self.value_type if get_origin(subtype) == Env])
98
+ > 0
99
+ )
100
+
101
+ self._data_type = [subtype_type.__name__ for subtype_type in self.value_type]
102
+
103
+ self.description = description
104
+
105
+ @property
106
+ def data_type(self):
107
+ return ", ".join(self._data_type)
108
+
109
+ @property
110
+ def value_type(self):
111
+ return (
112
+ self._value_type
113
+ if self._is_complex_type is False
114
+ else tuple([get_origin(data_type) for data_type in self._value_type])
115
+ )
116
+
117
+ def to_help_string(self):
118
+ help_string = f"{self.name}: [{self.data_type}]"
119
+
120
+ if self.description:
121
+ help_string = f"{help_string} {self.description}"
122
+
123
+ return help_string
124
+
125
+ async def parse(self, value: str | None = None):
126
+ parse_error: Exception | None = None
127
+
128
+ for subtype in self._value_type:
129
+ try:
130
+ if complex_type_factory := self._complex_types.get(get_origin(subtype)):
131
+ complex_type = complex_type_factory(self.name, subtype)
132
+
133
+ return await complex_type.parse(value)
134
+
135
+ elif subtype == bytes:
136
+ return bytes(value, encoding="utf-8")
137
+
138
+ return subtype(value)
139
+
140
+ except Exception as e:
141
+ parse_error = e
142
+
143
+ return parse_error
@@ -0,0 +1,9 @@
1
+ from .assert_set import AssertSet as AssertSet
2
+ from .context import Context as Context
3
+ from .env import Env as Env
4
+ from .import_file import ImportFile as ImportFile
5
+ from .json_data import JsonData as JsonData
6
+ from .json_file import JsonFile as JsonFile
7
+ from .paths import Paths as Paths
8
+ from .pattern import Pattern as Pattern
9
+ from .raw_file import RawFile as RawFile
@@ -0,0 +1,49 @@
1
+ from __future__ import annotations
2
+ import asyncio
3
+ from typing import TypeVar, Generic, Any
4
+ from .reduce_pattern_type import reduce_pattern_type
5
+
6
+
7
+ T = TypeVar("T")
8
+
9
+
10
+ class AssertSet(Generic[T]):
11
+ def __init__(self, name: str, data_type: AssertSet[T]):
12
+ super().__init__()
13
+ self.name = name
14
+ self.data: T | None = None
15
+
16
+ conversion_types: list[T] = reduce_pattern_type(data_type)
17
+
18
+ self._data_types = [
19
+ conversion_type.__name__
20
+ if hasattr(conversion_type, "__name__")
21
+ else conversion_type
22
+ for conversion_type in conversion_types
23
+ ]
24
+ self._types = conversion_types
25
+
26
+ self._loop = asyncio.get_event_loop()
27
+
28
+ def __contains__(self, value: Any):
29
+ return type(value) in [self._types]
30
+
31
+ @property
32
+ def data_type(self):
33
+ return ", ".join(self._data_types)
34
+
35
+ async def parse(self, arg: str | None = None):
36
+ if arg is None:
37
+ return Exception("no argument passed")
38
+
39
+ try:
40
+ assert arg in self._types, (
41
+ f"{arg} is not a supported value for {self.name} - please pass one of {self.data_type}"
42
+ )
43
+
44
+ self.data = arg
45
+
46
+ return self
47
+
48
+ except Exception as e:
49
+ return e
@@ -0,0 +1,16 @@
1
+ from typing import TypeVar, Generic
2
+
3
+
4
+ K = TypeVar("K")
5
+ V = TypeVar("V")
6
+
7
+
8
+ class Context(Generic[K, V]):
9
+ def __init__(self):
10
+ self._context: dict[K, V] = {}
11
+
12
+ def __setitem__(self, key: K, value: V):
13
+ self._context[key] = value
14
+
15
+ def __getitem__(self, key: K):
16
+ return self._context.get(key)
@@ -0,0 +1,76 @@
1
+ from __future__ import annotations
2
+
3
+ import asyncio
4
+ import os
5
+ from typing import Generic, TypeVar, Any
6
+ from .reduce_pattern_type import reduce_pattern_type
7
+
8
+
9
+ T = TypeVar("T")
10
+
11
+
12
+ class Env(Generic[T]):
13
+ def __init__(
14
+ self,
15
+ envar: str,
16
+ data_type: Env[T],
17
+ ):
18
+ super().__init__()
19
+ self._envar = envar
20
+
21
+ self.data: T | None = None
22
+
23
+ data_types = reduce_pattern_type(data_type)
24
+ self._types = data_types
25
+
26
+ self._data_types = [
27
+ conversion_type.__name__
28
+ if hasattr(conversion_type, "__name__")
29
+ else type(conversion_type).__name__
30
+ for conversion_type in self._types
31
+ ]
32
+
33
+ self._loop = asyncio.get_event_loop()
34
+
35
+ def __contains__(self, value: Any):
36
+ return type(value) in [self._types]
37
+
38
+ @property
39
+ def data_type(self):
40
+ return self._data_types
41
+
42
+ async def parse(self, _: str | None = None):
43
+ result = await self._load_envar()
44
+ if isinstance(result, Exception):
45
+ return result
46
+
47
+ self.data = result
48
+
49
+ return self
50
+
51
+ async def _load_envar(self):
52
+ value = await self._load()
53
+ if isinstance(value, None):
54
+ return Exception(f"no envar matching {self._envar.upper()} found")
55
+
56
+ for conversion_type in self._types:
57
+ try:
58
+ if conversion_type == bytes:
59
+ return bytes(value, encoding="utf-8")
60
+
61
+ else:
62
+ return conversion_type(value)
63
+
64
+ except Exception:
65
+ pass
66
+
67
+ return Exception(f"could not parse {value} specified types")
68
+
69
+ async def _load(self):
70
+ value = await self._loop.run_in_executor(
71
+ None,
72
+ os.getenv,
73
+ self._envar.upper(),
74
+ )
75
+
76
+ return value