Repository: conda/conda

Issue:
Would be nice if conda config --get channels listed the channels in priority order
As far as I can tell it currently lists them in reverse order. 



Discussion:
Good idea!

Wow, I was about to change this, but the code has a note

```
# Note, since conda config --add prepends, these are printed in
# the reverse order so that entering them in this order will
# recreate the same file
```

It's a good point.  And as implemented was intended to be a feature.  I don't think this is a bug anymore.  And if we change it, would have to go in 4.2.x instead of 4.1.x.  I have to think more about it.

I think one problem is that `--add` prepends.  It seems more natural to me that `--add` would append, and there should be a separate `--prepend` flag.

As a new feature (maybe not in 4.2.x), we should probably add both `--append` and `--prepend` flags.  Keep the `--add` flag as-is for a while, but warn on use, and eventually change the behavior for `--add` from prepend to append.

Good news: we already have append and prepend.

As a stopgap, you could perhaps add `# lowest priority` and `# highest priority` to the first and last lines of the output?

> Good news: we already have append and prepend.

Oh perfect. I thought we had added one of them.  Didn't remember if we put in both.


Resolving patch:
diff --git a/conda/cli/main_config.py b/conda/cli/main_config.py
--- a/conda/cli/main_config.py
+++ b/conda/cli/main_config.py
@@ -257,13 +257,19 @@ def execute_config(args, parser):
 
             if isinstance(rc_config[key], (bool, string_types)):
                 print("--set", key, rc_config[key])
-            else:
+            else:  # assume the key is a list-type
                 # Note, since conda config --add prepends, these are printed in
                 # the reverse order so that entering them in this order will
                 # recreate the same file
-                for item in reversed(rc_config.get(key, [])):
+                items = rc_config.get(key, [])
+                numitems = len(items)
+                for q, item in enumerate(reversed(items)):
                     # Use repr so that it can be pasted back in to conda config --add
-                    print("--add", key, repr(item))
+                    if key == "channels" and q in (0, numitems-1):
+                        print("--add", key, repr(item),
+                              "  # lowest priority" if q == 0 else "  # highest priority")
+                    else:
+                        print("--add", key, repr(item))
 
     # Add, append
     for arg, prepend in zip((args.add, args.append), (True, False)):


Test patch:
diff --git a/tests/test_config.py b/tests/test_config.py
--- a/tests/test_config.py
+++ b/tests/test_config.py
@@ -240,8 +240,8 @@ def test_config_command_get():
 --set always_yes True
 --set changeps1 False
 --set channel_alias http://alpha.conda.anaconda.org
---add channels 'defaults'
---add channels 'test'
+--add channels 'defaults'   # lowest priority
+--add channels 'test'   # highest priority
 --add create_default_packages 'numpy'
 --add create_default_packages 'ipython'\
 """
@@ -251,8 +251,8 @@ def test_config_command_get():
         '--get', 'channels')
 
         assert stdout == """\
---add channels 'defaults'
---add channels 'test'\
+--add channels 'defaults'   # lowest priority
+--add channels 'test'   # highest priority\
 """
         assert stderr == ""
 
@@ -269,8 +269,8 @@ def test_config_command_get():
 
         assert stdout == """\
 --set changeps1 False
---add channels 'defaults'
---add channels 'test'\
+--add channels 'defaults'   # lowest priority
+--add channels 'test'   # highest priority\
 """
         assert stderr == ""
 
@@ -326,12 +326,12 @@ def test_config_command_parser():
 
     with make_temp_condarc(condarc) as rc:
         stdout, stderr = run_conda_command('config', '--file', rc, '--get')
-
+        print(stdout)
         assert stdout == """\
 --set always_yes True
 --set changeps1 False
---add channels 'defaults'
---add channels 'test'
+--add channels 'defaults'   # lowest priority
+--add channels 'test'   # highest priority
 --add create_default_packages 'numpy'
 --add create_default_packages 'ipython'\
 """