rats-apps 0.8.0.dev20250324085239__py3-none-any.whl → 0.9.0.dev20250415195703__py3-none-any.whl
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.
- rats/apps/__init__.py +2 -0
- rats/cli/__init__.py +7 -2
- rats/cli/_command.py +24 -0
- rats/cli/_functions.py +61 -0
- rats/cli/_plugin.py +32 -51
- {rats_apps-0.8.0.dev20250324085239.dist-info → rats_apps-0.9.0.dev20250415195703.dist-info}/METADATA +1 -1
- {rats_apps-0.8.0.dev20250324085239.dist-info → rats_apps-0.9.0.dev20250415195703.dist-info}/RECORD +9 -7
- {rats_apps-0.8.0.dev20250324085239.dist-info → rats_apps-0.9.0.dev20250415195703.dist-info}/WHEEL +1 -1
- /rats/cli/{_app.py → _click_app.py} +0 -0
rats/apps/__init__.py
CHANGED
@@ -16,6 +16,7 @@ from ._annotations import (
|
|
16
16
|
service,
|
17
17
|
)
|
18
18
|
from ._app_containers import (
|
19
|
+
EMPTY_PLUGIN,
|
19
20
|
AppBundle,
|
20
21
|
AppContainer,
|
21
22
|
AppPlugin,
|
@@ -43,6 +44,7 @@ from ._static_container import StaticContainer, StaticProvider, static_group, st
|
|
43
44
|
|
44
45
|
__all__ = [
|
45
46
|
"EMPTY_CONTAINER",
|
47
|
+
"EMPTY_PLUGIN",
|
46
48
|
"App",
|
47
49
|
"AppBundle",
|
48
50
|
"AppContainer",
|
rats/cli/__init__.py
CHANGED
@@ -8,16 +8,21 @@ from ._annotations import (
|
|
8
8
|
get_class_groups,
|
9
9
|
group,
|
10
10
|
)
|
11
|
-
from .
|
11
|
+
from ._click_app import ClickApp
|
12
|
+
from ._command import Command
|
12
13
|
from ._container import CompositeContainer, Container
|
13
|
-
from .
|
14
|
+
from ._functions import attach, create_group
|
15
|
+
from ._plugin import PluginConfigs, PluginContainer
|
14
16
|
|
15
17
|
__all__ = [
|
16
18
|
"AUTO_COMMAND",
|
17
19
|
"ClickApp",
|
20
|
+
"Command",
|
18
21
|
"CommandId",
|
19
22
|
"CompositeContainer",
|
20
23
|
"Container",
|
24
|
+
"PluginConfigs",
|
25
|
+
"PluginContainer",
|
21
26
|
"attach",
|
22
27
|
"command",
|
23
28
|
"create_group",
|
rats/cli/_command.py
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
from collections.abc import Mapping
|
2
|
+
from dataclasses import dataclass
|
3
|
+
|
4
|
+
|
5
|
+
@dataclass(frozen=True)
|
6
|
+
class Command:
|
7
|
+
"""Wraps the information of a cli command."""
|
8
|
+
|
9
|
+
cwd: str
|
10
|
+
"""
|
11
|
+
The directory the command is run from.
|
12
|
+
|
13
|
+
Often taken from [pathlib.Path.cwd][] and turned into a plain string.
|
14
|
+
"""
|
15
|
+
argv: tuple[str, ...]
|
16
|
+
"""
|
17
|
+
The list of cli arguments passed to the command.
|
18
|
+
|
19
|
+
This has the same meaning as [sys.argv][] and is often populated by it.
|
20
|
+
"""
|
21
|
+
env: Mapping[str, str]
|
22
|
+
"""
|
23
|
+
The process environment variables often populated by [os.environ][].
|
24
|
+
"""
|
rats/cli/_functions.py
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
import click
|
2
|
+
|
3
|
+
from ._container import Container
|
4
|
+
|
5
|
+
|
6
|
+
def create_group(group: click.Group, container: Container) -> click.Group:
|
7
|
+
"""
|
8
|
+
A simple shortcut to create a [click.Group][] with commands provided by `rats.cli.Container`'s.
|
9
|
+
|
10
|
+
```python
|
11
|
+
import click
|
12
|
+
from rats import cli
|
13
|
+
|
14
|
+
|
15
|
+
class Example(cli.Container):
|
16
|
+
@cli.command()
|
17
|
+
def my_command(self) -> None:
|
18
|
+
print("hello, world. run me with `my-cli my-command`.")
|
19
|
+
|
20
|
+
|
21
|
+
if __name__ == "__main__":
|
22
|
+
cli.create_group(click.Group("my-cli"), Example()).main()
|
23
|
+
```
|
24
|
+
|
25
|
+
Args:
|
26
|
+
group: The [click.Group][] commands will be added to.
|
27
|
+
container: The [rats.cli.Container][] instance to attach commands from
|
28
|
+
"""
|
29
|
+
container.attach(group)
|
30
|
+
return group
|
31
|
+
|
32
|
+
|
33
|
+
def attach(
|
34
|
+
group: click.Group,
|
35
|
+
command: click.Command | click.Group,
|
36
|
+
*commands: click.Command | click.Group,
|
37
|
+
) -> None:
|
38
|
+
"""
|
39
|
+
Convenience function to attach multiple [click.Command]'s to a [click.Group].
|
40
|
+
|
41
|
+
```python
|
42
|
+
import click
|
43
|
+
from rats import cli
|
44
|
+
|
45
|
+
cli.attach(
|
46
|
+
click.Group("my-cli"),
|
47
|
+
click.Command("command-1"),
|
48
|
+
click.Command("command-2"),
|
49
|
+
)
|
50
|
+
```
|
51
|
+
|
52
|
+
Args:
|
53
|
+
group: The [click.Group] we want to build.
|
54
|
+
command: A [click.Command] to attach to the provided group.
|
55
|
+
*commands: Any number of additional [click.Command]'s to attach.
|
56
|
+
|
57
|
+
Returns: The input [click.Group][] with all of the commands attached.
|
58
|
+
"""
|
59
|
+
group.add_command(command)
|
60
|
+
for c in commands:
|
61
|
+
group.add_command(c)
|
rats/cli/_plugin.py
CHANGED
@@ -1,61 +1,42 @@
|
|
1
|
-
import
|
1
|
+
import os
|
2
|
+
import sys
|
3
|
+
from collections.abc import Mapping
|
4
|
+
from pathlib import Path
|
5
|
+
from typing import final
|
2
6
|
|
3
|
-
from
|
7
|
+
from rats import apps
|
4
8
|
|
9
|
+
from ._command import Command
|
5
10
|
|
6
|
-
def create_group(group: click.Group, container: Container) -> click.Group:
|
7
|
-
"""
|
8
|
-
A simple shortcut to create a [click.Group][] with commands provided by `rats.cli.Container`'s.
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
-
|
12
|
+
@apps.autoscope
|
13
|
+
class PluginConfigs:
|
14
|
+
"""Service IDs provided and used by [rats.cli.PluginContainer][]."""
|
13
15
|
|
16
|
+
COMMAND = apps.ServiceId[Command]("command")
|
17
|
+
CWD = apps.ServiceId[str]("cwd")
|
18
|
+
ARGV = apps.ServiceId[tuple[str, ...]]("argv")
|
19
|
+
ENV = apps.ServiceId[Mapping[str, str]]("env")
|
14
20
|
|
15
|
-
class Example(cli.Container):
|
16
|
-
@cli.command()
|
17
|
-
def my_command(self) -> None:
|
18
|
-
print("hello, world. run me with `my-cli my-command`.")
|
19
21
|
|
22
|
+
@final
|
23
|
+
class PluginContainer(apps.Container, apps.PluginMixin):
|
24
|
+
@apps.service(PluginConfigs.COMMAND)
|
25
|
+
def _command(self) -> Command:
|
26
|
+
return Command(
|
27
|
+
cwd=self._app.get(PluginConfigs.CWD),
|
28
|
+
argv=self._app.get(PluginConfigs.ARGV),
|
29
|
+
env=self._app.get(PluginConfigs.ENV),
|
30
|
+
)
|
20
31
|
|
21
|
-
|
22
|
-
|
23
|
-
|
32
|
+
@apps.fallback_service(PluginConfigs.CWD)
|
33
|
+
def _cwd(self) -> str:
|
34
|
+
return str(Path.cwd().resolve())
|
24
35
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
"""
|
29
|
-
container.attach(group)
|
30
|
-
return group
|
36
|
+
@apps.fallback_service(PluginConfigs.ARGV)
|
37
|
+
def _argv(self) -> tuple[str, ...]:
|
38
|
+
return tuple(sys.argv)
|
31
39
|
|
32
|
-
|
33
|
-
def
|
34
|
-
|
35
|
-
command: click.Command | click.Group,
|
36
|
-
*commands: click.Command | click.Group,
|
37
|
-
) -> None:
|
38
|
-
"""
|
39
|
-
Convenience function to attach multiple [click.Command]'s to a [click.Group].
|
40
|
-
|
41
|
-
```python
|
42
|
-
import click
|
43
|
-
from rats import cli
|
44
|
-
|
45
|
-
cli.attach(
|
46
|
-
click.Group("my-cli"),
|
47
|
-
click.Command("command-1"),
|
48
|
-
click.Command("command-2"),
|
49
|
-
)
|
50
|
-
```
|
51
|
-
|
52
|
-
Args:
|
53
|
-
group: The [click.Group] we want to build.
|
54
|
-
command: A [click.Command] to attach to the provided group.
|
55
|
-
*commands: Any number of additional [click.Command]'s to attach.
|
56
|
-
|
57
|
-
Returns: The input [click.Group][] with all of the commands attached.
|
58
|
-
"""
|
59
|
-
group.add_command(command)
|
60
|
-
for c in commands:
|
61
|
-
group.add_command(c)
|
40
|
+
@apps.fallback_service(PluginConfigs.ENV)
|
41
|
+
def _env(self) -> Mapping[str, str]:
|
42
|
+
return dict(os.environ)
|
{rats_apps-0.8.0.dev20250324085239.dist-info → rats_apps-0.9.0.dev20250415195703.dist-info}/RECORD
RENAMED
@@ -7,7 +7,7 @@ rats/app_context/_collection.py,sha256=5-Nog2Du2v0tAZbhsbpg3vMjMcZ--hSZ4acWM2HTl
|
|
7
7
|
rats/app_context/_container.py,sha256=YkNG25jngfN_064jv8fZmKW1FSuL6RRJAp9F_hm2NZg,2954
|
8
8
|
rats/app_context/_context.py,sha256=VUm-cg2WKtFU2VvIJI8OmTdRRoDLXeWPBYu_ynpUjlY,1599
|
9
9
|
rats/app_context/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
10
|
-
rats/apps/__init__.py,sha256=
|
10
|
+
rats/apps/__init__.py,sha256=BlI19Ko9nKjkHd7962P8IHgnqZxL5XAtI4aiXjq5sHc,2012
|
11
11
|
rats/apps/_annotations.py,sha256=6M_M7K8haNVda0Tx02EpFf3s9EjnWYacNMjTIkNEdRU,4617
|
12
12
|
rats/apps/_app_containers.py,sha256=ygZL0NM-fSRSemFddBsVMwcmSQw07sbb7bIqWTr-_yU,6147
|
13
13
|
rats/apps/_composite_container.py,sha256=FdpmH_xIly6LxNZrA_nZCznukptjVLXttXTMtf_tnv8,695
|
@@ -21,12 +21,14 @@ rats/apps/_runtimes.py,sha256=yzWPVbY0I-orRRN23on-iEX8Bo0BqoRiYeR3dwcBlGg,2592
|
|
21
21
|
rats/apps/_scoping.py,sha256=6C2-ID22cCPR9Cbexf3CvCF3o9F_7ieURbwqkf6DI68,1360
|
22
22
|
rats/apps/_static_container.py,sha256=KH4AwRMX5QPIwYrD9W_HayIpQIrbVn7clEMx44LFAGc,2113
|
23
23
|
rats/apps/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
24
|
-
rats/cli/__init__.py,sha256=
|
24
|
+
rats/cli/__init__.py,sha256=zMywV-4vqbtlobIoMItwbxxdvYGC20wiGU2TKm3II2A,714
|
25
25
|
rats/cli/__main__.py,sha256=WeldAKjA3Kmz9ZRnZVd3G8Ud66Y_gSRDLIPNE1JyhV0,1418
|
26
26
|
rats/cli/_annotations.py,sha256=-B2Y1bYjPbeTNTBMZzMdAU92qu9AyutKHN_NdFy-xhA,2964
|
27
|
-
rats/cli/
|
27
|
+
rats/cli/_click_app.py,sha256=4z2jiRHafCAN7S-cbMhfQJhLGwl6ljFS3r6P1COgR00,1454
|
28
|
+
rats/cli/_command.py,sha256=kyU3UqqF9aiTTaFvlQFBKDLXvArQS1QgjoQqlMbKzok,597
|
28
29
|
rats/cli/_container.py,sha256=FIQBqi9PTNpE2P52qkfGET51BczdD-JvcWXLTjCNPDI,3512
|
29
|
-
rats/cli/
|
30
|
+
rats/cli/_functions.py,sha256=BNmgWVquQUEqJAYsed_l8vLnlLP7u3XC1TDyEFI1AiU,1552
|
31
|
+
rats/cli/_plugin.py,sha256=o-pmEqU6mVH3QoRfRBrbG-XRTWCzt6pLKtSV3-5VSx0,1144
|
30
32
|
rats/cli/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
31
33
|
rats/logs/__init__.py,sha256=sizLa6JbqekhJGKDyRZUUQvTuqiJx6yxwA5jT-tDQck,152
|
32
34
|
rats/logs/_app.py,sha256=TF6rfQXQfaHd3AFW2anAoAGaxzU31kqJMoKkjuBtbF0,1617
|
@@ -40,6 +42,6 @@ rats_e2e/apps/inputs/_app.py,sha256=FiaLgOZc-d1ryKSwKnL5XBNGcOP1bHbxxeMJqoU_RJg,
|
|
40
42
|
rats_e2e/apps/minimal/__init__.py,sha256=bUR6Oexx6Jsouxor0cL9emXoVha4cm3WqyhU1pgchsI,521
|
41
43
|
rats_e2e/apps/minimal/__main__.py,sha256=Mf-a2iQKTTgh9hMd6AeuzmU9araMIyf1AtdWkh_L07E,117
|
42
44
|
rats_e2e/apps/minimal/_app.py,sha256=CQ09LVTNRarz7Pb1wiSuNHrZ_2KGcgH8nUqy4BjxMUY,849
|
43
|
-
rats_apps-0.
|
44
|
-
rats_apps-0.
|
45
|
-
rats_apps-0.
|
45
|
+
rats_apps-0.9.0.dev20250415195703.dist-info/METADATA,sha256=3flAxhmKtt4SzQvB7bBwIjgURpVwjieE2m2N-w6Oh0U,866
|
46
|
+
rats_apps-0.9.0.dev20250415195703.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
|
47
|
+
rats_apps-0.9.0.dev20250415195703.dist-info/RECORD,,
|
File without changes
|