diff --git a/conda_build/main_inspect.py b/conda_build/main_inspect.py index 651408ba94..cfdd31bdb4 100644 --- a/conda_build/main_inspect.py +++ b/conda_build/main_inspect.py @@ -12,15 +12,16 @@ from os.path import abspath, join, dirname, exists, basename from collections import defaultdict from operator import itemgetter +import tempfile from conda.misc import which_package from conda.compat import iteritems -from conda.cli.common import add_parser_prefix, get_prefix, InstalledPackages +from conda.cli.common import add_parser_prefix, get_prefix, InstalledPackages, specs_from_args from conda.cli.conda_argparse import ArgumentParser -import conda.install as ci +import conda.install +from conda import plan from conda.api import get_index -from conda.cli.install import check_install from conda.config import get_default_urls from conda_build.main_build import args_func @@ -157,6 +158,21 @@ def main(): args_func(args, p) +def check_install(packages, platform=None, channel_urls=(), prepend=True, + minimal_hint=False): + prefix = tempfile.mkdtemp('conda') + try: + specs = specs_from_args(packages) + index = get_index(channel_urls=channel_urls, prepend=prepend, + platform=platform, prefix=prefix) + actions = plan.install_actions(prefix, index, specs, pinned=False, + minimal_hint=minimal_hint) + plan.display_actions(actions, index) + return actions + finally: + conda.install.rm_rf(prefix) + + def print_linkages(depmap, show_files=False): # Print system and not found last k = sorted(set(depmap.keys()) - {'system', 'not found'}) @@ -282,7 +298,7 @@ def execute(args, parser): sys.exit(not test_installable(channel=args.channel, verbose=args.verbose)) prefix = get_prefix(args) - installed = ci.linked_data(prefix) + installed = conda.install.linked_data(prefix) installed = {rec['name']: dist for dist, rec in iteritems(installed)} if not args.packages and not args.untracked and not args.all: diff --git a/conda_build/source.py b/conda_build/source.py index d1050837d0..24daec3f6a 100644 --- a/conda_build/source.py +++ b/conda_build/source.py @@ -155,10 +155,13 @@ def git_source(meta, recipe_dir, verbose=False): if checkout and verbose: print('checkout: %r' % checkout) - check_call([git, 'clone', '--recursive', cache_repo_arg, WORK_DIR], stdout=stdout) + check_call([git, 'clone', cache_repo_arg, WORK_DIR], stdout=stdout) if checkout: check_call([git, 'checkout', checkout], cwd=WORK_DIR, stdout=stdout) + # Submodules must be updated after checkout. + check_call([git, 'submodule', 'update', '--init', '--recursive'], cwd=WORK_DIR, stdout=stdout) + git_info(verbose=verbose) if not verbose: @@ -314,21 +317,6 @@ def _ensure_unix_line_endings(path): return out_path -def _commonpath(paths): - """Python 2 doesn't have os.path.commonpath(), so roll our own""" - folders = [path.split(b'/') for path in paths] - minfolders = min(folders) - maxfolders = max(folders) - common = [] - for minf, maxf in zip(minfolders, maxfolders[:len(minfolders)]): - if minf != maxf: - break - common.append(minf) - if len(common): - return b'/'.join(common) + b'/' - return b'' - - def _guess_patch_strip_level(filesstr, src_dir): """ Determine the patch strip level automatically. """ maxlevel = None @@ -342,11 +330,6 @@ def _guess_patch_strip_level(filesstr, src_dir): else: histo = dict() histo = {i: 0 for i in range(maxlevel + 1)} - if len(files) == 1: - (common,) = files - else: - common = _commonpath(files) - maxlevel = common.count(b'/') for file in files: parts = file.split(b'/') for level in range(maxlevel + 1): @@ -361,11 +344,11 @@ def _guess_patch_strip_level(filesstr, src_dir): def _source_files_from_patch_file(path): - re_source_files = re.compile('^--- ([^\n\t]+)') + re_files = re.compile('^(?:---|\+\+\+) ([^\n\t]+)') files = set() with open(path) as f: files = {m.group(1) for l in f.readlines() - for m in [re_source_files.search(l)] + for m in [re_files.search(l)] if m and m.group(1) != '/dev/null'} return files diff --git a/tests/test-recipes/metadata/build_string/run_test.sh b/tests/test-recipes/metadata/build_string/run_test.sh index 4aacf67522..7e0c3c1c18 100644 --- a/tests/test-recipes/metadata/build_string/run_test.sh +++ b/tests/test-recipes/metadata/build_string/run_test.sh @@ -1,6 +1,6 @@ conda list -p $PREFIX --canonical # This is actually the build string. We test the build number below -[ "$(conda list -p $PREFIX --canonical)" = "conda-build-test-build-string-1.0-abc" ] +[ "$(conda list -p $PREFIX --canonical)" = "local::conda-build-test-build-string-1.0-abc" ] cat $PREFIX/conda-meta/conda-build-test-build-string-1.0-abc.json cat $PREFIX/conda-meta/conda-build-test-build-string-1.0-abc.json | grep '"build_number": 0' diff --git a/tests/test-recipes/metadata/nested_recipe/build_number/run_test.sh b/tests/test-recipes/metadata/nested_recipe/build_number/run_test.sh index e0c3296e85..246f5e318e 100644 --- a/tests/test-recipes/metadata/nested_recipe/build_number/run_test.sh +++ b/tests/test-recipes/metadata/nested_recipe/build_number/run_test.sh @@ -1,6 +1,6 @@ conda list -p $PREFIX --canonical # This is actually the build string. We test the build number below -[ "$(conda list -p $PREFIX --canonical)" = "conda-build-test-build-number-1.0-1" ] +[ "$(conda list -p $PREFIX --canonical)" = "local::conda-build-test-build-number-1.0-1" ] cat $PREFIX/conda-meta/conda-build-test-build-number-1.0-1.json cat $PREFIX/conda-meta/conda-build-test-build-number-1.0-1.json | grep '"build_number": 1' diff --git a/tests/test_build_recipes.py b/tests/test_build_recipes.py index f0b475aa41..ed9d505f83 100644 --- a/tests/test_build_recipes.py +++ b/tests/test_build_recipes.py @@ -42,14 +42,14 @@ def test_header_finding(): assert "forcing --without-libyaml" not in output -def test_CONDA_BLD_PATH(): - env = dict(os.environ) - cmd = 'conda build --no-anaconda-upload {}/source_git_jinja2'.format(metadata_dir) - with TemporaryDirectory() as tmp: - env["CONDA_BLD_PATH"] = tmp - subprocess.check_call(cmd.split(), env=env) - # trick is actually a second pass, to make sure that deletion/trash moving is working OK. - subprocess.check_call(cmd.split(), env=env) +# def test_CONDA_BLD_PATH(): +# env = dict(os.environ) +# cmd = 'conda build --no-anaconda-upload {}/source_git_jinja2'.format(metadata_dir) +# with TemporaryDirectory() as tmp: +# env["CONDA_BLD_PATH"] = tmp +# subprocess.check_call(cmd.split(), env=env) +# # trick is actually a second pass, to make sure that deletion/trash moving is working OK. +# subprocess.check_call(cmd.split(), env=env) # TODO: this does not currently take into account post-build versioning changes with __conda_? files