Skip to content

Commit

Permalink
Merge pull request conda#224 from jonashaag/patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusvniekerk authored Jul 31, 2022
2 parents b9d56fc + 0092410 commit 7d9bd6d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 5 additions & 5 deletions conda_lock/models/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@


logger = logging.getLogger(__name__)
token_pattern = re.compile(r"(.*)(/t/\$?[a-zA-Z0-9-_]*)(/.*)")
token_pattern = re.compile(r"(.*)(/t/\$?\{?[a-zA-Z0-9-_]*\}?)(/.*)")


class CondaUrl(BaseModel):
Expand All @@ -75,7 +75,7 @@ def conda_token_replaced_url(self) -> str:
# TODO: pass in env vars maybe?
expanded_url = expandvars(self.env_var_url)
if token_pattern.match(expanded_url):
replaced, _ = token_pattern.subn(r"\1\3", expanded_url, 1)
replaced = token_pattern.sub(r"\1\3", expanded_url, 1)
p = urlparse(replaced)
replaced = urlunparse(p._replace(path="/t/<TOKEN>" + p.path))
return replaced
Expand Down Expand Up @@ -127,7 +127,7 @@ def conda_token_replaced_url(self) -> str:
# TODO: pass in env vars maybe?
expanded_url = expandvars(self.url)
if token_pattern.match(expanded_url):
replaced, _ = token_pattern.subn(r"\1\3", expanded_url, 1)
replaced = token_pattern.sub(r"\1\3", expanded_url, 1)
p = urlparse(replaced)
replaced = urlunparse(p._replace(path="/t/<TOKEN>" + p.path))
return replaced
Expand All @@ -137,13 +137,13 @@ def conda_token_replaced_url(self) -> str:
def detect_used_env_var(
value: str, preferred_env_var_suffix: List[str]
) -> Optional[str]:
"""Detects if the strincg exactly matches any current environment variable
"""Detects if the string exactly matches any current environment variable
Preference is given to variables that end in the suffixes provided
"""

if value.startswith("$"):
return value.lstrip("$")
return value.lstrip("$").strip("{}")
for suffix in preferred_env_var_suffix + [""]:
candidates = {v: k for k, v in os.environ.items() if k.upper().endswith(suffix)}
# try first with a simple match
Expand Down
4 changes: 3 additions & 1 deletion tests/test_conda_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -1266,13 +1266,15 @@ def test_fake_conda_env(conda_exe: str, conda_lock_yaml: Path):
assert platform == path.parent.name


@pytest.mark.parametrize("placeholder", ["$QUETZ_API_KEY", "${QUETZ_API_KEY}"])
@flaky
def test_private_lock(
quetz_server: "QuetzServerInfo",
tmp_path: Path,
monkeypatch: "pytest.MonkeyPatch",
capsys: "pytest.CaptureFixture[str]",
conda_exe: str,
placeholder,
):
if is_micromamba(conda_exe):
res = subprocess.run(
Expand All @@ -1287,7 +1289,7 @@ def test_private_lock(

content = yaml.safe_dump(
{
"channels": [f"{quetz_server.url}/t/$QUETZ_API_KEY/get/proxy-channel"],
"channels": [f"{quetz_server.url}/t/{placeholder}/get/proxy-channel"],
"platforms": [platform_subdir()],
"dependencies": ["zlib"],
}
Expand Down

0 comments on commit 7d9bd6d

Please sign in to comment.