Skip to content

Commit

Permalink
Set --no-repodata-zst argument as NULL; alias no_use_repodata_zst for…
Browse files Browse the repository at this point in the history
… config file (#13530)

* set --no-repodata-zst argument as NULL; alias no_use_repodata_zst for config file

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
dholth and pre-commit-ci[bot] committed Jan 30, 2024
1 parent 78e494b commit 595de2b
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 12 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ command line interface related to environment management. (#13168)
* Provide a more useful warning when attempting to rename a non-existent prefix. (#13387)
* Add a new flag `--keep-env` to be used with `conda remove --all`. It allows users to delete all packages in the environment while retaining the environment itself. (#13419)
* Add a Y/N prompt warning users that `conda env remove` and `conda remove --all` deletes not only the conda packages but the entirety of the specified environment. (#13440)
* Add `--no-repodata-zst` flag to skip `repodata.json.zst` check. Useful if the repo returns unparseable `repodata.json.zst` instead of correct data or 404. (#13504)
* Add `--repodata-use-zst/--no-repodata-use-zst` flag to control `repodata.json.zst` check; corresponding `repodata_use_zst: true/false` for `.condarc`. Default is to check for `repodata.json.zst`. Disable if remote returns unparseable `repodata.json.zst` instead of correct data or 404. (#13504)


### Bug fixes

Expand Down
6 changes: 3 additions & 3 deletions conda/base/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ class Context(Configuration):
)
experimental = ParameterLoader(SequenceParameter(PrimitiveParameter("", str)))
no_lock = ParameterLoader(PrimitiveParameter(False))
no_repodata_zst = ParameterLoader(PrimitiveParameter(False))
repodata_use_zst = ParameterLoader(PrimitiveParameter(True))

####################################################
# Solver Configuration #
Expand Down Expand Up @@ -1164,7 +1164,7 @@ def category_map(self):
"fetch_threads",
"experimental",
"no_lock",
"no_repodata_zst",
"repodata_use_zst",
),
"Basic Conda Configuration": ( # TODO: Is there a better category name here?
"envs_dirs",
Expand Down Expand Up @@ -1836,7 +1836,7 @@ def description_map(self):
Disable index cache lock (defaults to enabled).
"""
),
no_repodata_zst=dals(
repodata_use_zst=dals(
"""
Disable check for `repodata.json.zst`; use `repodata.json` only.
"""
Expand Down
55 changes: 52 additions & 3 deletions conda/cli/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,52 @@
_MutuallyExclusiveGroup,
)

try:
from argparse import BooleanOptionalAction
except ImportError:
# Python < 3.9
from argparse import Action

class BooleanOptionalAction(Action):
# from Python 3.9+ argparse.py
def __init__(
self,
option_strings,
dest,
default=None,
type=None,
choices=None,
required=False,
help=None,
metavar=None,
):
_option_strings = []
for option_string in option_strings:
_option_strings.append(option_string)

if option_string.startswith("--"):
option_string = "--no-" + option_string[2:]
_option_strings.append(option_string)

super().__init__(
option_strings=_option_strings,
dest=dest,
nargs=0,
default=default,
type=type,
choices=choices,
required=required,
help=help,
metavar=metavar,
)

def __call__(self, parser, namespace, values, option_string=None):
if option_string in self.option_strings:
setattr(namespace, self.dest, not option_string.startswith("--no-"))

Check warning on line 57 in conda/cli/helpers.py

View check run for this annotation

Codecov / codecov/patch

conda/cli/helpers.py#L57

Added line #L57 was not covered by tests

def format_usage(self):
return " | ".join(self.option_strings)

Check warning on line 60 in conda/cli/helpers.py

View check run for this annotation

Codecov / codecov/patch

conda/cli/helpers.py#L60

Added line #L60 was not covered by tests


def add_parser_create_install_update(p, prefix_required=False):
from ..common.constants import NULL
Expand Down Expand Up @@ -222,10 +268,13 @@ def add_parser_channels(p: ArgumentParser) -> _ArgumentGroup:
action="store_true",
help="Disable locking when reading, updating index (repodata.json) cache. ",
)

channel_customization_options.add_argument(
"--no-repodata-zst",
action="store_true",
help="Do not check for repodata.json.zst.",
"--repodata-use-zst",
action=BooleanOptionalAction,
dest="repodata_use_zst",
default=NULL,
help="Check for/do not check for repodata.json.zst. Enabled by default.",
)
return channel_customization_options

Expand Down
2 changes: 1 addition & 1 deletion conda/gateways/repodata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def get_repo_interface() -> type[RepoInterface]:
f"Is the required jsonpatch package installed? {e}"
)

if not context.no_repodata_zst:
if context.repodata_use_zst:
try:
from .jlap.interface import ZstdRepoInterface

Expand Down
10 changes: 6 additions & 4 deletions tests/gateways/test_jlap.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,11 +367,13 @@ def test_jlap_flag(use_jlap):
assert get_repo_interface() is interface.JlapRepoInterface


@pytest.mark.parametrize("no_repodata_zst", [True, False])
def test_no_repodata_zst(no_repodata_zst):
expected = CondaRepoInterface if no_repodata_zst else interface.ZstdRepoInterface
@pytest.mark.parametrize("repodata_use_zst", [True, False])
def test_repodata_use_zst(repodata_use_zst):
expected = (
CondaRepoInterface if not repodata_use_zst else interface.ZstdRepoInterface
)
with env_vars(
{"CONDA_NO_REPODATA_ZST": no_repodata_zst},
{"CONDA_REPODATA_USE_ZST": repodata_use_zst},
stack_callback=conda_tests_ctxt_mgmt_def_pol,
):
assert get_repo_interface() is expected
Expand Down

0 comments on commit 595de2b

Please sign in to comment.