Skip to content

Commit 6086f73

Browse files
feat(cli): deprecate aws cloudformation install commands (#1201)
## Summary `braintrust install` (api, logs, bump-versions, run-migrations) is being retired rather than ported to `bt`. Code stays for now; each subcommand is registered via a shared `add_deprecated_parser` in `cli/install/_deprecation.py`, which: - marks the command `(deprecated)` in `--help` and adds the deprecation text to its description, - prints a warning to stderr before running, linking https://docs.braintrust.dev/admin/self-hosting/aws-cloudformation and recommending Terraform. boto3/botocore imports are deferred into the handlers, so `--help` works without `braintrust[cli]`; the missing-dependency message is preserved at run time. `py/README.md` notes the deprecation. `cli/test_install.py` runs the installed CLI (no mocks). Companion docs/Makefile PR in braintrustdata/braintrust removes `braintrust install` from the CloudFormation guide. Link to Devin session: https://braintrust.devinenterprise.com/sessions/d31abde6db4743ffab13f81a9a1505d6 Open in Devin Desktop: https://braintrust.devinenterprise.com/desktop/session/d31abde6db4743ffab13f81a9a1505d6?variant=devin --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Abhijeet Prasad <abhijeet@braintrustdata.com>
1 parent 0cb93c9 commit 6086f73

8 files changed

Lines changed: 154 additions & 49 deletions

File tree

‎py/README.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ Available extras:
6464
- `temporal`: installs Temporal integration dependencies
6565
- `all`: installs all optional extras
6666

67+
The `braintrust install` commands for AWS CloudFormation are deprecated. Use the
68+
[CloudFormation guide](https://docs.braintrust.dev/admin/self-hosting/aws-cloudformation)
69+
to manage existing stacks.
70+
6771
### Audio encoding
6872

6973
`braintrust[audio]` requires Python 3.12+ and uses PyAV's bundled FFmpeg codecs.
Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,18 @@
1-
import argparse
2-
import textwrap
1+
from argparse import RawDescriptionHelpFormatter
32

4-
5-
_module_not_found_error = None
6-
try:
7-
from . import api, bump_versions, logs, run_migrations
8-
except ModuleNotFoundError as e:
9-
_module_not_found_error = e
10-
11-
12-
def fail_with_module_not_found_error(*args, **kwargs):
13-
raise ModuleNotFoundError(
14-
textwrap.dedent(
15-
f"""\
16-
At least one dependency not found: {str(_module_not_found_error)!r}
17-
It is possible that braintrust was installed without the CLI dependencies. Run:
18-
19-
pip install 'braintrust[cli]'
20-
21-
to install braintrust with the CLI dependencies (make sure to quote 'braintrust[cli]')."""
22-
)
23-
)
3+
from . import api, bump_versions, logs, run_migrations
4+
from ._deprecation import DEPRECATION
245

256

267
def build_parser(subparsers, parent_parser):
278
install_parser = subparsers.add_parser(
289
"install",
29-
help="Tools to setup and verify Braintrust's installation in your environment.",
10+
help="Set up and verify a Braintrust CloudFormation stack (deprecated)",
11+
description=DEPRECATION,
12+
formatter_class=RawDescriptionHelpFormatter,
3013
parents=[parent_parser],
3114
)
32-
if _module_not_found_error:
33-
install_parser.add_argument("args", nargs=argparse.REMAINDER)
34-
install_parser.set_defaults(func=fail_with_module_not_found_error)
35-
else:
36-
install_subparsers = install_parser.add_subparsers(dest="install_subcommand", required=True)
15+
install_subparsers = install_parser.add_subparsers(dest="install_subcommand", required=True)
3716

38-
for module in [api, logs, bump_versions, run_migrations]:
39-
module.build_parser(install_subparsers, parents=[parent_parser])
17+
for module in [api, logs, bump_versions, run_migrations]:
18+
module.build_parser(install_subparsers, parents=[parent_parser])
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import sys
2+
import textwrap
3+
from argparse import RawDescriptionHelpFormatter
4+
from functools import wraps
5+
6+
7+
DEPRECATION = (
8+
"The braintrust install commands are deprecated.\n"
9+
"Use the CloudFormation guide for existing stacks:\n"
10+
"https://docs.braintrust.dev/admin/self-hosting/aws-cloudformation"
11+
)
12+
13+
14+
def add_deprecated_parser(subparsers, name, summary, parents, handler):
15+
parser = subparsers.add_parser(
16+
name,
17+
help=f"{summary} (deprecated)",
18+
description=f"{summary}.\n\n{DEPRECATION}",
19+
formatter_class=RawDescriptionHelpFormatter,
20+
parents=parents,
21+
)
22+
23+
@wraps(handler)
24+
def run(args):
25+
print("Warning: " + DEPRECATION.replace("\n", " "), file=sys.stderr)
26+
try:
27+
return handler(args)
28+
except ModuleNotFoundError as exc:
29+
if exc.name not in {"boto3", "botocore"}:
30+
raise
31+
raise ModuleNotFoundError(
32+
textwrap.dedent(
33+
f"""\
34+
At least one dependency not found: {str(exc)!r}
35+
It is possible that braintrust was installed without the CLI dependencies. Run:
36+
37+
pip install 'braintrust[cli]'
38+
39+
to install braintrust with the CLI dependencies (make sure to quote 'braintrust[cli]')."""
40+
)
41+
) from exc
42+
43+
parser.set_defaults(func=run)
44+
return parser

‎py/src/braintrust/cli/install/api.py‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33
import textwrap
44
import time
55

6-
from botocore.exceptions import ClientError
76
from braintrust.logger import app_conn, login
87

9-
# pylint: disable=no-name-in-module
10-
from ...aws import cloudformation
118
from ...util import response_raise_for_status
9+
from ._deprecation import add_deprecated_parser
1210

1311

1412
_logger = logging.getLogger("braintrust.install.api")
@@ -60,7 +58,7 @@
6058

6159

6260
def build_parser(subparsers, parents):
63-
parser = subparsers.add_parser("api", help="Install the Braintrust function API", parents=parents)
61+
parser = add_deprecated_parser(subparsers, "api", "Install the Braintrust function API", parents, main)
6462

6563
parser.add_argument("name", help="Name of the CloudFormation stack to create or update")
6664
parser.add_argument(
@@ -275,10 +273,13 @@ def build_parser(subparsers, parents):
275273
default=None,
276274
)
277275

278-
parser.set_defaults(func=main)
279-
280276

281277
def main(args):
278+
from botocore.exceptions import ClientError
279+
280+
# pylint: disable-next=no-name-in-module
281+
from ...aws import cloudformation
282+
282283
template = args.template or LATEST_TEMPLATE
283284

284285
status = None

‎py/src/braintrust/cli/install/bump_versions.py‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
import logging
22

3-
# pylint: disable=no-name-in-module
4-
from ...aws import LazyClient, cloudformation
3+
from ._deprecation import add_deprecated_parser
54

65

76
_logger = logging.getLogger("braintrust.install.logs")
87

98

109
def build_parser(subparsers, parents):
11-
parser = subparsers.add_parser(
12-
"bump-versions", help="Bump the version of each serverless function", parents=parents
10+
parser = add_deprecated_parser(
11+
subparsers, "bump-versions", "Bump the version of each serverless function", parents, main
1312
)
1413
parser.add_argument("name", help="Name of the CloudFormation stack")
15-
parser.set_defaults(func=main)
1614

1715

1816
def main(args):
17+
# pylint: disable-next=no-name-in-module
18+
from ...aws import LazyClient, cloudformation
19+
1920
resources = cloudformation.describe_stack_resources(StackName=args.name)
2021
lambda_ = LazyClient("lambda")
2122

‎py/src/braintrust/cli/install/logs.py‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,23 @@
22
import time
33
from concurrent.futures import ThreadPoolExecutor
44

5-
# pylint: disable=no-name-in-module
6-
from ...aws import cloudformation, logs
5+
from ._deprecation import add_deprecated_parser
76

87

98
_logger = logging.getLogger("braintrust.install.logs")
109

1110

1211
def build_parser(subparsers, parents):
13-
parser = subparsers.add_parser("logs", help="Capture recent logs", parents=parents)
12+
parser = add_deprecated_parser(subparsers, "logs", "Capture recent logs", parents, main)
1413
parser.add_argument("name", help="Name of the CloudFormation stack to collect logs from")
1514
parser.add_argument("--service", help="Name of the service", default="api", choices=["api", "brainstore", "all"])
1615
parser.add_argument("--hours", help="Number of hours in the past to collect logs from", default=1, type=float)
17-
parser.set_defaults(func=main)
1816

1917

2018
def main(args):
19+
# pylint: disable-next=no-name-in-module
20+
from ...aws import cloudformation, logs
21+
2122
stacks = cloudformation.describe_stacks(StackName=args.name)["Stacks"]
2223
if len(stacks) == 0:
2324
raise ValueError(f"Stack with name {args.name} does not exist")

‎py/src/braintrust/cli/install/run_migrations.py‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
import logging
22

3-
# pylint: disable=no-name-in-module
4-
from ...aws import LazyClient, cloudformation
3+
from ._deprecation import add_deprecated_parser
54

65

76
_logger = logging.getLogger("braintrust.install.logs")
87

98

109
def build_parser(subparsers, parents):
11-
parser = subparsers.add_parser("run-migrations", help="Run schema migrations", parents=parents)
10+
parser = add_deprecated_parser(subparsers, "run-migrations", "Run schema migrations", parents, main)
1211
parser.add_argument("name", help="Name of the CloudFormation stack")
13-
parser.set_defaults(func=main)
1412

1513

1614
def main(args):
15+
# pylint: disable-next=no-name-in-module
16+
from ...aws import LazyClient, cloudformation
17+
1718
resources = cloudformation.describe_stack_resources(StackName=args.name)
1819
migration_lambda = [r for r in resources["StackResources"] if r["LogicalResourceId"] == "MigrateDatabaseFunction"]
1920
if not migration_lambda:
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import os
2+
import shutil
3+
import subprocess
4+
import sysconfig
5+
6+
import pytest
7+
8+
9+
COMMANDS = ("api", "logs", "bump-versions", "run-migrations")
10+
GUIDE_URL = "https://docs.braintrust.dev/admin/self-hosting/aws-cloudformation"
11+
12+
13+
@pytest.fixture
14+
def cli():
15+
executable = shutil.which("braintrust", path=sysconfig.get_path("scripts"))
16+
assert executable is not None
17+
return executable
18+
19+
20+
@pytest.mark.parametrize("command", [(), *((name,) for name in COMMANDS)])
21+
def test_install_help(cli, command):
22+
result = subprocess.run(
23+
[cli, "install", *command, "--help"],
24+
capture_output=True,
25+
text=True,
26+
check=False,
27+
)
28+
29+
assert result.returncode == 0, result.stderr
30+
assert result.stderr == ""
31+
assert "deprecated" in result.stdout
32+
assert "Terraform" not in result.stdout
33+
assert GUIDE_URL in result.stdout
34+
if not command:
35+
assert result.stdout.count("(deprecated)") == len(COMMANDS)
36+
37+
38+
@pytest.mark.parametrize("command", COMMANDS)
39+
def test_install_warns_on_stderr_before_aws_setup(cli, command, tmp_path):
40+
result = subprocess.run(
41+
[cli, "install", command, "test-stack"],
42+
capture_output=True,
43+
text=True,
44+
check=False,
45+
env={
46+
**os.environ,
47+
"AWS_CONFIG_FILE": str(tmp_path / "config"),
48+
"AWS_SHARED_CREDENTIALS_FILE": str(tmp_path / "credentials"),
49+
"AWS_DEFAULT_PROFILE": "missing-test-profile",
50+
"AWS_PROFILE": "missing-test-profile",
51+
"AWS_EC2_METADATA_DISABLED": "true",
52+
},
53+
)
54+
55+
assert result.returncode == 1
56+
warning = result.stderr.splitlines()[0]
57+
assert warning.startswith("Warning:")
58+
assert "deprecated" in warning
59+
assert "Terraform" not in warning
60+
assert GUIDE_URL in warning
61+
assert GUIDE_URL not in result.stdout
62+
63+
64+
def test_install_requires_subcommand(cli):
65+
result = subprocess.run(
66+
[cli, "install"],
67+
capture_output=True,
68+
text=True,
69+
check=False,
70+
)
71+
72+
assert result.returncode == 2
73+
assert "usage:" in result.stderr
74+
assert "Warning:" not in result.stderr

0 commit comments

Comments
 (0)