Skip to content

Commit

Permalink
Revert "exp-push: show url to the Studio project" (iterative#9282)
Browse files Browse the repository at this point in the history
Revert "exp-push: show url to the Studio project (iterative#9278)"

This reverts commit 1ca3ef1.
  • Loading branch information
skshetry authored Mar 30, 2023
1 parent 1ca3ef1 commit 780dc72
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 32 deletions.
9 changes: 3 additions & 6 deletions dvc/commands/experiments/push.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def run(self):

self.raise_error_if_all_disabled()

result = self.repo.experiments.push(
pushed_exps = self.repo.experiments.push(
self.args.git_remote,
self.args.experiment,
all_commits=self.args.all_commits,
Expand All @@ -35,17 +35,14 @@ def run(self):
jobs=self.args.jobs,
run_cache=self.args.run_cache,
)
if pushed_exps := result.get("pushed"):

if pushed_exps:
ui.write(
f"Pushed experiment {humanize.join(map(repr, pushed_exps))} "
f"to Git remote {self.args.git_remote!r}."
)
else:
ui.write("No experiments to push.")

if project_url := result.get("url"):
ui.write("[yellow]View your experiments at", project_url, styled=True)

if not self.args.push_cache:
ui.write(
"To push cached outputs",
Expand Down
31 changes: 9 additions & 22 deletions dvc/repo/experiments/push.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
import logging
from typing import (
TYPE_CHECKING,
Any,
Dict,
Iterable,
List,
Mapping,
Optional,
Set,
Union,
)
from typing import TYPE_CHECKING, Any, Iterable, List, Mapping, Optional, Set, Union

from funcy import compact, group_by
from scmrepo.git.backend.base import SyncStatus
Expand All @@ -30,36 +20,33 @@
logger = logging.getLogger(__name__)


def notify_refs_to_studio(
repo: "Repo", git_remote: str, **refs: List[str]
) -> Optional[str]:
def notify_refs_to_studio(repo: "Repo", git_remote: str, **refs: List[str]) -> None:
config = repo.config["feature"]
refs = compact(refs)
if not refs or env2bool("DVC_TEST"):
return None
return

if not (config.get("studio_token") or config["push_exp_to_studio"]):
logger.debug(
"Either feature.studio_token or feature.push_exp_to_studio config "
"needs to be set."
)
return None
return

import os

token = os.environ.get("STUDIO_TOKEN") or config.get("studio_token")
if not token:
logger.debug("Studio token not found.")
return None
return

from dulwich.porcelain import get_remote_repo

from dvc.utils import studio

_, repo_url = get_remote_repo(repo.scm.dulwich.repo, git_remote)
studio_url = config.get("studio_url")
d = studio.notify_refs(repo_url, token, studio_url=studio_url, **refs)
return d.get("url")
studio.notify_refs(repo_url, token, studio_url=studio_url, **refs)


@locked
Expand All @@ -74,7 +61,7 @@ def push( # noqa: C901
force: bool = False,
push_cache: bool = False,
**kwargs: Any,
) -> Dict[str, Any]:
) -> Iterable[str]:
exp_ref_set: Set["ExpRefInfo"] = set()
assert isinstance(repo.scm, Git)
if all_commits:
Expand Down Expand Up @@ -119,8 +106,8 @@ def push( # noqa: C901

refs = push_result[SyncStatus.SUCCESS]
pushed_refs = [str(r) for r in refs]
url = notify_refs_to_studio(repo, git_remote, pushed=pushed_refs)
return {"pushed": [ref.name for ref in refs], "url": url}
notify_refs_to_studio(repo, git_remote, pushed=pushed_refs)
return [ref.name for ref in refs]


def _push(
Expand Down
5 changes: 1 addition & 4 deletions tests/func/experiments/test_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,7 @@ def test_push_diverged(tmp_dir, scm, dvc, git_upstream, exp_stage):

git_upstream.tmp_dir.scm.set_ref(str(ref_info), remote_rev)

assert dvc.experiments.push(git_upstream.remote, [ref_info.name]) == {
"pushed": [],
"url": None,
}
assert dvc.experiments.push(git_upstream.remote, [ref_info.name]) == []
assert git_upstream.tmp_dir.scm.get_ref(str(ref_info)) == remote_rev

dvc.experiments.push(git_upstream.remote, [ref_info.name], force=True)
Expand Down

0 comments on commit 780dc72

Please sign in to comment.