Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to set team in config for studio #527

Merged
merged 2 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/datachain/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,30 @@ def add_studio_parser(subparsers, parent_parser) -> None:
help=studio_logout_help,
)

studio_team_help = "Set the default team for Datachain"
amritghimire marked this conversation as resolved.
Show resolved Hide resolved
studio_team_description = (
"Set the default team for Datachain to use when interacting with Studio."
)

team_parser = studio_subparser.add_parser(
"team",
parents=[parent_parser],
description=studio_team_description,
help=studio_team_help,
)
# Add a positional argument for the team name
amritghimire marked this conversation as resolved.
Show resolved Hide resolved
team_parser.add_argument(
"team_name",
action="store",
help="The name of the team to set as the default.",
)
team_parser.add_argument(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it system or user config?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default, it is global config. Example: /Users/amritghimire/Library/Application Support/datachain/config

"--global",
action="store_true",
default=False,
help="Set the team globally for all Datachain projects.",
)

studio_token_help = "View the token datachain uses to contact Studio" # noqa: S105 # nosec B105

studio_subparser.add_parser(
Expand Down
13 changes: 13 additions & 0 deletions src/datachain/studio.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,22 @@ def process_studio_cli_args(args: "Namespace"):
return logout()
if args.cmd == "token":
return token()
if args.cmd == "team":
return set_team(args)
raise DataChainError(f"Unknown command '{args.cmd}'.")


def set_team(args: "Namespace"):
level = ConfigLevel.GLOBAL if args.__dict__.get("global") else ConfigLevel.LOCAL
config = Config(level)
with config.edit() as conf:
studio_conf = conf.get("studio", {})
studio_conf["team"] = args.team_name
conf["studio"] = studio_conf

print(f"Set default team to '{args.team_name}' in {config.config_file()}")


def login(args: "Namespace"):
from dvc_studio_client.auth import StudioAuthError, get_access_token

Expand Down
12 changes: 12 additions & 0 deletions tests/test_cli_studio.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,15 @@ def test_studio_token(capsys):
del conf["studio"]["token"]

assert main(["studio", "token"]) == 1


def test_studio_team_local():
assert main(["studio", "team", "team_name"]) == 0
config = Config(ConfigLevel.LOCAL).read()
assert config["studio"]["team"] == "team_name"


def test_studio_team_global():
assert main(["studio", "team", "team_name", "--global"]) == 0
config = Config(ConfigLevel.GLOBAL).read()
assert config["studio"]["team"] == "team_name"