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

Issue:
Lock files are written in the root environment
My users do not have write permissions in the root environment and they still need to use conda build. What are my options beyond --no-locking?


Discussion:
Use an older version of conda build.  Sorry.  Multi-user support is on the near-term road map, but not here yet.
@msarahan Is there a document detailing the design of the multi-user work? Might be useful to field some use cases.
Not currently, but feel free to add on to the issue at #1601 
Is there a way to turn on `--no-locking` by default?
No.  Not much of conda-build is available in .condarc.  You can hack around it with an alias:

    alias conda-build="conda-build --no-locking"

I also don't think ``--no-locking`` will totally solve your problems.  There are some places where the configuration may not be passed through, and those may still try to use locks when copying files.

PRs welcome.  My timeline for doing this myself is 1-2 weeks out.

Resolving patch:
diff --git a/conda_build/utils.py b/conda_build/utils.py
--- a/conda_build/utils.py
+++ b/conda_build/utils.py
@@ -249,6 +249,8 @@ def merge_tree(src, dst, symlinks=False, timeout=90, lock=None, locking=True):
 #    at any time, but the lock within this process should all be tied to the same tracking
 #    mechanism.
 _locations = {}
+_lock_folders = (os.path.join(root_dir, 'locks'),
+                 os.path.expanduser(os.path.join('~', '.conda_build_locks')))
 
 
 def get_lock(folder, timeout=90, filename=".conda_lock"):
@@ -263,15 +265,22 @@ def get_lock(folder, timeout=90, filename=".conda_lock"):
     lock_filename = base64.urlsafe_b64encode(b_location)[:20]
     if hasattr(lock_filename, 'decode'):
         lock_filename = lock_filename.decode()
-    locks_dir = os.path.join(root_dir, 'locks')
-    if not os.path.isdir(locks_dir):
-        os.makedirs(locks_dir)
-    lock_file = os.path.join(locks_dir, lock_filename)
-    if not os.path.isfile(lock_file):
-        with open(lock_file, 'a') as f:
-            f.write(location)
-    if location not in _locations:
-        _locations[location] = filelock.FileLock(lock_file, timeout)
+    for locks_dir in _lock_folders:
+        try:
+            if not os.path.isdir(locks_dir):
+                os.makedirs(locks_dir)
+            lock_file = os.path.join(locks_dir, lock_filename)
+            if not os.path.isfile(lock_file):
+                with open(lock_file, 'a') as f:
+                    f.write(location)
+            if location not in _locations:
+                _locations[location] = filelock.FileLock(lock_file, timeout)
+            break
+        except (OSError, IOError):
+            continue
+    else:
+        raise RuntimeError("Could not write locks folder to either system location ({0})"
+                           "or user location ({1}).  Aborting.".format(*_lock_folders))
     return _locations[location]
 
 


Test patch:
Repository: conda/conda-build

Issue:
skeleton cpan regression: not outputting recursive skeletons
See #1675 for more info


Discussion:
sorry, need to punt on this one.

Resolving patch:
diff --git a/conda_build/skeletons/cpan.py b/conda_build/skeletons/cpan.py
--- a/conda_build/skeletons/cpan.py
+++ b/conda_build/skeletons/cpan.py
@@ -634,7 +634,7 @@ def get_release_info(cpan_url, package, version, perl_version, config,
         try:
             new_rel_dict = get_cpan_api_url('{0}/release/{1}/{2}-{3}'.format(cpan_url,
                                                 author, package, version_str), colons=False)
-            new_rel_dict['version'] = new_rel_dict['version'].lstrip()
+            new_rel_dict['version'] = str(new_rel_dict['version']).lstrip()
         # Check if this is a core module, and don't die if it is
         except CondaHTTPError:
             core_version = core_module_version(orig_package, perl_version, config=config)
diff --git a/conda_build/skeletons/pypi.py b/conda_build/skeletons/pypi.py
--- a/conda_build/skeletons/pypi.py
+++ b/conda_build/skeletons/pypi.py
@@ -970,7 +970,11 @@ def run_setuppy(src_dir, temp_dir, python_version, extra_specs, config, setup_op
     :param temp_dir: Temporary directory for doing for storing pkginfo.yaml
     :type temp_dir: str
     '''
-    specs = ['python %s*' % python_version, 'pyyaml', 'setuptools']
+    # TODO: we could make everyone's lives easier if we include packaging here, because setuptools
+    #    needs it in recent versions.  At time of writing, it is not a package in defaults, so this
+    #    actually breaks conda-build right now.  Omit it until packaging is on defaults.
+    # specs = ['python %s*' % python_version, 'pyyaml', 'setuptools', 'six', 'packaging', 'appdirs']
+    specs = ['python %s*' % python_version, 'pyyaml']
     with open(os.path.join(src_dir, "setup.py")) as setup:
         text = setup.read()
         if 'import numpy' in text or 'from numpy' in text:
@@ -983,9 +987,10 @@ def run_setuppy(src_dir, temp_dir, python_version, extra_specs, config, setup_op
     # TODO: Try with another version of Python if this one fails. Some
     # packages are Python 2 or Python 3 only.
 
-    create_env(config.build_prefix, specs=specs,
-               clear_cache=False,
-               config=config)
+    if not os.path.isdir(config.build_prefix) or not os.listdir(config.build_prefix):
+        create_env(config.build_prefix, specs=specs,
+                clear_cache=False,
+                config=config)
     stdlib_dir = join(config.build_prefix,
                       'Lib' if sys.platform == 'win32'
                       else 'lib/python%s' % python_version)


Test patch:
Repository: conda/conda-build

Issue:
New error when dependencies are unsatifiable
```
File ".../lib/python3.5/site-packages/conda_build/build.py", line 1536, in build_tree
  .format(recipe, e.pkgs) + "\n\n" + extra_help)
AttributeError: 'UnsatisfiableError' object has no attribute 'pkgs'
```


Discussion:
Fixed in #1585 

Resolving patch:
diff --git a/conda_build/build.py b/conda_build/build.py
--- a/conda_build/build.py
+++ b/conda_build/build.py
@@ -1530,7 +1530,7 @@ def build_tree(recipe_list, config, build_only=False, post=False, notest=False,
                         add_recipes.append(recipe_dir)
                 else:
                     raise RuntimeError("Can't build {0} due to unsatisfiable dependencies:\n{1}"
-                                       .format(recipe, e.pkgs) + "\n\n" + extra_help)
+                                       .format(recipe, error_str) + "\n\n" + extra_help)
             if retried_recipes.count(recipe) >= len(metadata.ms_depends('build')):
                 raise RuntimeError("Can't build {0} due to environment creation error:\n"
                                     .format(recipe) + error_str + "\n" + extra_help)


Test patch:
Repository: conda/conda-build

Issue:
non-ASCII characters in patches not allowed.
I get an error when there are non-ASCII characters in a patch.
```
  File "/home/isuru/miniconda3_2/bin/conda-build", line 6, in <module>
    sys.exit(conda_build.cli.main_build.main())
  File "/home/isuru/miniconda3_2/lib/python3.5/site-packages/conda_build/cli/main_build.py", line 322, in main
    execute(sys.argv[1:])
  File "/home/isuru/miniconda3_2/lib/python3.5/site-packages/conda_build/cli/main_build.py", line 313, in execute
    noverify=args.no_verify)
  File "/home/isuru/miniconda3_2/lib/python3.5/site-packages/conda_build/api.py", line 97, in build
    need_source_download=need_source_download, config=config)
  File "/home/isuru/miniconda3_2/lib/python3.5/site-packages/conda_build/build.py", line 1484, in build_tree
    config=config)
  File "/home/isuru/miniconda3_2/lib/python3.5/site-packages/conda_build/build.py", line 983, in build
    config=config)
  File "/home/isuru/miniconda3_2/lib/python3.5/site-packages/conda_build/render.py", line 86, in parse_or_try_download
    source.provide(metadata, config=config)
  File "/home/isuru/miniconda3_2/lib/python3.5/site-packages/conda_build/source.py", line 529, in provide
    apply_patch(src_dir, join(metadata.path, patch), config, git)
  File "/home/isuru/miniconda3_2/lib/python3.5/site-packages/conda_build/source.py", line 460, in apply_patch
    files, is_git_format = _get_patch_file_details(path)
  File "/home/isuru/miniconda3_2/lib/python3.5/site-packages/conda_build/source.py", line 444, in _get_patch_file_details
    for l in f.readlines():
  File "/home/isuru/miniconda3_2/lib/python3.5/codecs.py", line 321, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa3 in position 8127: invalid start byte
```


Discussion:
Changing https://github.com/conda/conda-build/blob/dcc74eb815209cdcf98e0b9681f3b1456983ed93/conda_build/source.py#L444
to `with io.open(path, errors="ignore") as f:` works

Resolving patch:
diff --git a/conda_build/source.py b/conda_build/source.py
--- a/conda_build/source.py
+++ b/conda_build/source.py
@@ -1,5 +1,6 @@
 from __future__ import absolute_import, division, print_function
 
+import io
 import locale
 import logging
 import os
@@ -437,7 +438,7 @@ def _guess_patch_strip_level(filesstr, src_dir):
 def _get_patch_file_details(path):
     re_files = re.compile('^(?:---|\+\+\+) ([^\n\t]+)')
     files = set()
-    with open(path) as f:
+    with io.open(path, errors='ignore') as f:
         files = []
         first_line = True
         is_git_format = True


Test patch:
Repository: conda/conda-build

Issue:
AssertionError from conda inspect linkages
```
$conda inspect linkages scikit-umfpack
Traceback (most recent call last):
  File "/Users/aaronmeurer/anaconda/bin/conda-inspect", line 6, in <module>
    sys.exit(conda_build.cli.main_inspect.main())
  File "/Users/aaronmeurer/anaconda/lib/python3.5/site-packages/conda_build/cli/main_inspect.py", line 190, in main
    return execute(sys.argv[1:])
  File "/Users/aaronmeurer/anaconda/lib/python3.5/site-packages/conda_build/cli/main_inspect.py", line 179, in execute
    show_files=args.show_files, groupby=args.groupby))
  File "/Users/aaronmeurer/anaconda/lib/python3.5/site-packages/conda_build/api.py", line 251, in inspect_linkages
    show_files=show_files, groupby=groupby)
  File "/Users/aaronmeurer/anaconda/lib/python3.5/site-packages/conda_build/inspect.py", line 260, in inspect_linkages
    output_string += print_linkages(pkgmap[pkg], show_files=show_files)
  File "/Users/aaronmeurer/anaconda/lib/python3.5/site-packages/conda_build/inspect.py", line 102, in print_linkages
    k = sorted(set(depmap.keys()) - {'system', 'not found'})
  File "/Users/aaronmeurer/anaconda/lib/python3.5/site-packages/conda/models/dist.py", line 226, in __lt__
    assert isinstance(other, self.__class__)
AssertionError
```


Discussion:
Looks like a conda 4.3 compatibility.  Thanks for raising it.
What package did you trigger this with?  ```conda inspect linkages``` works fine for the python package on osx - that's part of our tests.  I want to make sure our tests catch this.

Resolving patch:
diff --git a/conda_build/inspect.py b/conda_build/inspect.py
--- a/conda_build/inspect.py
+++ b/conda_build/inspect.py
@@ -100,6 +100,13 @@ def check_install(packages, platform=None, channel_urls=(), prepend=True,
 
 def print_linkages(depmap, show_files=False):
     # Print system and not found last
+    dist_depmap = {}
+    for k, v in depmap.items():
+        if hasattr(k, 'dist_name'):
+            k = k.dist_name
+        dist_depmap[k] = v
+
+    depmap = dist_depmap
     k = sorted(set(depmap.keys()) - {'system', 'not found'})
     all_deps = k if 'not found' not in depmap.keys() else k + ['system', 'not found']
     output_string = ""


Test patch:
Repository: conda/conda-build

Issue:
Incomplete list of essential Windows environment variables
Hi, after one of my packages failed to build with conda-build 2.1.7 due to a missing environment variable (`USERNAME`, used by [`getpass.getuser`](https://github.com/python/cpython/blob/master/Lib/getpass.py#L162)), I had a look into `conda_build/environ.py` and noticed that `windows_vars(prefix)` is missing some important environment variables.

I will prepare a pull request which adds the [default Windows environment variables](https://en.wikipedia.org/wiki/Environment_variable#Default_values).


Discussion:

Resolving patch:
diff --git a/conda_build/environ.py b/conda_build/environ.py
--- a/conda_build/environ.py
+++ b/conda_build/environ.py
@@ -391,8 +391,34 @@ def windows_vars(prefix):
         'LIBRARY_LIB': join(library_prefix, 'lib'),
         'R': join(prefix, 'Scripts', 'R.exe'),
         'CYGWIN_PREFIX': ''.join(('/cygdrive/', drive.lower(), tail.replace('\\', '/'))),
-        'SYSTEMROOT': os.getenv('SYSTEMROOT'),
-        'WINDIR': os.getenv('WINDIR'),
+        # see https://en.wikipedia.org/wiki/Environment_variable#Default_values
+        'ALLUSERSPROFILE': os.getenv('ALLUSERSPROFILE'),
+        'APPDATA': os.getenv('APPDATA'),
+        'CommonProgramFiles': os.getenv('CommonProgramFiles'),
+        'CommonProgramFiles(x86)': os.getenv('CommonProgramFiles(x86)'),
+        'CommonProgramW6432': os.getenv('CommonProgramW6432'),
+        'COMPUTERNAME': os.getenv('COMPUTERNAME'),
+        'ComSpec': os.getenv('ComSpec'),
+        'HOMEDRIVE': os.getenv('HOMEDRIVE'),
+        'HOMEPATH': os.getenv('HOMEPATH'),
+        'LOCALAPPDATA': os.getenv('LOCALAPPDATA'),
+        'LOGONSERVER': os.getenv('LOGONSERVER'),
+        'PATHEXT': os.getenv('PATHEXT'),
+        'ProgramData': os.getenv('ProgramData'),
+        'ProgramFiles': os.getenv('ProgramFiles'),
+        'ProgramFiles(x86)': os.getenv('ProgramFiles(x86)'),
+        'ProgramW6432': os.getenv('ProgramW6432'),
+        'PROMPT': os.getenv('PROMPT'),
+        'PSModulePath': os.getenv('PSModulePath'),
+        'PUBLIC': os.getenv('PUBLIC'),
+        'SystemDrive': os.getenv('SystemDrive'),
+        'SystemRoot': os.getenv('SystemRoot'),
+        'TEMP': os.getenv('TEMP'),
+        'TMP': os.getenv('TMP'),
+        'USERDOMAIN': os.getenv('USERDOMAIN'),
+        'USERNAME': os.getenv('USERNAME'),
+        'USERPROFILE': os.getenv('USERPROFILE'),
+        'windir': os.getenv('windir'),
     }
 
 


Test patch:
Repository: conda/conda-build

Issue:
cleanup after failed build should not occur, but does
things should be left for debugging purposes, but are currently being cleaned up.


Discussion:

Resolving patch:
diff --git a/conda_build/build.py b/conda_build/build.py
--- a/conda_build/build.py
+++ b/conda_build/build.py
@@ -1309,7 +1309,8 @@ def build_tree(recipe_list, config, build_only=False, post=False, notest=False,
     metadata = None
     metadata_tuples = []
 
-    has_exception = set()
+    # set this to false whenever everything has succeeded.
+    has_exception = True
 
     while recipe_list:
         # This loop recursively builds dependencies if recipes exist
@@ -1391,11 +1392,10 @@ def build_tree(recipe_list, config, build_only=False, post=False, notest=False,
                         built_packages.update({pkg: dict_and_meta})
                 else:
                     built_packages.update(packages_from_this)
+            has_exception = False
         except DependencyNeedsBuildingError as e:
             skip_names = ['python', 'r', 'r-base', 'perl', 'lua']
             add_recipes = []
-            if metadata:
-                has_exception.add(metadata.dist())
             # add the failed one back in at the beginning - but its deps may come before it
             recipe_list.extendleft([metadata if metadata else recipe])
             for pkg in e.packages:
@@ -1430,7 +1430,7 @@ def build_tree(recipe_list, config, build_only=False, post=False, notest=False,
             recipe_list.extendleft(add_recipes)
         finally:
             for (m, _, _) in metadata_tuples:
-                if not getattr(m.config, 'dirty') and not m.dist() in has_exception:
+                if not getattr(m.config, 'dirty') and not has_exception:
                     m.config.clean()
 
     if post in [True, None]:


Test patch:
diff --git a/tests/test_api_build.py b/tests/test_api_build.py
--- a/tests/test_api_build.py
+++ b/tests/test_api_build.py
@@ -969,3 +969,11 @@ def test_extract_tarball_with_unicode_filename(testing_config):
     """See https://github.com/conda/conda-build/pull/1779"""
     recipe = os.path.join(metadata_dir, '_unicode_in_tarball')
     api.build(recipe, config=testing_config)
+
+
+def test_failed_recipe_leaves_folders(testing_config, testing_workdir):
+    recipe = os.path.join(fail_dir, 'recursive-build')
+    m = api.render(recipe, config=testing_config)[0][0]
+    with pytest.raises(RuntimeError):
+        api.build(m)
+    assert os.listdir(m.config.build_folder)
Repository: conda/conda-build

Issue:
'conda' script showing up in bin (Scripts) folder when building conda-devenv package
Hi,

Yesterday I build packages for version `0.9.3` of [conda-devenv](https://github.com/conda-forge/conda-devenv-feedstock) and noticed that the packages for all platforms contain a `conda` script in the `bin` directory: 

```
λ ls conda-devenv-0.9.3-py27_0\bin\
conda  conda-devenv
```

Or `Scripts` on Windows:

```
λ dir /b conda-devenv-0.9.3-py35_0\Scripts\ 
conda
conda-devenv-script.py
conda-devenv.exe
```

I did some local testing and noticed that this problem seems to have been introduced in **2.1.9**, because the exact same recipe when built with **2.1.5**, **.2.1.7** and **2.1.8** do not include the `conda` script above.

I did the same test in **2.1.9** with the `pytest` package it **does not** include the `conda` script, so I think the problem might have to do with the fact that `"conda-devenv"` starts with `"conda"`.

@gqmelo and I suspect this was introduced in #1881, but did not really verify this theory.


Discussion:

Resolving patch:
diff --git a/conda_build/build.py b/conda_build/build.py
--- a/conda_build/build.py
+++ b/conda_build/build.py
@@ -876,10 +876,15 @@ def bundle_conda(output, metadata, config, env, **kw):
         keep_files = set(utils.expand_globs(files, config.build_prefix))
         pfx_files = set(prefix_files(config.build_prefix))
         initial_files = set(item for item in (pfx_files - keep_files)
-                            if not any(keep_file.startswith(item) for keep_file in keep_files))
+                            if not any(keep_file == item for keep_file in keep_files))
 
     files = post_process_files(metadata, initial_files)
 
+    if output.get('name') and output.get('name') != 'conda':
+        assert 'bin/conda' not in files and 'Scripts/conda.exe' not in files, ("Bug in conda-build "
+            "has included conda binary in package. Please report this on the conda-build issue "
+            "tracker.")
+
     output_filename = ('-'.join([output['name'], metadata.version(),
                                  metadata.build_id()]) + '.tar.bz2')
     # first filter is so that info_files does not pick up ignored files


Test patch:
Repository: conda/conda-build

Issue:
Error when passing --skip-existing
Traceback (most recent call last):
  File "C:\Users\repair1\Miniconda3\Scripts\conda-build-script.py", line 11, in <module>
    load_entry_point('conda-build', 'console_scripts', 'conda-build')()
  File "z:\msarahan\code\conda-build\conda_build\cli\main_build.py", line 322, in main
    execute(sys.argv[1:])
  File "z:\msarahan\code\conda-build\conda_build\cli\main_build.py", line 313, in execute
    noverify=args.no_verify)
  File "z:\msarahan\code\conda-build\conda_build\api.py", line 170, in build
    need_source_download=need_source_download, config=config, variants=variants)
  File "z:\msarahan\code\conda-build\conda_build\build.py", line 1431, in build_tree
    built_packages=built_packages)
  File "z:\msarahan\code\conda-build\conda_build\build.py", line 944, in build
    print("BUILD START:", [os.path.basename(pkg) for pkg in package_locations])
  File "z:\msarahan\code\conda-build\conda_build\build.py", line 944, in <listcomp>
    print("BUILD START:", [os.path.basename(pkg) for pkg in package_locations])
  File "C:\Users\repair1\Miniconda3\lib\ntpath.py", line 235, in basename
    return split(p)[1]
  File "C:\Users\repair1\Miniconda3\lib\ntpath.py", line 204, in split
    p = os.fspath(p)
TypeError: expected str, bytes or os.PathLike object, not list


Discussion:

Resolving patch:
diff --git a/conda_build/build.py b/conda_build/build.py
--- a/conda_build/build.py
+++ b/conda_build/build.py
@@ -938,6 +938,8 @@ def build(m, index, post=None, need_source_download=True, need_reparse_in_env=Fa
                 print("Packages for ", m.path or m.name(),
                         "are already built in {0}, skipping.".format(package_locations))
                 return default_return
+            else:
+                package_locations = [bldpkg_path(om) for om, _, _ in output_metas]
         else:
             package_locations = [bldpkg_path(om) for om, _, _ in output_metas]
 
@@ -1620,5 +1622,6 @@ def is_package_built(metadata):
         urls.extend(metadata.config.channel_urls)
 
     # will be empty if none found, and evalute to False
-    return [url for url in urls
+    found_urls = [url for url in urls
             if dist_str_in_index(index, url + '::' + metadata.pkg_fn())]
+    return found_urls[0] if found_urls else None


Test patch:
Repository: conda/conda-build

Issue:
Error when try to run `conda build`
``` 
>  conda build .                                                                                                                                                                                                                                                  
Traceback (most recent call last):
  File "/data2/user/shared/tools/miniconda2/bin/conda-build", line 4, in <module>
    import conda_build.cli.main_build
  File "/data2/user/shared/tools/miniconda2/lib/python2.7/site-packages/conda_build/cli/main_build.py", line 16, in <module>
    import conda_build.api as api
  File "/data2/user/shared/tools/miniconda2/lib/python2.7/site-packages/conda_build/api.py", line 22, in <module>
    from conda_build.config import Config, get_or_merge_config, DEFAULT_PREFIX_LENGTH as _prefix_length
  File "/data2/user/shared/tools/miniconda2/lib/python2.7/site-packages/conda_build/config.py", line 15, in <module>
    from .conda_interface import root_dir, root_writable, subdir, cc_platform, cc_conda_build
  File "/data2/user/shared/tools/miniconda2/lib/python2.7/site-packages/conda_build/conda_interface.py", line 216, in <module>
    get_local_urls = cc.get_local_urls
NameError: name 'cc' is not defined
```
Look at the source code: https://github.com/conda/conda-build/blob/master/conda_build/conda_interface.py#L200-224

That's definitely a problem to delete `cc` (L200) when you still need to use it (L223,224)
Will create a PR for this.


Discussion:

Resolving patch:
diff --git a/conda_build/conda_interface.py b/conda_build/conda_interface.py
--- a/conda_build/conda_interface.py
+++ b/conda_build/conda_interface.py
@@ -197,8 +197,6 @@ def default(self, obj):
 
     cc_conda_build = cc.rc.get('conda-build', {})
 
-    del locals()['cc']
-
     class CondaHTTPError(Exception):
         pass
 
@@ -222,6 +220,8 @@ class CondaError(Exception):
 
     get_local_urls = cc.get_local_urls
     arch_name = cc.arch_name
+    
+    del locals()['cc']
 
 CondaError, CondaHTTPError, get_prefix, LinkError = CondaError, CondaHTTPError, get_prefix, LinkError  # NOQA
 LockError, non_x86_linux_machines, NoPackagesFoundError = LockError, non_x86_linux_machines, NoPackagesFoundError  # NOQA


Test patch: