Repository: conda/conda

Issue:
conda -h => ValueError: unsupported format character
(jupyterlab) C:\Users\scuba>conda -h

# >>>>>>>>>>>>>>>>>>>>>> ERROR REPORT <<<<<<<<<<<<<<<<<<<<<<

    Traceback (most recent call last):
      File "E:\Miniconda3\lib\site-packages\conda\exceptions.py", line 724, in __call__
        return func(*args, **kwargs)
      File "E:\Miniconda3\lib\site-packages\conda\cli\main.py", line 71, in _main
        args = p.parse_args(args[1:])
      File "E:\Miniconda3\lib\argparse.py", line 1730, in parse_args
        args, argv = self.parse_known_args(args, namespace)
      File "E:\Miniconda3\lib\argparse.py", line 1762, in parse_known_args
        namespace, args = self._parse_known_args(args, namespace)
      File "E:\Miniconda3\lib\argparse.py", line 1968, in _parse_known_args
        start_index = consume_optional(start_index)
      File "E:\Miniconda3\lib\argparse.py", line 1908, in consume_optional
        take_action(action, args, option_string)
      File "E:\Miniconda3\lib\argparse.py", line 1836, in take_action
        action(self, namespace, argument_values, option_string)
      File "E:\Miniconda3\lib\argparse.py", line 1020, in __call__
        parser.print_help()
      File "E:\Miniconda3\lib\site-packages\conda\cli\conda_argparse.py", line 149, in print_help
        super(ArgumentParser, self).print_help()
      File "E:\Miniconda3\lib\argparse.py", line 2362, in print_help
        self._print_message(self.format_help(), file)
      File "E:\Miniconda3\lib\argparse.py", line 2346, in format_help
        return formatter.format_help()
      File "E:\Miniconda3\lib\argparse.py", line 282, in format_help
        help = self._root_section.format_help()
      File "E:\Miniconda3\lib\argparse.py", line 213, in format_help
        item_help = join([func(*args) for func, args in self.items])
      File "E:\Miniconda3\lib\argparse.py", line 213, in <listcomp>
        item_help = join([func(*args) for func, args in self.items])
      File "E:\Miniconda3\lib\argparse.py", line 213, in format_help
        item_help = join([func(*args) for func, args in self.items])
      File "E:\Miniconda3\lib\argparse.py", line 213, in <listcomp>
        item_help = join([func(*args) for func, args in self.items])
      File "E:\Miniconda3\lib\argparse.py", line 531, in _format_action
        parts.append(self._format_action(subaction))
      File "E:\Miniconda3\lib\argparse.py", line 519, in _format_action
        help_text = self._expand_help(action)
      File "E:\Miniconda3\lib\argparse.py", line 606, in _expand_help
        return self._get_help_string(action) % params
    ValueError: unsupported format character 'U' (0x55) at index 140

is there a fix for this?


Discussion:
What is the output of `conda info`?
(base) C:\Users\scuba>conda info

     active environment : base
    active env location : E:\Miniconda3
            shell level : 1
       user config file : C:\Users\scuba\%USERPROFILE%\.condarc
 populated config files : C:\Users\scuba\%USERPROFILE%\.condarc
          conda version : 4.4.6
    conda-build version : not installed
         python version : 3.6.3.final.0
       base environment : E:\Miniconda3  (writable)
           channel URLs : https://repo.continuum.io/pkgs/main/win-64
                          https://repo.continuum.io/pkgs/main/noarch
                          https://repo.continuum.io/pkgs/free/win-64
                          https://repo.continuum.io/pkgs/free/noarch
                          https://repo.continuum.io/pkgs/r/win-64
                          https://repo.continuum.io/pkgs/r/noarch
                          https://repo.continuum.io/pkgs/pro/win-64
                          https://repo.continuum.io/pkgs/pro/noarch
                          https://repo.continuum.io/pkgs/msys2/win-64
                          https://repo.continuum.io/pkgs/msys2/noarch
          package cache : E:\Miniconda3\pkgs
                          C:\Users\scuba\AppData\Local\conda\conda\pkgs
       envs directories : E:\Miniconda3\envs
                          C:\Users\scuba\AppData\Local\conda\conda\envs
                          C:\Users\scuba\%USERPROFILE%\.conda\envs
               platform : win-64
             user-agent : conda/4.4.6 requests/2.18.4 CPython/3.6.3 Windows/10 Windows/10.0.15063
          administrator : False
             netrc file : None
           offline mode : False


%USERPROFILE%  appears to be the problem (windows 10) but how to solve it?

Resolving patch:
diff --git a/conda/cli/conda_argparse.py b/conda/cli/conda_argparse.py
--- a/conda/cli/conda_argparse.py
+++ b/conda/cli/conda_argparse.py
@@ -19,7 +19,8 @@
 # duplicated code in the interest of import efficiency
 on_win = bool(sys.platform == "win32")
 user_rc_path = abspath(expanduser('~/.condarc'))
-sys_rc_path = join(sys.prefix, '.condarc')
+escaped_user_rc_path = user_rc_path.replace("%", "%%")
+escaped_sys_rc_path = abspath(join(sys.prefix, '.condarc')).replace("%", "%%")
 
 
 def generate_parser():
@@ -297,7 +298,7 @@ def configure_parser_config(sub_parsers):
     Modify configuration values in .condarc.  This is modeled after the git
     config command.  Writes to the user .condarc file (%s) by default.
 
-    """) % user_rc_path
+    """) % escaped_user_rc_path
 
     # Note, the extra whitespace in the list keys is on purpose. It's so the
     # formatting from help2man is still valid YAML (otherwise it line wraps the
@@ -357,22 +358,25 @@ def configure_parser_config(sub_parsers):
         "--system",
         action="store_true",
         help="""Write to the system .condarc file ({system}). Otherwise writes to the user
-        config file ({user}).""".format(system=sys_rc_path,
-                                        user=user_rc_path),
+        config file ({user}).""".format(system=escaped_sys_rc_path,
+                                        user=escaped_user_rc_path),
     )
     location.add_argument(
         "--env",
         action="store_true",
         help="Write to the active conda environment .condarc file (%s). "
              "If no environment is active, write to the user config file (%s)."
-             "" % (os.getenv('CONDA_PREFIX', "<no active environment>"), user_rc_path),
+             "" % (
+                 os.getenv('CONDA_PREFIX', "<no active environment>").replace("%", "%%"),
+                 escaped_user_rc_path,
+             ),
     )
     location.add_argument(
         "--file",
         action="store",
         help="""Write to the given file. Otherwise writes to the user config file ({user})
 or the file path given by the 'CONDARC' environment variable, if it is set
-(default: %(default)s).""".format(user=user_rc_path),
+(default: %(default)s).""".format(user=escaped_user_rc_path),
         default=os.environ.get('CONDARC', user_rc_path)
     )
 


Test patch: