Skip to content

Commit

Permalink
fix extraneous output when outputting build path
Browse files Browse the repository at this point in the history
  • Loading branch information
msarahan committed May 18, 2016
1 parent eedbe7f commit b4ec0e0
Show file tree
Hide file tree
Showing 7 changed files with 247 additions and 77 deletions.
11 changes: 9 additions & 2 deletions conda_build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ def create_info_files(m, files, include_recipe=True):
shutil.copytree(src_path, dst_path)
else:
shutil.copy(src_path, dst_path)
# move the potentially unrendered meta.yaml file
os.rename(join(recipe_dir, "meta.yaml"), join(recipe_dir, "meta.yaml.template"))
# store the rendered meta.yaml file, plus information about where it came from
# and what version of conda-build created it
_render_recipe()


license_file = m.get_value('about/license_file')
if license_file:
Expand Down Expand Up @@ -368,7 +374,7 @@ def bldpkg_path(m):
return join(config.bldpkgs_dir, '%s.tar.bz2' % m.dist())


def build(m, post=None, include_recipe=True, keep_old_work=False, need_source_download=False):
def build(m, post=None, include_recipe=True, keep_old_work=False, need_source_download=True):
'''
Build the package with the specified metadata.
Expand Down Expand Up @@ -436,7 +442,8 @@ def build(m, post=None, include_recipe=True, keep_old_work=False, need_source_do
try:
os.environ['PATH'] = prepend_bin_path({'PATH': _old_path},
config.build_prefix)['PATH']
m, need_source_download = parse_or_try_download(m, no_download_source=False)
m, need_source_download = parse_or_try_download(m, no_download_source=False,
hide_output=False)
assert not need_source_download, "Source download failed. Please investigate."
finally:
os.environ['PATH'] = _old_path
Expand Down
3 changes: 2 additions & 1 deletion conda_build/main_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@ def execute(args, parser):
sys.exit("Error: no such directory: %s" % recipe_dir)

# 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)
m, need_source_download = render_recipe(recipe_dir, no_download_source=False,
hide_download_output=args.output)
if m.get_value('build/noarch_python'):
config.noarch = True

Expand Down
47 changes: 5 additions & 42 deletions conda_build/main_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def get_render_parser():
version='conda-build %s' % __version__,
)
p.add_argument(
'-n', "--no_source",
'-n', "--no-source",
action="store_true",
help="When templating can't be completed, do not obtain the \
source to try fill in related template variables.",
Expand Down Expand Up @@ -100,37 +100,6 @@ def get_render_parser():
return p


# Next bit of stuff is to support YAML output in the order we expect.
# http://stackoverflow.com/a/17310199/1170370
class MetaYaml(dict):
fields = ["package", "source", "build", "requirements", "test", "about", "extra"]

def to_omap(self):
return [(field, self[field]) for field in MetaYaml.fields if field in self]


def represent_omap(dumper, data):
return dumper.represent_mapping(u'tag:yaml.org,2002:map', data.to_omap())


def unicode_representer(dumper, uni):
node = yaml.ScalarNode(tag=u'tag:yaml.org,2002:str', value=uni)
return node


class IndentDumper(yaml.Dumper):
def increase_indent(self, flow=False, indentless=False):
return super(IndentDumper, self).increase_indent(flow, False)


yaml.add_representer(MetaYaml, represent_omap)
if PY3:
yaml.add_representer(str, unicode_representer)
unicode = None # silence pyflakes about unicode not existing in py3
else:
yaml.add_representer(unicode, unicode_representer)


def main():
p = get_render_parser()
p.add_argument(
Expand All @@ -151,18 +120,12 @@ def main():
args = p.parse_args()
set_language_env_vars(args, p)

metadata = render_recipe(find_recipe(args.recipe), no_download_source=args.no_source)
metadata, _ = _render_recipe(find_recipe(args.recipe), no_download_source=args.no_source,
hide_download_output=args.output)
if args.output:
print(bldpkg_path(metadata))
print(_get_output_path(metadata))
else:
output = yaml.dump(MetaYaml(metadata.meta), Dumper=IndentDumper,
default_flow_style=False, indent=4)
if args.file:
with open(args.file, "w") as f:
f.write(output)
else:
print(output)

print(_output_yaml(metadata, args.file)

if __name__ == '__main__':
main()
57 changes: 50 additions & 7 deletions conda_build/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from conda.compat import PY3
from conda.lock import Locked

from conda_build.build import bldpkg_path
from conda_build import exceptions
from conda_build.config import config
from conda_build.metadata import MetaData
Expand Down Expand Up @@ -65,7 +66,10 @@ def set_language_env_vars(args, parser, execute=None):
os.environ[var] = str(getattr(config, var))


def parse_or_try_download(metadata, no_download_source):
def get_output_path(metadata):
return bldpkg_path(metadata)

def parse_or_try_download(metadata, no_download_source, hide_output):
if not no_download_source:
# this try/catch is for when the tool to download source is actually in
# meta.yaml, and not previously installed in builder env.
Expand All @@ -75,15 +79,15 @@ def parse_or_try_download(metadata, no_download_source):
need_source_download = False
except subprocess.CalledProcessError:
print("Warning: failed to download source. If building, will try "
"again after downloading recipe dependencies.")
"again after downloading recipe dependencies.")
need_source_download = True
else:
metadata.parse_again(permit_undefined_jinja=False)
need_source_download = no_download_source
else:
need_source_download = no_download_source
metadata.parse_again(permit_undefined_jinja=False)
return metadata, need_source_download


def render_recipe(recipe_path, no_download_source):
def render_recipe(recipe_path, no_download_source, hide_download_output):
with Locked(config.croot):
arg = recipe_path
# Don't use byte literals for paths in Python 2
Expand Down Expand Up @@ -112,9 +116,48 @@ def render_recipe(recipe_path, no_download_source):
sys.stderr.write(e.error_msg())
sys.exit(1)

m = parse_or_try_download(m, no_download_source=no_download_source)
m = parse_or_try_download(m, no_download_source=no_download_source,
hide_output=hide_download_output)

if need_cleanup:
shutil.rmtree(recipe_dir)

return m


# Next bit of stuff is to support YAML output in the order we expect.
# http://stackoverflow.com/a/17310199/1170370
class _MetaYaml(dict):
fields = ["package", "source", "build", "requirements", "test", "about", "extra"]

def to_omap(self):
return [(field, self[field]) for field in MetaYaml.fields if field in self]

def _represent_omap(dumper, data):
return dumper.represent_mapping(u'tag:yaml.org,2002:map', data.to_omap())

def _unicode_representer(dumper, uni):
node = yaml.ScalarNode(tag=u'tag:yaml.org,2002:str', value=uni)
return node

class _IndentDumper(yaml.Dumper):
def increase_indent(self, flow=False, indentless=False):
return super(_IndentDumper, self).increase_indent(flow, False)

yaml.add_representer(_MetaYaml, _represent_omap)
if PY3:
yaml.add_representer(str, _unicode_representer)
unicode = None # silence pyflakes about unicode not existing in py3
else:
yaml.add_representer(unicode, _unicode_representer)


def output_yaml(metdata, filename=None):
output = yaml.dump(_MetaYaml(metadata.meta), Dumper=_IndentDumper,
default_flow_style=False, indent=4)
if filename:
with open(filename, "w") as f:
f.write(output)
return("Wrote yaml to %s" % filename)
else:
return(output)
Loading

0 comments on commit b4ec0e0

Please sign in to comment.