Skip to content

Commit

Permalink
Merge pull request #12931 from conda/23.7.x
Browse files Browse the repository at this point in the history
  • Loading branch information
kenodegard committed Jul 27, 2023
2 parents 6d5f755 + 7964b95 commit 1b53c20
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 20 deletions.
6 changes: 3 additions & 3 deletions .authors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1519,7 +1519,7 @@
first_commit: 2019-08-26 04:18:04
- name: Jannis Leidel
email: jannis@leidel.info
num_commits: 100
num_commits: 101
first_commit: 2021-06-07 16:46:45
github: jezdez
- name: Saranya Mahalingam
Expand Down Expand Up @@ -1957,7 +1957,7 @@
first_commit: 2016-12-11 16:14:03
- name: Ken Odegard
email: kodegard@anaconda.com
num_commits: 546
num_commits: 552
first_commit: 2016-09-27 18:04:21
github: kenodegard
aliases:
Expand Down Expand Up @@ -2083,7 +2083,7 @@
github: beeankha
alternate_emails:
- beeankha@gmail.com
num_commits: 27
num_commits: 25
first_commit: 2022-05-12 13:39:02
- name: Kian-Meng Ang
email: kianmeng.ang@gmail.com
Expand Down
2 changes: 1 addition & 1 deletion .mailmap
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ Matthew Wardrop <mpwardrop@gmail.com>
Matthieu Guillaumin <matthieg@amazon.com>
MatthieuDartiailh <marul@laposte.net>
Matti Picus <matti.picus@gmail.com> mattip <matti.picus@gmail.com>
Maurice Meyer <morre@mor.re> morre <morre@mor.re>
Maurice Meyer <morre@mor.re>
Max Reeder <reeder.max@gmail.com>
Maximilian Noethe <maximilian.noethe@tu-dortmund.de>
Maya Gilad <ms.maya.gilad@gmail.com> mayagilad <ms.maya.gilad@gmail.com>
Expand Down
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
[//]: # (current developments)

## 23.7.1 (2023-07-26)

### Bug fixes

* Patch parsed args with pre_args to correctly parse `--json` and `--debug` arguments. (#12928, #12929)

### Contributors

* @jezdez
* @kenodegard



## 23.7.0 (2023-07-25)

### Enhancements
Expand Down
6 changes: 6 additions & 0 deletions conda/cli/conda_argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,12 @@ def _check_value(self, action, value):
else:
super()._check_value(action, value)

def parse_args(self, *args, override_args=None, **kwargs):
parsed_args = super().parse_args(*args, **kwargs)
for name, value in (override_args or {}).items():
setattr(parsed_args, name, value)
return parsed_args


class _GreedySubParsersAction(argparse._SubParsersAction):
"""A custom subparser action to conditionally act as a greedy consumer.
Expand Down
5 changes: 4 additions & 1 deletion conda/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ def main_subshell(*args, post_parse_hook=None, **kwargs):
pre_parser = generate_pre_parser(add_help=False)
pre_args, unknown = pre_parser.parse_known_args(args)

# the arguments that we want to pass to the main parser later on
override_args = {"json": pre_args.json, "debug": pre_args.debug}

context.__init__(argparse_args=pre_args)
if context.no_plugins:
context.plugin_manager.disable_external_plugins()
Expand All @@ -49,7 +52,7 @@ def main_subshell(*args, post_parse_hook=None, **kwargs):
context.__init__(argparse_args=pre_args)

parser = generate_parser(add_help=True)
args = parser.parse_args(unknown, namespace=pre_args)
args = parser.parse_args(unknown, override_args=override_args, namespace=pre_args)

context.__init__(argparse_args=args)
init_loggers(context)
Expand Down
36 changes: 21 additions & 15 deletions conda/testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,28 +178,34 @@ def __call__(self, *argv: str) -> tuple[str, str, int]:
:return: Command results
:rtype: tuple[stdout, stdout, exitcode]
"""
# extra checks to handle legacy subcommands
# ensure arguments are string
argv = tuple(map(str, argv))

# mock legacy subcommands
if argv[0] == "env":
from conda_env.cli.main import create_parser as generate_parser
from conda_env.cli.main import do_call
from conda_env.cli.main import create_parser, do_call

argv = argv[1:]
else:
from conda.cli.conda_argparse import do_call, generate_parser

# ensure arguments are string
argv = tuple(map(str, argv))
# parse arguments
parser = create_parser()
args = parser.parse_args(argv)

# initialize context and loggers
context.__init__(argparse_args=args)
init_loggers(context)

# parse arguments
parser = generate_parser()
args = parser.parse_args(argv)
# run command
code = do_call(args, parser)

# all other subcommands
else:
from conda.cli.main import main_subshell

# initialize context and loggers
context.__init__(argparse_args=args)
init_loggers(context)
# run command
code = main_subshell(*argv)

# run command
code = do_call(args, parser)
# capture output
out, err = self.capsys.readouterr()

# restore to prior state
Expand Down
15 changes: 15 additions & 0 deletions tests/cli/test_subcommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# SPDX-License-Identifier: BSD-3-Clause
from __future__ import annotations

import json
from pathlib import Path
from typing import Callable, ContextManager

Expand Down Expand Up @@ -71,6 +72,20 @@ def test_info(conda_cli: CondaCLIFixture):
assert not code


def test_info_json(conda_cli: CondaCLIFixture):
out1, err, code = conda_cli("info", "--json")
assert json.loads(out1)
assert not err
assert not code

out2, err, code = conda_cli("--json", "info")
assert json.loads(out2)
assert not err
assert not code

assert out1 == out2


def test_init(conda_cli: CondaCLIFixture):
out, err, code = conda_cli("init", "--dry-run")
assert out
Expand Down

0 comments on commit 1b53c20

Please sign in to comment.