Skip to content

Commit

Permalink
refactor notify_refs_to_studio
Browse files Browse the repository at this point in the history
  • Loading branch information
dberenbaum authored and dberenbaum committed Mar 11, 2024
1 parent 837c8e8 commit a96a446
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 22 deletions.
25 changes: 11 additions & 14 deletions dvc/repo/experiments/push.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from funcy import compact, group_by
from scmrepo.git.backend.base import SyncStatus

from dvc.env import DVC_STUDIO_TOKEN, DVC_STUDIO_URL
from dvc.exceptions import DvcException
from dvc.log import logger
from dvc.repo import locked
Expand Down Expand Up @@ -32,28 +31,26 @@ def __init__(self, msg, result):
def notify_refs_to_studio(
repo: "Repo", git_remote: str, **refs: list[str]
) -> Optional[str]:
import os
from dvc_studio_client.config import get_studio_config

from dvc.utils import studio

config = repo.config["studio"]
refs = compact(refs)
if not refs or env2bool("DVC_TEST"):
return None

token = (
os.environ.get(DVC_STUDIO_TOKEN)
or os.environ.get("STUDIO_TOKEN")
or config.get("token")
)
config = repo.config["studio"]
config = get_studio_config(dvc_studio_config=config)
token = config.get("token")
studio_url = config.get("url")
if not token:
logger.debug("Studio token not found.")
return None
repo_url = studio.get_repo_url(repo, git_remote)
if not repo_url:
logger.debug("Git remote repo URL not found.")
return None

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 = os.environ.get(DVC_STUDIO_URL) or config.get("url")
d = studio.notify_refs(repo_url, token, base_url=studio_url, **refs)
return d.get("url")

Expand Down
2 changes: 1 addition & 1 deletion dvc/repo/experiments/queue/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from dataclasses import asdict, dataclass
from typing import TYPE_CHECKING, Any, NamedTuple, Optional, Union

from dvc_studio_client.post_live_metrics import get_studio_config
from dvc_studio_client.config import get_studio_config
from funcy import retry

from dvc.dependency import ParamsDependency
Expand Down
16 changes: 9 additions & 7 deletions dvc/utils/studio.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,17 +128,19 @@ def get_subrepo_relpath(repo: "Repo") -> str:
return "" if relpath == "." else relpath


def get_repo_url(repo: "Repo") -> str:
def get_repo_url(repo: "Repo", git_remote: Optional[str] = None) -> str | None:
from dulwich.porcelain import get_remote_repo

from dvc.env import DVC_EXP_GIT_REMOTE

repo_url = os.getenv(
DVC_EXP_GIT_REMOTE, repo.config.get("exp", {}).get("git_remote")
)
if repo_url:
if not git_remote:
git_remote = os.getenv(
DVC_EXP_GIT_REMOTE, repo.config.get("exp", {}).get("git_remote")
)
if git_remote:
try:
_, repo_url = get_remote_repo(repo.scm.dulwich.repo, repo_url)
_, repo_url = get_remote_repo(repo.scm.dulwich.repo, git_remote)
return repo_url
except IndexError:
pass
return repo_url
return git_remote

0 comments on commit a96a446

Please sign in to comment.