Repository: conda/conda-build

Issue:
Conda-build and conda-versions should be included in package meta-data
I'm trying to update and build an older package for a client and I can not because of errors. I need to figure out the context in which this package was originally built.

cc @csoja  re Anaconda-Platform/anaconda-server#2949



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
@@ -12,6 +12,7 @@
 import mmap
 import os
 from os.path import isdir, isfile, islink, join
+import re
 import shutil
 import stat
 import subprocess
@@ -26,6 +27,8 @@
 
 import filelock
 
+# used to get version
+import conda
 from .conda_interface import cc
 from .conda_interface import envs_dirs, root_dir
 from .conda_interface import plan
@@ -279,6 +282,10 @@ def detect_and_record_prefix_files(m, files, prefix, config):
         raise RuntimeError(errstr)
 
 
+def sanitize_channel(channel):
+    return re.sub('\/t\/[a-zA-Z0-9\-]*\/', '/t/<TOKEN>/', channel)
+
+
 def write_about_json(m, config):
     with open(join(config.info_dir, 'about.json'), 'w') as fo:
         d = {}
@@ -287,6 +294,30 @@ def write_about_json(m, config):
             value = m.get_value('about/%s' % key)
             if value:
                 d[key] = value
+        # for sake of reproducibility, record some conda info
+        conda_info = subprocess.check_output(['conda', 'info', '--json', '-s'])
+        if hasattr(conda_info, 'decode'):
+            conda_info = conda_info.decode(codec)
+        conda_info = json.loads(conda_info)
+        d['conda_version'] = conda_info['conda_version']
+        d['conda_build_version'] = conda_info['conda_build_version']
+        d['conda_env_version'] = conda_info['conda_env_version']
+        d['offline'] = conda_info['offline']
+        channels = conda_info['channels']
+        stripped_channels = []
+        for channel in channels:
+            stripped_channels.append(sanitize_channel(channel))
+        d['channels'] = stripped_channels
+        # this information will only be present in conda 4.2.10+
+        try:
+            d['conda_private'] = conda_info['conda_private']
+            d['env_vars'] = conda_info['env_vars']
+        except KeyError:
+            pass
+        pkgs = subprocess.check_output(['conda', 'list', '-n', 'root', '--json'])
+        if hasattr(pkgs, 'decode'):
+            pkgs = pkgs.decode(codec)
+        d['root_pkgs'] = json.loads(pkgs)
         json.dump(d, fo, indent=2, sort_keys=True)
 
 
diff --git a/conda_build/utils.py b/conda_build/utils.py
--- a/conda_build/utils.py
+++ b/conda_build/utils.py
@@ -346,7 +346,7 @@ def path2url(path):
 
 def get_stdlib_dir(prefix):
     if sys.platform == 'win32':
-        stdlib_dir = os.path.join(prefix, 'Lib', 'site-packages')
+        stdlib_dir = os.path.join(prefix, 'Lib')
     else:
         lib_dir = os.path.join(prefix, 'lib')
         stdlib_dir = glob(os.path.join(lib_dir, 'python[0-9\.]*'))


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
@@ -10,6 +10,8 @@
 import json
 import uuid
 
+# for version
+import conda
 from conda_build.conda_interface import PY3, url_path
 
 from binstar_client.commands import remove, show
@@ -18,7 +20,8 @@
 import yaml
 import tarfile
 
-from conda_build import api, exceptions
+from conda_build import api, exceptions, __version__
+from conda_build.build import VersionOrder
 from conda_build.utils import (copy_into, on_win, check_call_env, convert_path_for_cygwin_or_msys2,
                                package_has_file)
 from conda_build.os_utils.external import find_executable
@@ -616,10 +619,28 @@ def test_noarch_foo_value():
     assert metadata['noarch'] == "foo"
 
 
+def test_about_json_content(test_metadata):
+    api.build(test_metadata)
+    fn = api.get_output_file_path(test_metadata)
+    about = json.loads(package_has_file(fn, 'info/about.json').decode())
+    assert 'conda_version' in about and about['conda_version'] == conda.__version__
+    assert 'conda_build_version' in about and about['conda_build_version'] == __version__
+    assert 'channels' in about and about['channels']
+    try:
+        assert 'env_vars' in about and about['env_vars']
+    except AssertionError:
+        # new versions of conda support this, so we should raise errors.
+        if VersionOrder(conda.__version__) >= VersionOrder('4.2.10'):
+            raise
+        else:
+            pass
+
+    assert 'root_pkgs' in about and about['root_pkgs']
+
+
 @pytest.mark.xfail(reason="Conda can not yet install `noarch: python` packages")
 def test_noarch_python_with_tests():
     recipe = os.path.join(metadata_dir, "_noarch_python_with_tests")
-    fn = api.get_output_file_path(recipe)
     api.build(recipe)
 
 
@@ -642,12 +663,12 @@ def test_skip_compile_pyc():
     for f in tf.getmembers():
         filename = os.path.basename(f.name)
         _, ext = os.path.splitext(filename)
-        basename = filename.split('.',1)[0]
+        basename = filename.split('.', 1)[0]
         if basename == 'skip_compile_pyc':
             assert not ext == '.pyc', "a skip_compile_pyc .pyc was compiled: {}".format(filename)
         if ext == '.pyc':
             assert basename == 'compile_pyc', "an unexpected .pyc was compiled: {}".format(filename)
-            pyc_count = pyc_count+1
+            pyc_count = pyc_count + 1
     assert pyc_count == 2, "there should be 2 .pyc files, instead there were {}".format(pyc_count)
 
 
diff --git a/tests/test_build.py b/tests/test_build.py
--- a/tests/test_build.py
+++ b/tests/test_build.py
@@ -137,3 +137,8 @@ def test_warn_on_old_conda_build(test_config, capfd):
                                   available_packages=['1.0.0beta'])
     output, error = capfd.readouterr()
     assert "conda-build appears to be out of date. You have version " not in error
+
+
+def test_sanitize_channel():
+    test_url = 'https://conda.anaconda.org/t/ms-534991f2-4123-473a-b512-42025291b927/somechannel'
+    assert build.sanitize_channel(test_url) == 'https://conda.anaconda.org/t/<TOKEN>/somechannel'