Skip to content

Commit

Permalink
Merge pull request #960 from msarahan/more_output_fixes
Browse files Browse the repository at this point in the history
fix more source checkout outputs showing up without --verbose
  • Loading branch information
msarahan committed May 18, 2016
2 parents f91de2a + 7725352 commit 3a496bb
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 31 deletions.
4 changes: 2 additions & 2 deletions conda_build/main_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def execute(args, parser):

# this fully renders any jinja templating, throwing an error if any data is missing
m, need_source_download = render_recipe(recipe_dir, no_download_source=False,
verbose=build.verbose)
verbose=False)
if m.get_value('build/noarch_python'):
config.noarch = True

Expand All @@ -299,7 +299,7 @@ def execute(args, parser):
elif args.test:
build.test(m, move_broken=False)
elif args.source:
source.provide(m.path, m.get_section('source'))
source.provide(m.path, m.get_section('source'), verbose=build.verbose)
print('Source tree in:', source.get_dir())
else:
# This loop recursively builds dependencies if recipes exist
Expand Down
58 changes: 32 additions & 26 deletions conda_build/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import locale
import time

from conda.compat import StringIO
from conda.fetch import download
from conda.install import move_to_trash
from conda.utils import hashsum_file
Expand Down Expand Up @@ -96,8 +95,9 @@ def git_source(meta, recipe_dir, verbose=False):
stdout = None
stderr = None
else:
stdout = StringIO()
stderr = StringIO()
FNULL = open(os.devnull, 'w')
stdout = FNULL
stderr = FNULL

if not isdir(GIT_CACHE):
os.makedirs(GIT_CACHE)
Expand Down Expand Up @@ -154,19 +154,23 @@ def git_source(meta, recipe_dir, verbose=False):
cwd=git_url)
output = process.communicate()[0].strip()
checkout = output.decode('utf-8')
if checkout:
if checkout and verbose:
print('checkout: %r' % checkout)

check_call([git, 'clone', '--recursive', cache_repo_arg, WORK_DIR],
stdout=stdout, stderr=stderr)
if checkout:
check_call([git, 'checkout', checkout], cwd=WORK_DIR, stdout=stdout, stderr=stderr)

git_info()
git_info(verbose=verbose)

if not verbose:
FNULL.close()

return WORK_DIR


def git_info(fo=None):
def git_info(fo=None, verbose=False):
''' Print info about a Git repo. '''
assert isdir(WORK_DIR)

Expand All @@ -191,10 +195,12 @@ def git_info(fo=None):
raise Exception("git error: %s" % stderr)
if fo:
fo.write(u'==> %s <==\n' % cmd)
fo.write(stdout + u'\n')
if verbose:
fo.write(stdout + u'\n')
else:
print(u'==> %s <==\n' % cmd)
safe_print_unicode(stdout + u'\n')
if verbose:
print(u'==> %s <==\n' % cmd)
safe_print_unicode(stdout + u'\n')


def hg_source(meta, verbose=False):
Expand All @@ -203,8 +209,9 @@ def hg_source(meta, verbose=False):
stdout = None
stderr = None
else:
stdout = StringIO()
stderr = StringIO()
FNULL = open(os.devnull, 'w')
stdout = FNULL
stderr = FNULL

hg = external.find_executable('hg')
if not hg:
Expand All @@ -222,10 +229,15 @@ def hg_source(meta, verbose=False):

# now clone in to work directory
update = meta.get('hg_tag') or 'tip'
print('checkout: %r' % update)
if verbose:
print('checkout: %r' % update)

check_call([hg, 'clone', cache_repo, WORK_DIR], stdout=stdout, stderr=stderr)
check_call([hg, 'update', '-C', update], cwd=WORK_DIR, stdout=stdout, stderr=stderr)

if not verbose:
FNULL.close()

return WORK_DIR


Expand All @@ -235,8 +247,9 @@ def svn_source(meta, verbose=False):
stdout = None
stderr = None
else:
stdout = StringIO()
stderr = StringIO()
FNULL = open(os.devnull, 'w')
stdout = FNULL
stderr = FNULL

def parse_bool(s):
return str(s).lower().strip() in ('yes', 'true', '1', 'on')
Expand Down Expand Up @@ -265,6 +278,10 @@ def parse_bool(s):

# now copy into work directory
copytree(cache_repo, WORK_DIR, symlinks=True)

if not verbose:
FNULL.close()

return WORK_DIR


Expand Down Expand Up @@ -331,12 +348,6 @@ def provide(recipe_dir, meta, verbose=False, patch=True):
- unpack
- apply patches (if any)
"""
# temporarily catch output to stdout and stderr
if not verbose:
stdout = sys.stdout
stderr = sys.stderr
sys.stdout = StringIO()
sys.stderr = StringIO()

if sys.platform == 'win32':
if isdir(WORK_DIR):
Expand All @@ -345,7 +356,7 @@ def provide(recipe_dir, meta, verbose=False, patch=True):
rm_rf(WORK_DIR)

if any(k in meta for k in ('fn', 'url')):
unpack(meta)
unpack(meta, verbose=verbose)
elif 'git_url' in meta:
git_source(meta, recipe_dir, verbose=verbose)
# build to make sure we have a work directory with source in it. We want to make sure that
Expand All @@ -368,11 +379,6 @@ def provide(recipe_dir, meta, verbose=False, patch=True):
for patch in meta.get('patches', []):
apply_patch(src_dir, join(recipe_dir, patch))

# restore outputs
if not verbose:
sys.stdout = stdout
sys.stderr = stderr


if __name__ == '__main__':
print(provide('.',
Expand Down
6 changes: 3 additions & 3 deletions tests/test_build_recipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ def is_valid_dir(parent_dir, dirname):


# TODO: this does not currently take into account post-build versioning changes with __conda_? files
def test_output_build_path():
cmd = 'conda build --output {}'.format(os.path.join(metadata_dir, "python_run"))
def test_output_build_path_git_source():
cmd = 'conda build --output {}'.format(os.path.join(metadata_dir, "source_git_jinja2"))
process = subprocess.Popen(cmd.split(),
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output, error = process.communicate()
test_path = os.path.join(sys.prefix, "conda-bld", subdir,
"conda-build-test-python-run-1.0-py{}{}_0.tar.bz2".format(
"conda-build-test-source-git-jinja2-1.8.1-py{}{}_0_gf3d51ae.tar.bz2".format(
sys.version_info.major, sys.version_info.minor))
if PY3:
output = output.decode("UTF-8")
Expand Down

0 comments on commit 3a496bb

Please sign in to comment.