Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

split off recipe render from build; recurse to find meta.yaml #908

Merged
merged 11 commits into from
May 5, 2016
5 changes: 5 additions & 0 deletions bin/conda-render
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env python
import sys
from conda_build.main_render import main

sys.exit(main())
50 changes: 50 additions & 0 deletions conda_build/completers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import os
from os.path import isdir, isfile, join
from conda.cli.common import Completer


all_versions = {
'python': [26, 27, 33, 34, 35],
'numpy': [16, 17, 18, 19, 110],
'perl': None,
'R': None,
'lua': ["2.0", "5.1", "5.2", "5.3"]
}

conda_version = {
'python': 'CONDA_PY',
'numpy': 'CONDA_NPY',
'perl': 'CONDA_PERL',
'R': 'CONDA_R',
'lua': 'CONDA_LUA',
}

class RecipeCompleter(Completer):
def _get_items(self):
completions = []
for path in os.listdir('.'):
if isdir(path) and isfile(join(path, 'meta.yaml')):
completions.append(path)
if isfile('meta.yaml'):
completions.append('.')
return completions

# These don't represent all supported versions. It's just for tab completion.

class PythonVersionCompleter(Completer):
def _get_items(self):
return ['all'] + [str(i/10) for i in all_versions['python']]

class NumPyVersionCompleter(Completer):
def _get_items(self):
versions = [str(i) for i in all_versions['numpy']]
return ['all'] + ['%s.%s' % (ver[0], ver[1:]) for ver in versions]

class RVersionsCompleter(Completer):
def _get_items(self):
return ['3.1.2', '3.1.3', '3.2.0', '3.2.1', '3.2.2']

class LuaVersionsCompleter(Completer):
def _get_items(self):
return ['all'] + [i for i in all_versions['lua']]

187 changes: 22 additions & 165 deletions conda_build/main_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,78 +7,35 @@
from __future__ import absolute_import, division, print_function

import argparse
import os
import sys
from collections import deque
from glob import glob
from locale import getpreferredencoding
from os import listdir
from os import environ as os_environ
from os.path import exists, isdir, isfile, join
import warnings

import conda.config as config
from conda.compat import PY3
from conda.cli.common import add_parser_channels, Completer
from conda.cli.conda_argparse import ArgumentParser
from conda.cli.common import add_parser_channels
from conda.install import delete_trash
from conda.resolve import NoPackagesFound, Unsatisfiable

from conda_build import __version__, exceptions
from conda_build import exceptions
from conda_build.index import update_index
from conda.install import delete_trash
from conda_build.main_render import get_render_parser
from conda_build.utils import find_recipe
from conda_build.main_render import get_package_build_string, set_language_env_vars, RecipeCompleter
on_win = (sys.platform == 'win32')

all_versions = {
'python': [26, 27, 33, 34, 35],
'numpy': [16, 17, 18, 19, 110],
'perl': None,
'R': None,
'lua': ["2.0", "5.1", "5.2", "5.3"]
}

class RecipeCompleter(Completer):
def _get_items(self):
completions = []
for path in listdir('.'):
if isdir(path) and isfile(join(path, 'meta.yaml')):
completions.append(path)
if isfile('meta.yaml'):
completions.append('.')
return completions

# These don't represent all supported versions. It's just for tab completion.

class PythonVersionCompleter(Completer):
def _get_items(self):
return ['all'] + [str(i/10) for i in all_versions['python']]

class NumPyVersionCompleter(Completer):
def _get_items(self):
versions = [str(i) for i in all_versions['numpy']]
return ['all'] + ['%s.%s' % (ver[0], ver[1:]) for ver in versions]

class RVersionsCompleter(Completer):
def _get_items(self):
return ['3.1.2', '3.1.3', '3.2.0', '3.2.1', '3.2.2']

class LuaVersionsCompleter(Completer):
def _get_items(self):
return ['all'] + [i for i in all_versions['lua']]

def main():
p = ArgumentParser(
description="""
p=get_render_parser()
p.description="""
Tool for building conda packages. A conda package is a binary tarball
containing system-level libraries, Python modules, executable programs, or
other components. conda keeps track of dependencies between packages and
platform specifics, making it simple to create working environments from
different sets of packages."""
)
p.add_argument(
'-V', '--version',
action='version',
help='Show the conda-build version number and exit.',
version = 'conda-build %s' % __version__,
)
p.add_argument(
"--check",
action="store_true",
Expand All @@ -105,12 +62,6 @@ def main():
dest='include_recipe',
default=True,
)
p.add_argument(
"--output",
action="store_true",
help="Output the conda package filename which would have been "
"created and exit.",
)
p.add_argument(
'-s', "--source",
action="store_true",
Expand All @@ -121,14 +72,6 @@ def main():
action="store_true",
help="Test package (assumes package is already build).",
)
p.add_argument(
'recipe',
action="store",
metavar='RECIPE_PATH',
nargs='+',
choices=RecipeCompleter(),
help="Path to recipe directory.",
)
p.add_argument(
'--no-test',
action='store_true',
Expand All @@ -146,6 +89,14 @@ def main():
action="store_true",
help="Run the post-build logic. Implies --no-test and --no-anaconda-upload.",
)
p.add_argument(
'recipe',
action="store",
metavar='RECIPE_PATH',
nargs='+',
choices=RecipeCompleter(),
help="Path to recipe directory.",
)
p.add_argument(
'--skip-existing',
action='store_true',
Expand All @@ -157,49 +108,6 @@ def main():
action="store_true",
help="do not display progress bar",
)
p.add_argument(
'--python',
action="append",
help="""Set the Python version used by conda build. Can be passed
multiple times to build against multiple versions. Can be 'all' to
build against all known versions (%r)""" % [i for i in
PythonVersionCompleter() if '.' in i],
metavar="PYTHON_VER",
choices=PythonVersionCompleter(),
)
p.add_argument(
'--perl',
action="append",
help="""Set the Perl version used by conda build. Can be passed
multiple times to build against multiple versions.""",
metavar="PERL_VER",
)
p.add_argument(
'--numpy',
action="append",
help="""Set the NumPy version used by conda build. Can be passed
multiple times to build against multiple versions. Can be 'all' to
build against all known versions (%r)""" % [i for i in
NumPyVersionCompleter() if '.' in i],
metavar="NUMPY_VER",
choices=NumPyVersionCompleter(),
)
p.add_argument(
'--R',
action="append",
help="""Set the R version used by conda build. Can be passed
multiple times to build against multiple versions.""",
metavar="R_VER",
choices=RVersionsCompleter(),
)
p.add_argument(
'--lua',
action="append",
help="""Set the Lua version used by conda build. Can be passed
multiple times to build against multiple versions (%r).""" % [i for i in LuaVersionsCompleter()],
metavar="LUA_VER",
choices=LuaVersionsCompleter(),
)

add_parser_channels(p)
p.set_defaults(func=execute)
Expand Down Expand Up @@ -303,49 +211,7 @@ def execute(args, parser):
"imported that is hard-linked by files in the trash. "
"Will try again on next run.")

conda_version = {
'python': 'CONDA_PY',
'numpy': 'CONDA_NPY',
'perl': 'CONDA_PERL',
'R': 'CONDA_R',
'lua': 'CONDA_LUA',
}

for lang in ['python', 'numpy', 'perl', 'R', 'lua']:
versions = getattr(args, lang)
if not versions:
continue
if versions == ['all']:
if all_versions[lang]:
versions = all_versions[lang]
else:
parser.error("'all' is not supported for --%s" % lang)
if len(versions) > 1:
for ver in versions[:]:
setattr(args, lang, [str(ver)])
execute(args, parser)
# This is necessary to make all combinations build.
setattr(args, lang, versions)
return
else:
version = versions[0]
if lang in ('python', 'numpy'):
version = int(version.replace('.', ''))
setattr(config, conda_version[lang], version)
if not len(str(version)) in (2, 3) and lang in ['python', 'numpy']:
if all_versions[lang]:
raise RuntimeError("%s must be major.minor, like %s, not %s" %
(conda_version[lang], all_versions[lang][-1]/10, version))
else:
raise RuntimeError("%s must be major.minor, not %s" %
(conda_version[lang], version))

# Using --python, --numpy etc. is equivalent to using CONDA_PY, CONDA_NPY, etc.
# Auto-set those env variables
for var in conda_version.values():
if getattr(config, var):
# Set the env variable.
os_environ[var] = str(getattr(config, var))
set_language_env_vars(args, parser, execute=execute)

if args.skip_existing:
for d in config.bldpkgs_dirs:
Expand Down Expand Up @@ -378,6 +244,8 @@ def execute(args, parser):
recipe_dir = abspath(arg)
need_cleanup = False

# recurse looking for meta.yaml that is potentially not in immediate folder
recipe_dir = find_recipe(recipe_dir)
if not isdir(recipe_dir):
sys.exit("Error: no such directory: %s" % recipe_dir)

Expand All @@ -403,18 +271,7 @@ def execute(args, parser):
"configuration." % m.dist())
continue
if args.output:
try:
m.parse_again(permit_undefined_jinja=False)
except SystemExit:
# Something went wrong; possibly due to undefined GIT_ jinja variables.
# Maybe we need to actually download the source in order to resolve the build_id.
source.provide(m.path, m.get_section('source'))

# Parse our metadata again because we did not initialize the source
# information before.
m.parse_again(permit_undefined_jinja=False)

print(build.bldpkg_path(m))
print(get_package_build_string(m))
continue
elif args.test:
build.test(m, move_broken=False)
Expand Down Expand Up @@ -453,7 +310,7 @@ def execute(args, parser):
if pkg in skip_names:
continue
recipe_glob = glob(pkg + '-[v0-9][0-9.]*')
if exists(pkg):
if os.path.exists(pkg):
recipe_glob.append(pkg)
if recipe_glob:
try_again = True
Expand Down