internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: conda/conda

Issue:
Add ability to keep retrying with a lock error
The yum installer (IIRC) has a nice feature that it will keep trying every 10 seconds or so if there is a lock error. This could be useful for conda. 



Discussion:

Resolving patch:
diff --git a/conda/lock.py b/conda/lock.py
--- a/conda/lock.py
+++ b/conda/lock.py
@@ -19,7 +19,7 @@
 import os
 from os.path import join
 import glob
-
+from time import sleep
 
 LOCKFN = '.conda_lock'
 
@@ -36,15 +36,28 @@ def __init__(self, path):
         self.remove = True
 
     def __enter__(self):
-        files = glob.glob(self.pattern)
-        if files and not files[0].endswith(self.end):
-            # Keep the string "LOCKERROR" in this string so that external
-            # programs can look for it.
-            raise RuntimeError("""\
-LOCKERROR: It looks like conda is already doing something.
-The lock %s was found. Wait for it to finish before continuing.
-If you are sure that conda is not running, remove it and try again.
-You can also use: $ conda clean --lock""" % self.lock_path)
+        retries = 10
+        # Keep the string "LOCKERROR" in this string so that external
+        # programs can look for it.
+        lockstr = ("""\
+    LOCKERROR: It looks like conda is already doing something.
+    The lock %s was found. Wait for it to finish before continuing.
+    If you are sure that conda is not running, remove it and try again.
+    You can also use: $ conda clean --lock""" % self.lock_path)
+        sleeptime = 1
+        while retries:
+            files = glob.glob(self.pattern)
+            if files and not files[0].endswith(self.end):
+                print(lockstr)
+                print("Sleeping for %s seconds" % sleeptime)
+                sleep(sleeptime)
+                sleeptime *= 2
+                retries -= 1
+            else:
+                break
+        else:
+            print("Exceeded max retries, giving up")
+            raise RuntimeError(lockstr)
 
         if not files:
             try:


Test patch:
Repository: conda/conda

Issue:
`conda create --file deps.txt pkg1 pkg2 ... pkgn` doesn't work
```
$ echo "scipy" > deps.txt
$ conda create -n test08 --file deps.txt sympy
Fetching package metadata: ..
Solving package specifications: .
Package plan for installation in environment /home/mateusz/py/envs/test08:

The following packages will be linked:

    package                    |            build
    ---------------------------|-----------------
    numpy-1.8.1                |           py27_0   hard-link
    openssl-1.0.1h             |                0   hard-link
    python-2.7.8               |                0   hard-link
    readline-6.2               |                2   hard-link
    scipy-0.14.0               |       np18py27_0   hard-link
    sqlite-3.8.4.1             |                0   hard-link
    system-5.8                 |                1   hard-link
    tk-8.5.15                  |                0   hard-link
    zlib-1.2.7                 |                0   hard-link

Proceed ([y]/n)? n
```



Discussion:

Resolving patch:
diff --git a/conda/cli/install.py b/conda/cli/install.py
--- a/conda/cli/install.py
+++ b/conda/cli/install.py
@@ -143,10 +143,10 @@ def install(args, parser, command='install'):
     common.ensure_override_channels_requires_channel(args)
     channel_urls = args.channel or ()
 
+    specs = []
     if args.file:
-        specs = common.specs_from_url(args.file)
+        specs.extend(common.specs_from_url(args.file))
     elif getattr(args, 'all', False):
-        specs = []
         linked = ci.linked(prefix)
         for pkg in linked:
             name, ver, build = pkg.rsplit('-', 2)
@@ -155,8 +155,7 @@ def install(args, parser, command='install'):
                 specs.append('%s >=%s,<3' % (name, ver))
             else:
                 specs.append('%s >=%s' % (name, ver))
-    else:
-        specs = common.specs_from_args(args.packages)
+    specs.extend(common.specs_from_args(args.packages))
 
     if command == 'install' and args.revision:
         get_revision(args.revision)


Test patch:
Repository: conda/conda

Issue:
Use rmtree workaround for write-protected files on Windows
See https://stackoverflow.com/questions/1889597/deleting-directory-in-python/1889686#1889686. Alternately we can use rd /s. 



Discussion:

Resolving patch:
diff --git a/conda/install.py b/conda/install.py
--- a/conda/install.py
+++ b/conda/install.py
@@ -155,11 +155,20 @@ def rm_rf(path, max_retries=5):
                 shutil.rmtree(path)
                 return
             except OSError as e:
-                log.debug("Unable to delete %s (%s): retrying after %s "
-                          "seconds" % (path, e, i))
+                msg = "Unable to delete %s\n%s\n" % (path, e)
+                if on_win and e.args[0] == 5:
+                    try:
+                        subprocess.check_call(['cmd', '/c', 'rd', '/s', '/q', path])
+                        return
+                    except subprocess.CalledProcessError as e1:
+                        msg += '%s\n' % e1
+                log.debug(msg + "Retrying after %s seconds..." % i)
                 time.sleep(i)
         # Final time. pass exceptions to caller.
-        shutil.rmtree(path)
+        if on_win and e.args[0] == 5:
+            subprocess.check_call(['cmd', '/c', 'rd', '/s', '/q', path])
+        else:
+            shutil.rmtree(path)
 
 def rm_empty_dir(path):
     """


Test patch:
Repository: conda/conda

Issue:
Only try updating outdated packages with update --all
conda update --all tends to fail a lot because it requires that the whole environment become satisfiable, and without downgrading any packages. Perhaps a better solution would be to only try installing those packages that are known to be outdated. 

Another idea would be to relax the downgrade restriction, and just have it essentially "reinstall" the environment. This could lead to some surprises when it does downgrade things, but it would also reduce the number of unsatisfiable packages issues, as those seem to usually come from the version specification.



Discussion:

Resolving patch:
diff --git a/conda/cli/install.py b/conda/cli/install.py
--- a/conda/cli/install.py
+++ b/conda/cli/install.py
@@ -191,13 +191,13 @@ def install(args, parser, command='install'):
                 "prefix %s" % prefix)
         for pkg in linked:
             name, ver, build = pkg.rsplit('-', 2)
-            if name in getattr(args, '_skip', []):
+            if name in getattr(args, '_skip', ['anaconda']):
                 continue
             if name == 'python' and ver.startswith('2'):
                 # Oh Python 2...
                 specs.append('%s >=%s,<3' % (name, ver))
             else:
-                specs.append('%s >=%s' % (name, ver))
+                specs.append('%s' % name)
     specs.extend(common.specs_from_args(args.packages, json=args.json))
 
     if command == 'install' and args.revision:
@@ -345,7 +345,7 @@ def install(args, parser, command='install'):
             else:
                 # Not sure what to do here
                 pass
-            args._skip = getattr(args, '_skip', [])
+            args._skip = getattr(args, '_skip', ['anaconda'])
             args._skip.extend([i.split()[0] for i in e.pkgs])
             return install(args, parser, command=command)
         else:


Test patch:
Repository: conda/conda

Issue:
conda remove --dry-run actually removes the package
Is there anything set around here:

https://github.com/conda/conda/blob/ded940c3fa845bbb86b3492e4a7c883c1bcec10b/conda/cli/main_remove.py#L196

to actually exit before removing the package if --dry-run is set but --json is not?

I'm just running 3.11.0 and haven't grabbed and functionally tested master to see if this is still a problem.



Discussion:

Resolving patch:
diff --git a/conda/cli/main_remove.py b/conda/cli/main_remove.py
--- a/conda/cli/main_remove.py
+++ b/conda/cli/main_remove.py
@@ -190,6 +190,9 @@ def execute(args, parser):
         return
 
 
+    if not args.json:
+        common.confirm_yn(args)
+
     if args.json and not args.quiet:
         with json_progress_bars():
             plan.execute_actions(actions, index, verbose=not args.quiet)


Test patch:
Repository: conda/conda

Issue:
Set the default CondaSession.verify default from the config setting
Currently, the .condarc config setting must be explicitly used when making a request with a CondaSession object.  This means that anyone who wants to use CondaSession must check the .condarc ssl_verify value and appropriately interpret it, etc.  (For example, see https://github.com/conda/conda/blob/47e300b0e2cd5aad1dfe18d26eada5995b058004/conda/fetch.py#L101)

I think it would be much cleaner for CondaSession itself to set the default verify value in its **init**: `self.verify = <code to get the .condarc ssl_verify setting`.  See https://github.com/kennethreitz/requests/blob/8b5e457b756b2ab4c02473f7a42c2e0201ecc7e9/requests/sessions.py#L314 to see that this is correct.

This change would mean that we don't need the verify argument here: https://github.com/conda/conda/blob/47e300b0e2cd5aad1dfe18d26eada5995b058004/conda/fetch.py#L101, and would also solve this issue: https://github.com/conda/conda-build/issues/523



Discussion:
Sounds good to me. 


Resolving patch:
diff --git a/conda/connection.py b/conda/connection.py
--- a/conda/connection.py
+++ b/conda/connection.py
@@ -19,7 +19,7 @@
 
 import conda
 from conda.compat import urlparse, StringIO
-from conda.config import get_proxy_servers
+from conda.config import get_proxy_servers, ssl_verify
 
 import requests
 
@@ -82,6 +82,7 @@ def __init__(self, *args, **kwargs):
         self.headers['User-Agent'] = "conda/%s %s" % (
                           conda.__version__, self.headers['User-Agent'])
 
+        self.verify = ssl_verify
 
 class S3Adapter(requests.adapters.BaseAdapter):
 
diff --git a/conda/fetch.py b/conda/fetch.py
--- a/conda/fetch.py
+++ b/conda/fetch.py
@@ -97,8 +97,7 @@ def fetch_repodata(url, cache_dir=None, use_cache=False, session=None):
 
     try:
         resp = session.get(url + 'repodata.json.bz2',
-                           headers=headers, proxies=session.proxies,
-                           verify=config.ssl_verify)
+                           headers=headers, proxies=session.proxies)
         resp.raise_for_status()
         if resp.status_code != 304:
             cache = json.loads(bz2.decompress(resp.content).decode('utf-8'))
@@ -323,8 +322,7 @@ def download(url, dst_path, session=None, md5=None, urlstxt=False,
         retries = RETRIES
     with Locked(dst_dir):
         try:
-            resp = session.get(url, stream=True, proxies=session.proxies,
-                               verify=config.ssl_verify)
+            resp = session.get(url, stream=True, proxies=session.proxies)
             resp.raise_for_status()
         except requests.exceptions.HTTPError as e:
             if e.response.status_code == 407: # Proxy Authentication Required


Test patch:
Repository: conda/conda

Issue:
`conda.install.update_prefix` is modifying cached pkgs in Windows
Since files are hardlinks, it looks like conda's prefix replacement mechanism is breaking its own files.

File contents inside package:

``` python
x = r'/opt/anaconda1anaconda2anaconda3\Scripts',
```

File contents after installing in 'env1':

``` python
x = r'C:\Miniconda\envs\env1\Scripts',
```

File contents after installing in 'NOTENV1':

``` python
x = r'C:\Miniconda\envs\env1\Scripts',
```

Note that the second install fails, because the first one modified the cached files in `C:\Miniconda\pkgs`.

Reading @asmeurer comments in #679, I agree that the correct behavior in this case would be to delete the file being modified and re-create it to avoid this issue.



Discussion:

Resolving patch:
diff --git a/conda/install.py b/conda/install.py
--- a/conda/install.py
+++ b/conda/install.py
@@ -272,6 +272,7 @@ def update_prefix(path, new_prefix, placeholder=prefix_placeholder,
     if new_data == data:
         return
     st = os.lstat(path)
+    os.remove(path) # Remove file before rewriting to avoid destroying hard-linked cache.
     with open(path, 'wb') as fo:
         fo.write(new_data)
     os.chmod(path, stat.S_IMODE(st.st_mode))


Test patch:
Repository: conda/conda

Issue:
conda install --no-deps still installing deps when installing tarball
When running the following command:

`conda install --no-deps ./matplotlib-1.4.0-np18py27_0.tar.bz2`
You would assume that no dependencies are installed, but conda seems to install the dependencies anyway.



Discussion:
fwiw: This seemed to work with conda 3.7.0

That's because conda used to never install the dependencies of a tarball. This feature was added, but the `--no-deps` flag was neglected. 

@ilanschnell this is similar to the issue I was describing with `--offline` installations breaking because of the dependency resolution happening after tarball installs.  Didn't you say you had a fix in mind for how to deal with that?  Would that also solve this problem?

Yes, I have described the fix I had in mind here: https://github.com/conda/conda/issues/1075

Just fixing this issue should be much simpler than fixing that, though. We just need to make it respect the command line flag. 

What is the status here?


Resolving patch:
diff --git a/conda/cli/install.py b/conda/cli/install.py
--- a/conda/cli/install.py
+++ b/conda/cli/install.py
@@ -196,12 +196,14 @@ def install(args, parser, command='install'):
         common.check_specs(prefix, specs, json=args.json,
                            create=(command == 'create'))
 
-    # handle tar file containing conda packages
+
     num_cp = sum(s.endswith('.tar.bz2') for s in args.packages)
     if num_cp:
         if num_cp == len(args.packages):
             depends = misc.install_local_packages(prefix, args.packages,
                                                   verbose=not args.quiet)
+            if args.no_deps:
+                depends = []
             specs = list(set(depends))
             args.unknown = True
         else:
@@ -209,10 +211,14 @@ def install(args, parser, command='install'):
                 "cannot mix specifications with conda package filenames",
                 json=args.json,
                 error_type="ValueError")
+
+    # handle tar file containing conda packages
     if len(args.packages) == 1:
         tar_path = args.packages[0]
         if tar_path.endswith('.tar'):
             depends = install_tar(prefix, tar_path, verbose=not args.quiet)
+            if args.no_deps:
+                depends = []
             specs = list(set(depends))
             args.unknown = True
 


Test patch:
Repository: conda/conda

Issue:
conda remove shouldn't fetch the package metadata
It only needs it to print the channel location. It should either get that locally, or at least just use the index cache. 



Discussion:

Resolving patch:
diff --git a/conda/cli/common.py b/conda/cli/common.py
--- a/conda/cli/common.py
+++ b/conda/cli/common.py
@@ -180,6 +180,16 @@ def add_parser_use_index_cache(p):
         help="Use cache of channel index files.",
     )
 
+
+def add_parser_no_use_index_cache(p):
+    p.add_argument(
+        "--no-use-index-cache",
+        action="store_false",
+        default=True,
+        dest="use_index_cache",
+        help="Use cache of channel index files.",
+    )
+
 def add_parser_copy(p):
     p.add_argument(
         '--copy',
diff --git a/conda/cli/main_remove.py b/conda/cli/main_remove.py
--- a/conda/cli/main_remove.py
+++ b/conda/cli/main_remove.py
@@ -68,6 +68,8 @@ def configure_parser(sub_parsers, name='remove'):
     common.add_parser_channels(p)
     common.add_parser_prefix(p)
     common.add_parser_quiet(p)
+    # Putting this one first makes it the default
+    common.add_parser_no_use_index_cache(p)
     common.add_parser_use_index_cache(p)
     common.add_parser_use_local(p)
     common.add_parser_offline(p)


Test patch:
Repository: conda/conda

Issue:
Race condition for root environment detection
Periodically, when two conda processes are running at the same time, it is possible to see a race condition on determining whether the root environment is writable. Notice how the following produces two different configs from the same setup:

```
$ conda info & conda info 

Current conda install:

             platform : osx-64
        conda version : 3.18.3
  conda-build version : 1.18.0
       python version : 2.7.10.final.0
     requests version : 2.8.1
     root environment : /Users/pelson/miniconda  (read only)
  default environment : /Users/pelson/miniconda
     envs directories : /Users/pelson/.conda/envs
                        /Users/pelson/envs
                        /Users/pelson/miniconda/envs
        package cache : /Users/pelson/.conda/envs/.pkgs
                        /Users/pelson/envs/.pkgs
                        /Users/pelson/miniconda/pkgs
...

Current conda install:

             platform : osx-64
        conda version : 3.18.3
  conda-build version : 1.18.0
       python version : 2.7.10.final.0
     requests version : 2.8.1
     root environment : /Users/pelson/miniconda  (writable)
  default environment : /Users/pelson/miniconda
     envs directories : /Users/pelson/miniconda/envs
        package cache : /Users/pelson/miniconda/pkgs
...
```

The offending line is in https://github.com/conda/conda/blob/master/conda/config.py#L135-L143 and https://github.com/conda/conda/blob/master/conda/utils.py#L43-L54. My assumption is that the `.conda-try-write` is being removed by the other process, and the exception is being raised in the `finally` block.



Discussion:

Resolving patch:
diff --git a/conda/utils.py b/conda/utils.py
--- a/conda/utils.py
+++ b/conda/utils.py
@@ -5,8 +5,10 @@
 import hashlib
 import collections
 from functools import partial
-from os.path import abspath, isdir, join
+from os.path import abspath, isdir
 import os
+import tempfile
+
 
 log = logging.getLogger(__name__)
 stderrlog = logging.getLogger('stderrlog')
@@ -43,13 +45,10 @@ def can_open_all_files_in_prefix(prefix, files):
 def try_write(dir_path):
     assert isdir(dir_path)
     try:
-        try:
-            with open(join(dir_path, '.conda-try-write'), mode='wb') as fo:
-                fo.write(b'This is a test file.\n')
-            return True
-        finally:
-            # XXX: If this raises an exception it will also return False
-            os.unlink(join(dir_path, '.conda-try-write'))
+        with tempfile.TemporaryFile(prefix='.conda-try-write',
+                                    dir=dir_path) as fo:
+            fo.write(b'This is a test file.\n')
+        return True
     except (IOError, OSError):
         return False
 


Test patch:
Repository: conda/conda

Issue:
confusing error message when boto is missing
If one tries to install from an s3 channel (e.g., `conda install foo -c s3://bar/baz/conda`) while in an environment, this message shows up:  `Error: boto is required for S3 channels. Please install it with: conda install boto`.  Installing `boto` in the environment doesn't actually solve the problem, however, because `boto` has to be installed into the main set of packages (e.g., `source deactivate; conda install boto`).

Perhaps a simple edit to the error message would address this.  (e.g., `Error: boto is required for S3 channels. Please install it with: conda install boto.  Make sure to run "source deactivate" if you are in an environment.`)



Discussion:

Resolving patch:
diff --git a/conda/connection.py b/conda/connection.py
--- a/conda/connection.py
+++ b/conda/connection.py
@@ -101,7 +101,9 @@ def send(self, request, stream=None, timeout=None, verify=None, cert=None,
             import boto
         except ImportError:
             stderrlog.info('\nError: boto is required for S3 channels. '
-                           'Please install it with: conda install boto\n')
+                           'Please install it with `conda install boto`\n'
+                           'Make sure to run `source deactivate` if you '
+                           'are in a conda environment.\n')
             resp.status_code = 404
             return resp
 


Test patch:
Repository: conda/conda

Issue:
BeeGFS hard-links
[BeeGFS](http://www.beegfs.com), a parallel cluster file system, [does not support](https://groups.google.com/forum/#!topic/fhgfs-user/cTJcqGZceVA) `hard-links` between files in differents directories.

Depending on the [configuration](https://groups.google.com/forum/#!topic/fhgfs-user/pvQSo0QWicw), either an error is issued, or a `symbolic-link` is created.

If a `symbolic-link` is created instead of a `hard-link`, it can cause problem, for example:

```
pkgs/bin/mpicc
pkgs/lib/libopen-pal.so
envs/bin/mpicc
envs/lib/libopen-pal.so
```

Here, when `envs/bin/mpicc` is executed, it is actually `pkgs/bin/mpicc` that is executed, and the library `$PREFIX/../lib/libopen-pal.so` actually loaded is `pkgs/lib/libopen-pal.so,` which is different from `envs/lib/libopen-pal.so` for which conda has fixed hard-coded prefix path, and as a final consequence `mpicc` fails to find its configuration file.
#805 is another (closed) related to `BeeGFS`.

Would we need a new conda options to turn hard-link into copy?



Discussion:

Resolving patch:
diff --git a/conda/install.py b/conda/install.py
--- a/conda/install.py
+++ b/conda/install.py
@@ -515,7 +515,12 @@ def try_hard_link(pkgs_dir, prefix, dist):
         if not isdir(prefix):
             os.makedirs(prefix)
         _link(src, dst, LINK_HARD)
-        return True
+        # Some file systems (at least BeeGFS) do not support hard-links
+        # between files in different directories. Depending on the
+        # file system configuration, a symbolic link may be created
+        # instead. If a symbolic link is created instead of a hard link,
+        # return False.
+        return not os.path.islink(dst)
     except OSError:
         return False
     finally:


Test patch:
Repository: conda/conda

Issue:
When no condarc is found "no path!" is printed
Why was https://github.com/conda/conda/blob/master/conda/config.py#L115 added?
Is this a debug statement which never got removed?



Discussion:
Yes, sorry. I'll fix.

I just ran into this. Aside: is there good guidance for users looking to use conda outside of Anaconda (e.g. with some custom repo of packages but not really using anything in defaults)? 


Resolving patch:
diff --git a/conda/config.py b/conda/config.py
--- a/conda/config.py
+++ b/conda/config.py
@@ -113,7 +113,6 @@ def get_rc_path():
 
 def load_condarc(path):
     if not path or not isfile(path):
-        print("no path!")
         return {}
     with open(path) as f:
         return yaml_load(f) or {}


Test patch:
Repository: conda/conda

Issue:
Disable .netrc authentication
Anaconda-Server/support#23

When a user has a `~/.netrc` file present, `requests` will use that file to populate the `Authorization` header (using HTTP Basic auth). When authorization fails, conda falls into an infinite loop retrying.

To fix this problem in `anaconda-client`, I disabled `.netrc` authorization by adding a `NullAuth` to the `requests.Session`.

https://github.com/Anaconda-Server/anaconda-client/pull/298



Discussion:

Resolving patch:
diff --git a/conda/connection.py b/conda/connection.py
--- a/conda/connection.py
+++ b/conda/connection.py
@@ -91,6 +91,8 @@ def __init__(self, *args, **kwargs):
         proxies = get_proxy_servers()
         if proxies:
             self.proxies = proxies
+        self.trust_env = False  # disable .netrc file
+                                # also disables REQUESTS_CA_BUNDLE, CURL_CA_BUNDLE env variables
 
         # Configure retries
         if retries:


Test patch: