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

fix: allow for private anaconda channels #53

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 12 additions & 2 deletions metaflow_extensions/netflix_ext/plugins/conda/conda.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
from concurrent.futures import ThreadPoolExecutor, as_completed
from contextlib import closing
from datetime import datetime
from pathlib import Path
from shutil import which
from typing import (
Any,
Callable,
Expand All @@ -33,7 +35,7 @@
Union,
cast,
)
from shutil import which
from urllib.parse import urlparse, urlunparse

from requests.auth import AuthBase
from urllib3 import Retry
Expand Down Expand Up @@ -1377,9 +1379,17 @@ def _download_web(
"%s -> download %s to %s"
% (pkg_spec.filename, pkg_spec.url, local_path)
)
url = pkg_spec.url
up = urlparse(url)
if up.hostname == "conda.anaconda.org":
token = Path(
f"{os.path.expanduser('~')}/.continuum/anaconda-client/tokens/https%3A%2F%2Fapi.anaconda.org.token"
)
if token.exists():
url = urlunparse([*up[:2], f"/t/{token.read_text()}{up.path}", *up[3:]])
try:
with open(local_path, "wb") as f:
with session.get(pkg_spec.url, stream=True, auth=auth_info) as r:
with session.get(url, stream=True, auth=auth_info) as r:
r.raise_for_status()
for chunk in r.iter_content(chunk_size=None):
base_hash.update(chunk)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ def _pkg_key(
lnk["build_number"],
)
url, md5_hash = fetched_packages[k]
url = url.replace("/t/<TOKEN>", "")
if not url.startswith(lnk["base_url"]):
raise CondaException(
"Unexpected record for %s: %s" % (k, str(conda_result))
Expand Down
4 changes: 2 additions & 2 deletions metaflow_extensions/netflix_ext/plugins/conda/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,14 +574,14 @@ def normalize_to_underscore(name: str) -> str:

def channel_from_url(url: str) -> Optional[str]:
up = urlparse(url)
if up.hostname == "conda.anaconda.org":
if up.hostname == "conda.anaconda.org" and not up.path.startswith("/t/"):
return up.path.split("/", 2)[1]
return None


def channel_or_url(url: str) -> str:
up = urlparse(url)
if up.hostname == "conda.anaconda.org":
if up.hostname == "conda.anaconda.org" and not up.path.startswith("/t/"):
return up.path.split("/", 2)[1]
return url

Expand Down