Skip to content

Commit

Permalink
Merge pull request #63 from dkillick/config_for_post-build
Browse files Browse the repository at this point in the history
Use conda-build config variable when making built artefact available
  • Loading branch information
pelson authored Sep 15, 2016
2 parents b6429bd + 8200a54 commit 4afd09b
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 21 deletions.
11 changes: 7 additions & 4 deletions conda_build_all/artefact_destination.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ArtefactDestination(object):
def __init__(self):
pass

def make_available(self, meta, built_dist_path, just_built):
def make_available(self, meta, built_dist_path, just_built, config=None):
"""
Put the built distribution on this destination.
Expand All @@ -45,6 +45,8 @@ def make_available(self, meta, built_dist_path, just_built):
The location of the built distribution for this artefact.
just_built : bool
Whether this artefact was just built, or was already available.
config
The conda-build configuration for the build.
"""
pass
Expand All @@ -58,7 +60,7 @@ def __init__(self, directory):
if not os.path.isdir(self.directory):
raise IOError("The destination provided is not a directory.")

def make_available(self, meta, built_dist_path, just_built):
def make_available(self, meta, built_dist_path, just_built, config=None):
if just_built:
print(meta, built_dist_path, just_built)
shutil.copy(built_dist_path, self.directory)
Expand Down Expand Up @@ -87,7 +89,7 @@ def from_spec(cls, spec):
owner, channel = spec, 'main'
return cls(token, owner, channel)

def make_available(self, meta, built_dist_path, just_built):
def make_available(self, meta, built_dist_path, just_built, config=None):
if self._cli is None:
self._cli = binstar_client.utils.get_binstar(Namespace(token=self.token, site=None))

Expand All @@ -112,7 +114,8 @@ def make_available(self, meta, built_dist_path, just_built):
elif just_built:
# Upload the distribution
log.info('Uploading {} to the {} channel.'.format(meta.name(), self.channel))
build.upload(self._cli, meta, self.owner, channels=[self.channel])
build.upload(self._cli, meta, self.owner, channels=[self.channel],
config=config)

elif not just_built:
# The distribution already existed, but not under the target owner.
Expand Down
4 changes: 2 additions & 2 deletions conda_build_all/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ def build(meta, test=True):
return meta


def upload(cli, meta, owner, channels=['main']):
def upload(cli, meta, owner, channels=['main'], config=None):
"""Upload a distribution, given the build metadata."""
fname = bldpkg_path(meta)
fname = bldpkg_path(meta, config)
package_type = detect_package_type(fname)
package_attrs, release_attrs, file_attrs = get_attrs(package_type, fname)
package_name = package_attrs['name']
Expand Down
12 changes: 8 additions & 4 deletions conda_build_all/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def compute_build_distros(self, index, recipes, config):
return all_distros

def main(self):
index = get_index(use_cache=True)
index = get_index(use_cache=False)
if hasattr(conda_build, 'api'):
build_config = conda_build.api.Config()
else:
Expand Down Expand Up @@ -261,9 +261,10 @@ def main(self):
was_built = built_dist_location is None
if was_built:
built_dist_location = self.build(meta, build_config)
self.post_build(meta, built_dist_location, was_built)
self.post_build(meta, built_dist_location, was_built,
config=build_config)

def post_build(self, meta, built_dist_location, was_built):
def post_build(self, meta, built_dist_location, was_built, config=None):
"""
The post build phase occurs whether or not a build has actually taken place.
It is the point at which a distribution is transfered to the desired artefact
Expand All @@ -275,7 +276,10 @@ def post_build(self, meta, built_dist_location, was_built):
The distribution for which we are running the post-build phase
build_dist_location : str
The location of the built .tar.bz2 file for the given meta.
config
The conda-build configuration for the build.
"""
for artefact_destination in self.artefact_destinations:
artefact_destination.make_available(meta, built_dist_location, was_built)
artefact_destination.make_available(meta, built_dist_location, was_built,
config=config)
10 changes: 9 additions & 1 deletion conda_build_all/tests/integration/test_inspect_binstar.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

from binstar_client.utils import get_binstar
from argparse import Namespace
try:
import conda_build.api
except ImportError:
import conda_build.config

from conda_build_all.build import build, upload
from conda_build_all.inspect_binstar import (distribution_exists,
Expand Down Expand Up @@ -57,12 +61,16 @@ def test_distribution_exists(self):
script: echo "v0.1.0.dev1" > __conda_version__.txt
""")
meta = build(meta)
if hasattr(conda_build, 'api'):
build_config = conda_build.api.Config()
else:
build_config = conda_build.config.config

# Check distribution exists returns false when there is no distribution.
self.assertFalse(distribution_exists(CLIENT, OWNER, meta))

# upload the distribution
upload(CLIENT, meta, OWNER, channels=['testing'])
upload(CLIENT, meta, OWNER, channels=['testing'], config=build_config)

# Check the distribution exists. Notice there is no channel being supplied here.
self.assertTrue(distribution_exists(CLIENT, OWNER, meta))
Expand Down
39 changes: 29 additions & 10 deletions conda_build_all/tests/unit/test_artefact_destination.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ def setUp(self):
def tearDown(self):
self.logger_patch.stop()

def _get_config(self):
# Provide an object that will behave like a conda_build config object.
config = mock.Mock()
config.bldpkgs_dir = mock.Mock(return_value='')
return config

@contextmanager
def dist_exists_setup(self, on_owner, on_channel):
dist_exists = mock.patch('conda_build_all.inspect_binstar.distribution_exists', return_value=on_owner)
Expand All @@ -44,10 +50,11 @@ def test_not_already_available_not_just_built(self):
ad = AnacondaClientChannelDest(mock.sentinel.token, owner, channel)
ad._cli = client
meta = DummyPackage('a', '2.1.0')
config = self._get_config()
with self.dist_exists_setup(on_owner=True, on_channel=False):
with mock.patch('conda_build_all.inspect_binstar.add_distribution_to_channel') as add_to_channel:
ad.make_available(meta, mock.sentinel.dist_path,
just_built=False)
just_built=False, config=config)
add_to_channel.assert_called_once_with(client, owner, meta, channel=channel)
self.logger.info.assert_called_once_with('Adding existing a-0.0-0 to the sentinel.owner/sentinel.channel channel.')

Expand All @@ -57,11 +64,13 @@ def test_not_already_available_just_built(self):
ad = AnacondaClientChannelDest(mock.sentinel.token, owner, channel)
ad._cli = client
meta = DummyPackage('a', '2.1.0')
config = self._get_config()
with self.dist_exists_setup(on_owner=False, on_channel=False):
with mock.patch('conda_build_all.build.upload') as upload:
ad.make_available(meta, mock.sentinel.dist_path,
just_built=True)
upload.assert_called_once_with(client, meta, owner, channels=[channel])
just_built=True, config=config)
upload.assert_called_once_with(client, meta, owner,
channels=[channel], config=config)
self.logger.info.assert_called_once_with('Uploading a to the sentinel.channel channel.')

def test_already_available_not_just_built(self):
Expand All @@ -71,9 +80,11 @@ def test_already_available_not_just_built(self):
mock.sentinel.channel]
ad = AnacondaClientChannelDest(mock.sentinel.token, owner, channel)
meta = DummyPackage('a', '2.1.0')
config = self._get_config()
with self.dist_exists_setup(on_owner=True, on_channel=True):
with mock.patch('binstar_client.utils.get_binstar') as get_binstar:
ad.make_available(meta, mock.sentinel.dist_path, just_built=False)
ad.make_available(meta, mock.sentinel.dist_path,
just_built=False, config=config)
get_binstar.assert_called_once_with(Namespace(site=None, token=mock.sentinel.token))
# Nothing happens, we just get a message.
self.logger.info.assert_called_once_with('Nothing to be done for a - it is already on sentinel.owner/sentinel.channel.')
Expand All @@ -84,8 +95,10 @@ def test_already_available_just_built(self):
ad = AnacondaClientChannelDest(mock.sentinel.token, owner, channel)
ad._cli = client
meta = DummyPackage('a', '2.1.0')
config = self._get_config()
with self.dist_exists_setup(on_owner=True, on_channel=True):
ad.make_available(meta, mock.sentinel.dist_path, just_built=True)
ad.make_available(meta, mock.sentinel.dist_path,
just_built=True, config=config)
# Nothing happens, we just get a message.
self.logger.warn.assert_called_once_with("Assuming the distribution we've just built and the one on sentinel.owner/sentinel.channel are the same.")

Expand All @@ -95,14 +108,16 @@ def test_already_available_elsewhere(self):
ad = AnacondaClientChannelDest(mock.sentinel.token, owner, channel)
ad._cli = client
meta = DummyPackage('a', '2.1.0')
config = self._get_config()
source_owner = 'fake_owner'
# The osx-64 subdirectory at the end of the URL is not important to the test.
for url in ['http://foo.bar/{}/osx-64/'.format(source_owner),
'https://foo.bar/wibble/{}/osx-64/'.format(source_owner),
'https://foo.bar/wibble/{}/osx-64'.format(source_owner)]:
with self.dist_exists_setup(on_owner=False, on_channel=False):
with mock.patch('conda_build_all.inspect_binstar.copy_distribution_to_owner') as copy:
ad.make_available(meta, url, just_built=False)
ad.make_available(meta, url, just_built=False,
config=config)
copy.assert_called_once_with(ad._cli, source_owner, owner, meta, channel=channel)

def test_from_spec_owner(self):
Expand Down Expand Up @@ -131,14 +146,18 @@ def tearDown(self):

def test_not_copying(self):
dd = DirectoryDestination(self.tmp_dir)
dd.make_available(mock.sentinel.dummy_meta, mock.sentinel.dummy_path,
just_built=False)
dd.make_available(mock.sentinel.dummy_meta,
mock.sentinel.dummy_path,
just_built=False,
config=mock.sentinel.dummy_config)

def test_copying(self):
dd = DirectoryDestination(self.tmp_dir)
with mock.patch('shutil.copy') as copy:
dd.make_available(mock.sentinel.dummy_meta, mock.sentinel.dummy_path,
just_built=True)
dd.make_available(mock.sentinel.dummy_meta,
mock.sentinel.dummy_path,
just_built=True,
config=mock.sentinel.dummy_config)
copy.assert_called_once_with(mock.sentinel.dummy_path, self.tmp_dir)


Expand Down

0 comments on commit 4afd09b

Please sign in to comment.