dagster-cloud-cli 1.12.16__py2.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.
Files changed (71) hide show
  1. dagster_cloud_cli/__init__.py +5 -0
  2. dagster_cloud_cli/commands/__init__.py +0 -0
  3. dagster_cloud_cli/commands/branch_deployment/__init__.py +154 -0
  4. dagster_cloud_cli/commands/ci/__init__.py +1207 -0
  5. dagster_cloud_cli/commands/ci/checks.py +135 -0
  6. dagster_cloud_cli/commands/ci/report.py +49 -0
  7. dagster_cloud_cli/commands/ci/state.py +129 -0
  8. dagster_cloud_cli/commands/ci/utils.py +22 -0
  9. dagster_cloud_cli/commands/config.py +250 -0
  10. dagster_cloud_cli/commands/deployment/__init__.py +108 -0
  11. dagster_cloud_cli/commands/deployment/alert_policies/__init__.py +0 -0
  12. dagster_cloud_cli/commands/deployment/alert_policies/commands.py +52 -0
  13. dagster_cloud_cli/commands/integration/__init__.py +6 -0
  14. dagster_cloud_cli/commands/integration/atlan/__init__.py +94 -0
  15. dagster_cloud_cli/commands/job/__init__.py +117 -0
  16. dagster_cloud_cli/commands/metrics.py +114 -0
  17. dagster_cloud_cli/commands/organization/__init__.py +134 -0
  18. dagster_cloud_cli/commands/organization/saml/__init__.py +0 -0
  19. dagster_cloud_cli/commands/organization/saml/commands.py +85 -0
  20. dagster_cloud_cli/commands/run/__init__.py +27 -0
  21. dagster_cloud_cli/commands/serverless/Dockerfile +38 -0
  22. dagster_cloud_cli/commands/serverless/Dockerfile.dagster-cloud-cli +20 -0
  23. dagster_cloud_cli/commands/serverless/__init__.py +560 -0
  24. dagster_cloud_cli/commands/workspace/__init__.py +358 -0
  25. dagster_cloud_cli/config/__init__.py +6 -0
  26. dagster_cloud_cli/config/jinja_template_loader.py +45 -0
  27. dagster_cloud_cli/config/list_merge_strategies.py +77 -0
  28. dagster_cloud_cli/config/loader.py +23 -0
  29. dagster_cloud_cli/config/merger.py +92 -0
  30. dagster_cloud_cli/config/models.py +76 -0
  31. dagster_cloud_cli/config_utils.py +506 -0
  32. dagster_cloud_cli/core/__init__.py +0 -0
  33. dagster_cloud_cli/core/agent_queue.py +3 -0
  34. dagster_cloud_cli/core/alert_types.py +26 -0
  35. dagster_cloud_cli/core/artifacts.py +192 -0
  36. dagster_cloud_cli/core/docker_runner.py +57 -0
  37. dagster_cloud_cli/core/errors.py +32 -0
  38. dagster_cloud_cli/core/graphql_client.py +420 -0
  39. dagster_cloud_cli/core/headers/__init__.py +0 -0
  40. dagster_cloud_cli/core/headers/auth.py +16 -0
  41. dagster_cloud_cli/core/headers/impl.py +31 -0
  42. dagster_cloud_cli/core/headers/versioning/__init__.py +0 -0
  43. dagster_cloud_cli/core/headers/versioning/constants.py +2 -0
  44. dagster_cloud_cli/core/pex_builder/__init__.py +8 -0
  45. dagster_cloud_cli/core/pex_builder/code_location.py +126 -0
  46. dagster_cloud_cli/core/pex_builder/deploy.py +255 -0
  47. dagster_cloud_cli/core/pex_builder/deps.py +495 -0
  48. dagster_cloud_cli/core/pex_builder/git_context.py +29 -0
  49. dagster_cloud_cli/core/pex_builder/github_context.py +178 -0
  50. dagster_cloud_cli/core/pex_builder/gitlab_context.py +30 -0
  51. dagster_cloud_cli/core/pex_builder/parse_workspace.py +39 -0
  52. dagster_cloud_cli/core/pex_builder/pex_registry.py +148 -0
  53. dagster_cloud_cli/core/pex_builder/platforms.py +6105 -0
  54. dagster_cloud_cli/core/pex_builder/selftest.py +14 -0
  55. dagster_cloud_cli/core/pex_builder/source.py +166 -0
  56. dagster_cloud_cli/core/pex_builder/util.py +165 -0
  57. dagster_cloud_cli/core/workspace.py +145 -0
  58. dagster_cloud_cli/docker_utils.py +98 -0
  59. dagster_cloud_cli/entrypoint.py +209 -0
  60. dagster_cloud_cli/gql.py +1025 -0
  61. dagster_cloud_cli/pex_utils.py +180 -0
  62. dagster_cloud_cli/py.typed +0 -0
  63. dagster_cloud_cli/types.py +78 -0
  64. dagster_cloud_cli/ui.py +101 -0
  65. dagster_cloud_cli/utils.py +107 -0
  66. dagster_cloud_cli/version.py +1 -0
  67. dagster_cloud_cli-1.12.16.dist-info/METADATA +31 -0
  68. dagster_cloud_cli-1.12.16.dist-info/RECORD +71 -0
  69. dagster_cloud_cli-1.12.16.dist-info/WHEEL +5 -0
  70. dagster_cloud_cli-1.12.16.dist-info/entry_points.txt +3 -0
  71. dagster_cloud_cli-1.12.16.dist-info/licenses/LICENSE +201 -0
@@ -0,0 +1,209 @@
1
+ # The following allows logging calls with extra arguments
2
+ # ruff: noqa: PLE1205
3
+ import importlib.util
4
+ import json
5
+ import logging
6
+ import time
7
+ from collections.abc import Callable, Mapping
8
+ from enum import Enum
9
+
10
+ import typer
11
+ from typer.models import CommandInfo
12
+
13
+ from dagster_cloud_cli.commands.branch_deployment import app as branch_deployment_app
14
+ from dagster_cloud_cli.commands.ci import app as ci_app
15
+ from dagster_cloud_cli.commands.config import (
16
+ app as config_app,
17
+ app_configure as configure_app,
18
+ )
19
+ from dagster_cloud_cli.commands.deployment import app as deployment_app
20
+ from dagster_cloud_cli.commands.integration import app as integration_app
21
+ from dagster_cloud_cli.commands.job import app as job_app
22
+ from dagster_cloud_cli.commands.organization import (
23
+ app as organization_app,
24
+ legacy_settings_app,
25
+ )
26
+ from dagster_cloud_cli.commands.run import app as run_app
27
+ from dagster_cloud_cli.commands.serverless import app as serverless_app
28
+ from dagster_cloud_cli.commands.workspace import app as workspace_app
29
+ from dagster_cloud_cli.utils import create_stub_app
30
+ from dagster_cloud_cli.version import __version__
31
+
32
+ has_dagster_cloud = importlib.util.find_spec("dagster_cloud") is not None
33
+
34
+
35
+ if has_dagster_cloud:
36
+ from dagster_cloud.agent.cli import app as agent_app # type: ignore
37
+ from dagster_cloud.pex.grpc.server.cli import app as pex_app # type: ignore
38
+ else:
39
+ agent_app = create_stub_app("dagster-cloud")
40
+ pex_app = create_stub_app("dagster-cloud")
41
+
42
+
43
+ def _import_commands(
44
+ parent: typer.Typer,
45
+ child: typer.Typer,
46
+ remap_fn: Callable[[CommandInfo], CommandInfo] | None = None,
47
+ ) -> None:
48
+ """Copies the commands from one Typer app to another.
49
+ Equivalent of `add_typer` but doesn't add a subcommand.
50
+ """
51
+ for raw_command in child.registered_commands:
52
+ command = remap_fn(raw_command) if remap_fn else raw_command
53
+ parent.registered_commands.append(command)
54
+
55
+
56
+ def _rename_command(command_info: CommandInfo, name: str) -> CommandInfo:
57
+ return CommandInfo(
58
+ name=name,
59
+ cls=command_info.cls,
60
+ context_settings=command_info.context_settings,
61
+ callback=command_info.callback,
62
+ help=command_info.help,
63
+ epilog=command_info.epilog,
64
+ short_help=command_info.short_help,
65
+ options_metavar=command_info.options_metavar,
66
+ add_help_option=command_info.add_help_option,
67
+ no_args_is_help=command_info.no_args_is_help,
68
+ hidden=command_info.hidden,
69
+ deprecated=command_info.deprecated,
70
+ # This avoids an error if a user is using an older version of Typer, since
71
+ # `rich_help_panel` was added in typer==0.6.0.
72
+ **(
73
+ {"rich_help_panel": getattr(command_info, "rich_help_panel")}
74
+ if hasattr(command_info, "rich_help_panel")
75
+ else {}
76
+ ),
77
+ )
78
+
79
+
80
+ app = typer.Typer(
81
+ help="CLI tools for working with Dagster Cloud.",
82
+ no_args_is_help=True,
83
+ context_settings={
84
+ "help_option_names": ["-h", "--help"],
85
+ },
86
+ pretty_exceptions_enable=False, # don't display overly verbose stack traces
87
+ )
88
+
89
+
90
+ def version_callback(value: bool):
91
+ if value:
92
+ typer.echo(f"Dagster Cloud version: {__version__}")
93
+ raise typer.Exit()
94
+
95
+
96
+ class LogFormat(Enum):
97
+ DEFAULT = "default"
98
+ FLUENTBIT = "fluentbit"
99
+
100
+
101
+ class FluentbitJsonFormatter(logging.Formatter):
102
+ def __init__(self, fmt: str, json_fields: Mapping[str, str]):
103
+ super().__init__(fmt=fmt)
104
+ self.json_fields = dict(json_fields)
105
+
106
+ def format(self, record: logging.LogRecord) -> str:
107
+ log = super().format(record)
108
+ output = {
109
+ # Time format specified here: https://github.com/fluent/fluent-bit/blob/master/conf/parsers.conf#L35-L39
110
+ "time": time.strftime("%d/%b/%Y:%H:%M:%S %z", time.localtime(record.created)),
111
+ "log": log,
112
+ "status": record.levelname,
113
+ "logger": record.name,
114
+ }
115
+
116
+ if isinstance(record.args, dict):
117
+ for source_field, target_field in self.json_fields.items():
118
+ if source_field in record.args:
119
+ output[target_field] = str(record.args[source_field])
120
+
121
+ return json.dumps(output)
122
+
123
+
124
+ def log_format_callback(value: LogFormat):
125
+ if value == LogFormat.FLUENTBIT:
126
+ logger = logging.getLogger()
127
+ for handler in logger.handlers[:]:
128
+ logger.removeHandler(handler)
129
+ logger.setLevel(logging.INFO)
130
+ handler = logging.StreamHandler()
131
+ handler.setFormatter(
132
+ FluentbitJsonFormatter(
133
+ "%(module)s - %(message)s",
134
+ {"event_name": "event_name", "duration_seconds": "duration_seconds"},
135
+ )
136
+ )
137
+ logger.addHandler(handler)
138
+
139
+
140
+ @app.callback()
141
+ def main(
142
+ _version: bool = typer.Option(
143
+ False,
144
+ "--version",
145
+ "-v",
146
+ callback=version_callback,
147
+ is_eager=True,
148
+ show_default=False,
149
+ help="Show Dagster Cloud version.",
150
+ ),
151
+ log_format: LogFormat = typer.Option(
152
+ "default",
153
+ "--log-format",
154
+ envvar="DAGSTER_LOG_FORMAT",
155
+ callback=log_format_callback,
156
+ is_eager=True,
157
+ show_default=True,
158
+ help="Logging level and format",
159
+ ),
160
+ ):
161
+ return
162
+
163
+
164
+ @app.command(hidden=True)
165
+ def logtest() -> None:
166
+ logging.info("this is an info message")
167
+ logging.error("this is an error message")
168
+ logging.warning("this is a warning message")
169
+ try:
170
+ pass
171
+ except:
172
+ logging.exception("this is inside an exception")
173
+ logger = logging.getLogger("cloud-events")
174
+ logger.info(
175
+ "logger info message with some tags", {"event_name": "event.NAME", "duration_seconds": 0.11}
176
+ )
177
+ logger.error(
178
+ "logger error message with some tags",
179
+ {"event_name": "event.NAME", "duration_seconds": 0.11},
180
+ )
181
+
182
+
183
+ app.add_typer(agent_app, name="agent", no_args_is_help=True)
184
+ app.add_typer(config_app, name="config", no_args_is_help=True)
185
+ app.add_typer(deployment_app, name="deployment", no_args_is_help=True)
186
+ app.add_typer(organization_app, name="organization", no_args_is_help=True)
187
+ app.add_typer(workspace_app, name="workspace", no_args_is_help=True, hidden=True)
188
+ _import_commands(
189
+ deployment_app,
190
+ workspace_app,
191
+ remap_fn=lambda c: (
192
+ _rename_command(c, f"{c.name}-locations") if c.name and "location" not in c.name else c
193
+ ),
194
+ )
195
+ app.add_typer(branch_deployment_app, name="branch-deployment", no_args_is_help=True)
196
+ app.add_typer(job_app, name="job", no_args_is_help=True)
197
+ app.add_typer(run_app, name="run", no_args_is_help=True, hidden=True)
198
+ app.add_typer(serverless_app, name="serverless", no_args_is_help=True)
199
+ app.add_typer(pex_app, name="pex", hidden=True, no_args_is_help=True)
200
+ app.add_typer(ci_app, name="ci", no_args_is_help=True)
201
+ app.add_typer(integration_app, name="integration", no_args_is_help=True)
202
+
203
+ # Deprecated in favor of organization
204
+ app.add_typer(legacy_settings_app, name="settings", hidden=True)
205
+
206
+ _import_commands(app, configure_app)
207
+
208
+ if __name__ == "__main__":
209
+ app()