Skip to content

Commit

Permalink
Merge pull request #93 from msarahan/conda-build-3
Browse files Browse the repository at this point in the history
Adaptations for conda-build 3 support
  • Loading branch information
pelson authored Nov 4, 2017
2 parents 7af078b + 9a47d25 commit 11e2b8f
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 24 deletions.
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ env:
matrix:
- PYTHON=2.7
- PYTHON=3.4
# test against older conda-build
- PYTHON=3.5
EXTRA_DEPS='conda-build=1.*'
EXTRA_DEPS='conda-build=2.0.*'
- PYTHON=3.5
CONDA_BUILD_ALL_TEST_ANACONDA_CLOUD=1
- PYTHON=3.5
CONDA_ORIGIN=defaults
CONDA_ORIGIN=https://repo.continuum.io/pkgs/main

install:
- mkdir -p ${HOME}/cache/pkgs
Expand All @@ -37,7 +38,7 @@ install:

# Now do the things we need to do to install it.
- conda install -c conda-forge --file requirements.txt nose mock python=${PYTHON} ${EXTRA_DEPS} --yes --quiet
- if [[ -n ${CONDA_ORIGIN} ]]; then conda install -yq -f -c ${CONDA_ORIGIN} conda; fi
- if [[ -n ${CONDA_ORIGIN} ]]; then conda install -yq -c ${CONDA_ORIGIN} conda conda-build; fi
- python setup.py install
- mkdir not_the_source_root && cd not_the_source_root

Expand Down
32 changes: 26 additions & 6 deletions conda_build_all/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@

from binstar_client.utils import get_binstar
import binstar_client
from .conda_interface import Resolve, get_index, subdir, copy_index
from .conda_interface import (Resolve, get_index, subdir, copy_index,
string_types)

try:
import conda_build.api
Expand Down Expand Up @@ -84,7 +85,17 @@ def list_metas(directory, max_depth=0, config=None):

if 'meta.yaml' in files:
if hasattr(conda_build, 'api'):
packages.append(conda_build.api.render(new_root, config=config)[0])
pkgs = conda_build.api.render(new_root, config=config,
finalize=False, bypass_env_check=True)
# cb2 returns a tuple, with the metadata object as the first
# element. That's all we care about.
if hasattr(pkgs[0], 'config'):
pkgs = [pkgs[0]]
# cb3 returns a list of tuples, each with the metadata object
# as the first element. Collect them up.
else:
pkgs = [pkg[0] for pkg in pkgs]
packages.extend(pkgs)
else:
packages.append(MetaData(new_root))

Expand All @@ -107,8 +118,15 @@ def select_lines(data, *args, **kwargs):
# is only a suitable solution when selectors are also comments.
return data

meta.final = False
with mock.patch('conda_build.metadata.select_lines', new=select_lines):
with mock.patch('conda_build.jinja_context.select_lines', new=select_lines):
try:
with mock.patch('conda_build.jinja_context.select_lines', new=select_lines):
try:
meta.parse_again(config, permit_undefined_jinja=True)
except TypeError:
meta.parse_again(permit_undefined_jinja=True)
except AttributeError:
try:
meta.parse_again(config, permit_undefined_jinja=True)
except TypeError:
Expand Down Expand Up @@ -206,11 +224,13 @@ def build(self, meta, config):
print('Building ', meta.dist())
config = meta.vn_context(config=config)
try:
conda_build.api.build(meta.meta, config=config)
return conda_build.api.get_output_file_path(meta.meta, config)
output_paths = conda_build.api.build(meta.meta, config=config)
except AttributeError:
with meta.vn_context():
return bldpkg_path(build.build(meta.meta))
output_paths = bldpkg_path(build.build(meta.meta))
if isinstance(output_paths, string_types):
output_paths = [output_paths]
return output_paths

def compute_build_distros(self, index, recipes, config):
"""
Expand Down
3 changes: 3 additions & 0 deletions conda_build_all/conda_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from conda.exports import Unsatisfiable
from conda.exports import NoPackagesFound
from conda.exports import Resolve
from conda.exports import string_types
from conda.models.dist import Dist as _Dist

def get_key(dist_or_filename):
Expand All @@ -37,6 +38,7 @@ def ensure_dist_or_dict(fn):
from conda.exports import Unsatisfiable
from conda.exports import NoPackagesFound
from conda.exports import Resolve
from conda.exports import string_types

def get_key(dist_or_filename):
return dist_or_filename.fn
Expand All @@ -63,3 +65,4 @@ def ensure_dist_or_dict(fn):
Resolve, get_index = Resolve, get_index
MatchSpec = MatchSpec
Unsatisfiable, NoPackagesFound = Unsatisfiable, NoPackagesFound
string_types = string_types
38 changes: 23 additions & 15 deletions conda_build_all/tests/integration/test_builder.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from contextlib import contextmanager
import os
import re
import shutil
import tempfile
import textwrap
Expand All @@ -11,6 +12,7 @@
import conda_build.config

from conda_build.metadata import MetaData
from conda_build_all.conda_interface import string_types

from conda_build_all.resolved_distribution import ResolvedDistribution
from conda_build_all.builder import Builder
Expand Down Expand Up @@ -55,12 +57,14 @@ def test_no_source(self):
pkg1_resolved = ResolvedDistribution(pkg1, (()))
builder = Builder(None, None, None, None, None)
if hasattr(conda_build, 'api'):
r = builder.build(pkg1_resolved, conda_build.api.Config())
rs = builder.build(pkg1_resolved, conda_build.api.Config())
else:
r = builder.build(pkg1_resolved, conda_build.config.config)
self.assertTrue(os.path.exists(r))
self.assertEqual(os.path.abspath(r), r)
self.assertEqual(os.path.basename(r), 'pkg1-1.0-0.tar.bz2')
rs = builder.build(pkg1_resolved, conda_build.config.config)
for r in rs:
self.assertTrue(os.path.exists(r))
self.assertEqual(os.path.abspath(r), r)
self.assertTrue(bool(re.match('pkg1-1.0-(h[0-9a-f]{7}_)?0.tar.bz2',
os.path.basename(r))))

def test_noarch_python(self):
pkg1 = self.write_meta('pkg1', """
Expand All @@ -78,12 +82,14 @@ def test_noarch_python(self):
pkg1_resolved = ResolvedDistribution(pkg1, (['python', '3.5'], ))
builder = Builder(None, None, None, None, None)
if hasattr(conda_build, 'api'):
r = builder.build(pkg1_resolved, conda_build.api.Config())
rs = builder.build(pkg1_resolved, conda_build.api.Config())
else:
r = builder.build(pkg1_resolved, conda_build.config.config)
self.assertTrue(os.path.exists(r))
self.assertEqual(os.path.abspath(r), r)
self.assertEqual(os.path.basename(r), 'pkg1-1.0-py_0.tar.bz2')
rs = builder.build(pkg1_resolved, conda_build.config.config)
for r in rs:
self.assertTrue(os.path.exists(r))
self.assertEqual(os.path.abspath(r), r)
self.assertTrue(bool(re.match('pkg1-1.0-py(h[0-9a-f]{7})?_0.tar.bz2',
os.path.basename(r))))

def test_numpy_dep(self):
pkg1 = self.write_meta('pkg1', """
Expand All @@ -101,12 +107,14 @@ def test_numpy_dep(self):
pkg1_resolved = ResolvedDistribution(pkg1, (['python', '3.5'], ['numpy', '1.11']))
builder = Builder(None, None, None, None, None)
if hasattr(conda_build, 'api'):
r = builder.build(pkg1_resolved, conda_build.api.Config())
rs = builder.build(pkg1_resolved, conda_build.api.Config())
else:
r = builder.build(pkg1_resolved, conda_build.config.config)
self.assertTrue(os.path.exists(r))
self.assertEqual(os.path.abspath(r), r)
self.assertEqual(os.path.basename(r), 'pkg1-1.0-np111py35_0.tar.bz2')
rs = builder.build(pkg1_resolved, conda_build.config.config)
for r in rs:
self.assertTrue(os.path.exists(r))
self.assertEqual(os.path.abspath(r), r)
self.assertTrue(bool(re.match('pkg1-1.0-np111py35(h[0-9a-f]{7})?_0.tar.bz2',
os.path.basename(r))))


class Test__find_existing_built_dists(RecipeCreatingUnit):
Expand Down

0 comments on commit 11e2b8f

Please sign in to comment.