<s> from __future__ import absolute_import , division , print_function <EOL> import argparse <EOL> import sys <EOL> from collections import deque <EOL> from glob import glob <EOL> from locale import getpreferredencoding <EOL> from os import listdir <EOL> from os import environ as os_environ <EOL> from os . path import exists , isdir , isfile , join <EOL> import warnings <EOL> import conda . config as config <EOL> from conda . compat import PY3 <EOL> from conda . cli . common import add_parser_channels , Completer <EOL> from conda . cli . conda_argparse import ArgumentParser <EOL> from conda . resolve import NoPackagesFound , Unsatisfiable <EOL> from conda_build import __version__ , exceptions <EOL> from conda_build . index import update_index <EOL> from conda . install import delete_trash <EOL> on_win = ( sys . platform == '<STR_LIT:win32>' ) <EOL> all_versions = { <EOL> '<STR_LIT>' : [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> '<STR_LIT>' : [ <NUM_LIT:16> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT:R>' : None , <EOL> '<STR_LIT>' : [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> } <EOL> class RecipeCompleter ( Completer ) : <EOL> def _get_items ( self ) : <EOL> completions = [ ] <EOL> for path in listdir ( '<STR_LIT:.>' ) : <EOL> if isdir ( path ) and isfile ( join ( path , '<STR_LIT>' ) ) : <EOL> completions . append ( path ) <EOL> if isfile ( '<STR_LIT>' ) : <EOL> completions . append ( '<STR_LIT:.>' ) <EOL> return completions <EOL> class PythonVersionCompleter ( Completer ) : <EOL> def _get_items ( self ) : <EOL> return [ '<STR_LIT:all>' ] + [ str ( i / <NUM_LIT:10> ) for i in all_versions [ '<STR_LIT>' ] ] <EOL> class NumPyVersionCompleter ( Completer ) : <EOL> def _get_items ( self ) : <EOL> versions = [ str ( i ) for i in all_versions [ '<STR_LIT>' ] ] <EOL> return [ '<STR_LIT:all>' ] + [ '<STR_LIT>' % ( ver [ <NUM_LIT:0> ] , ver [ <NUM_LIT:1> : ] ) for ver in versions ] <EOL> class RVersionsCompleter ( Completer ) : <EOL> def _get_items ( self ) : <EOL> return [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> class LuaVersionsCompleter ( Completer ) : <EOL> def _get_items ( self ) : <EOL> return [ '<STR_LIT:all>' ] + [ i for i in all_versions [ '<STR_LIT>' ] ] <EOL> def main ( ) : <EOL> p = ArgumentParser ( <EOL> description = """<STR_LIT>""" <EOL> ) <EOL> p . add_argument ( <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> action = '<STR_LIT:version>' , <EOL> help = '<STR_LIT>' , <EOL> version = '<STR_LIT>' % __version__ , <EOL> ) <EOL> p . add_argument ( <EOL> "<STR_LIT>" , <EOL> action = "<STR_LIT:store_true>" , <EOL> help = "<STR_LIT>" , <EOL> ) <EOL> p . add_argument ( <EOL> "<STR_LIT>" , <EOL> action = "<STR_LIT>" , <EOL> help = "<STR_LIT>" , <EOL> dest = '<STR_LIT>' , <EOL> default = config . binstar_upload , <EOL> ) <EOL> p . add_argument ( <EOL> "<STR_LIT>" , <EOL> action = "<STR_LIT>" , <EOL> help = argparse . SUPPRESS , <EOL> dest = '<STR_LIT>' , <EOL> default = config . binstar_upload , <EOL> ) <EOL> p . add_argument ( <EOL> "<STR_LIT>" , <EOL> action = "<STR_LIT>" , <EOL> help = "<STR_LIT>" , <EOL> dest = '<STR_LIT>' , <EOL> default = True , <EOL> ) <EOL> p . add_argument ( <EOL> "<STR_LIT>" , <EOL> action = "<STR_LIT:store_true>" , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> ) <EOL> p . add_argument ( <EOL> '<STR_LIT>' , "<STR_LIT>" , <EOL> action = "<STR_LIT:store_true>" , <EOL> help = "<STR_LIT>" , <EOL> ) <EOL> p . add_argument ( <EOL> '<STR_LIT>' , "<STR_LIT>" , <EOL> action = "<STR_LIT:store_true>" , <EOL> help = "<STR_LIT>" , <EOL> ) <EOL> p . add_argument ( <EOL> '<STR_LIT>' , <EOL> action = "<STR_LIT:store>" , <EOL> metavar = '<STR_LIT>' , <EOL> nargs = '<STR_LIT:+>' , <EOL> choices = RecipeCompleter ( ) , <EOL> help = "<STR_LIT>" , <EOL> ) <EOL> p . add_argument ( <EOL> '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> dest = '<STR_LIT>' , <EOL> help = "<STR_LIT>" , <EOL> ) <EOL> p . add_argument ( <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> action = "<STR_LIT:store_true>" , <EOL> help = """<STR_LIT>""" , <EOL> ) <EOL> p . add_argument ( <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> action = "<STR_LIT:store_true>" , <EOL> help = "<STR_LIT>" , <EOL> ) <EOL> p . add_argument ( <EOL> '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> help = """<STR_LIT>""" <EOL> ) <EOL> p . add_argument ( <EOL> '<STR_LIT>' , "<STR_LIT>" , <EOL> action = "<STR_LIT:store_true>" , <EOL> help = "<STR_LIT>" , <EOL> ) <EOL> p . add_argument ( <EOL> '<STR_LIT>' , <EOL> action = "<STR_LIT>" , <EOL> help = """<STR_LIT>""" % [ i for i in <EOL> PythonVersionCompleter ( ) if '<STR_LIT:.>' in i ] , <EOL> metavar = "<STR_LIT>" , <EOL> choices = PythonVersionCompleter ( ) , <EOL> ) <EOL> p . add_argument ( <EOL> '<STR_LIT>' , <EOL> action = "<STR_LIT>" , <EOL> help = """<STR_LIT>""" , <EOL> metavar = "<STR_LIT>" , <EOL> ) <EOL> p . add_argument ( <EOL> '<STR_LIT>' , <EOL> action = "<STR_LIT>" , <EOL> help = """<STR_LIT>""" % [ i for i in <EOL> NumPyVersionCompleter ( ) if '<STR_LIT:.>' in i ] , <EOL> metavar = "<STR_LIT>" , <EOL> choices = NumPyVersionCompleter ( ) , <EOL> ) <EOL> p . add_argument ( <EOL> '<STR_LIT>' , <EOL> action = "<STR_LIT>" , <EOL> help = """<STR_LIT>""" , <EOL> metavar = "<STR_LIT>" , <EOL> choices = RVersionsCompleter ( ) , <EOL> ) <EOL> p . add_argument ( <EOL> '<STR_LIT>' , <EOL> action = "<STR_LIT>" , <EOL> help = """<STR_LIT>""" % [ i for i in LuaVersionsCompleter ( ) ] , <EOL> metavar = "<STR_LIT>" , <EOL> choices = LuaVersionsCompleter ( ) , <EOL> ) <EOL> add_parser_channels ( p ) <EOL> p . set_defaults ( func = execute ) <EOL> args = p . parse_args ( ) <EOL> args_func ( args , p ) <EOL> def handle_binstar_upload ( path , args ) : <EOL> import subprocess <EOL> from conda_build . external import find_executable <EOL> if args . binstar_upload is None : <EOL> args . yes = False <EOL> args . dry_run = False <EOL> upload = False <EOL> else : <EOL> upload = args . binstar_upload <EOL> no_upload_message = """<STR_LIT>""" % path <EOL> if not upload : <EOL> print ( no_upload_message ) <EOL> return <EOL> binstar = find_executable ( '<STR_LIT>' ) <EOL> if binstar is None : <EOL> print ( no_upload_message ) <EOL> sys . exit ( '''<STR_LIT>''' ) <EOL> print ( "<STR_LIT>" ) <EOL> args = [ binstar , '<STR_LIT>' , path ] <EOL> try : <EOL> subprocess . call ( args ) <EOL> except : <EOL> print ( no_upload_message ) <EOL> raise <EOL> def check_external ( ) : <EOL> import os <EOL> import conda_build . external as external <EOL> if sys . platform . startswith ( '<STR_LIT>' ) : <EOL> patchelf = external . find_executable ( '<STR_LIT>' ) <EOL> if patchelf is None : <EOL> sys . exit ( """<STR_LIT>""" % ( os . pathsep . join ( external . dir_paths ) ) ) <EOL> def execute ( args , parser ) : <EOL> import sys <EOL> import shutil <EOL> import tarfile <EOL> import tempfile <EOL> from os import makedirs <EOL> from os . path import abspath , isdir , isfile <EOL> from conda . lock import Locked <EOL> import conda_build . build as build <EOL> import conda_build . source as source <EOL> from conda_build . config import config <EOL> from conda_build . metadata import MetaData <EOL> check_external ( ) <EOL> build . channel_urls = args . channel or ( ) <EOL> build . override_channels = args . override_channels <EOL> build . verbose = not args . quiet <EOL> if on_win : <EOL> try : <EOL> delete_trash ( None ) <EOL> except : <EOL> warnings . warn ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> conda_version = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:R>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> for lang in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:R>' , '<STR_LIT>' ] : <EOL> versions = getattr ( args , lang ) <EOL> if not versions : <EOL> continue <EOL> if versions == [ '<STR_LIT:all>' ] : <EOL> if all_versions [ lang ] : <EOL> versions = all_versions [ lang ] <EOL> else : <EOL> parser . error ( "<STR_LIT>" % lang ) <EOL> if len ( versions ) > <NUM_LIT:1> : <EOL> for ver in versions [ : ] : <EOL> setattr ( args , lang , [ str ( ver ) ] ) <EOL> execute ( args , parser ) <EOL> setattr ( args , lang , versions ) <EOL> return <EOL> else : <EOL> version = versions [ <NUM_LIT:0> ] <EOL> if lang in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> version = int ( version . replace ( '<STR_LIT:.>' , '<STR_LIT>' ) ) <EOL> setattr ( config , conda_version [ lang ] , version ) <EOL> if not len ( str ( version ) ) in ( <NUM_LIT:2> , <NUM_LIT:3> ) and lang in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> if all_versions [ lang ] : <EOL> raise RuntimeError ( "<STR_LIT>" % <EOL> ( conda_version [ lang ] , all_versions [ lang ] [ - <NUM_LIT:1> ] / <NUM_LIT:10> , version ) ) <EOL> else : <EOL> raise RuntimeError ( "<STR_LIT>" % <EOL> ( conda_version [ lang ] , version ) ) <EOL> for var in conda_version . values ( ) : <EOL> if getattr ( config , var ) : <EOL> os_environ [ var ] = str ( getattr ( config , var ) ) <EOL> if args . skip_existing : <EOL> for d in config . bldpkgs_dirs : <EOL> if not isdir ( d ) : <EOL> makedirs ( d ) <EOL> update_index ( d ) <EOL> index = build . get_build_index ( clear_cache = True ) <EOL> already_built = [ ] <EOL> to_build_recursive = [ ] <EOL> with Locked ( config . croot ) : <EOL> recipes = deque ( args . recipe ) <EOL> while recipes : <EOL> arg = recipes . popleft ( ) <EOL> try_again = False <EOL> if not PY3 : <EOL> arg = arg . decode ( getpreferredencoding ( ) or '<STR_LIT:utf-8>' ) <EOL> if isfile ( arg ) : <EOL> if arg . endswith ( ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) : <EOL> recipe_dir = tempfile . mkdtemp ( ) <EOL> t = tarfile . open ( arg , '<STR_LIT>' ) <EOL> t . extractall ( path = recipe_dir ) <EOL> t . close ( ) <EOL> need_cleanup = True <EOL> else : <EOL> print ( "<STR_LIT>" % arg ) <EOL> continue <EOL> else : <EOL> recipe_dir = abspath ( arg ) <EOL> need_cleanup = False <EOL> if not isdir ( recipe_dir ) : <EOL> sys . exit ( "<STR_LIT>" % recipe_dir ) <EOL> try : <EOL> m = MetaData ( recipe_dir ) <EOL> if m . get_value ( '<STR_LIT>' ) : <EOL> config . noarch = True <EOL> except exceptions . YamlParsingError as e : <EOL> sys . stderr . write ( e . error_msg ( ) ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> binstar_upload = False <EOL> if args . check and len ( args . recipe ) > <NUM_LIT:1> : <EOL> print ( m . path ) <EOL> m . check_fields ( ) <EOL> if args . check : <EOL> continue <EOL> if args . skip_existing : <EOL> if m . pkg_fn ( ) in index or m . pkg_fn ( ) in already_built : <EOL> print ( "<STR_LIT>" % m . dist ( ) ) <EOL> continue <EOL> if m . skip ( ) : <EOL> print ( "<STR_LIT>" <EOL> "<STR_LIT>" % m . dist ( ) ) <EOL> continue <EOL> if args . output : <EOL> try : <EOL> m . parse_again ( permit_undefined_jinja = False ) <EOL> except SystemExit : <EOL> source . provide ( m . path , m . get_section ( '<STR_LIT:source>' ) ) <EOL> m . parse_again ( permit_undefined_jinja = False ) <EOL> print ( build . bldpkg_path ( m ) ) <EOL> continue <EOL> elif args . test : <EOL> build . test ( m , move_broken = False ) <EOL> elif args . source : <EOL> source . provide ( m . path , m . get_section ( '<STR_LIT:source>' ) ) <EOL> print ( '<STR_LIT>' , source . get_dir ( ) ) <EOL> else : <EOL> if args . build_only : <EOL> post = False <EOL> args . notest = True <EOL> args . binstar_upload = False <EOL> elif args . post : <EOL> post = True <EOL> args . notest = True <EOL> args . binstar_upload = False <EOL> else : <EOL> post = None <EOL> try : <EOL> build . build ( m , post = post , <EOL> include_recipe = args . include_recipe ) <EOL> except ( NoPackagesFound , Unsatisfiable ) as e : <EOL> error_str = str ( e ) <EOL> skip_names = [ '<STR_LIT>' , '<STR_LIT:r>' ] <EOL> add_recipes = [ ] <EOL> for line in error_str . splitlines ( ) : <EOL> if not line . startswith ( '<STR_LIT>' ) : <EOL> continue <EOL> pkg = line . lstrip ( '<STR_LIT>' ) . split ( '<STR_LIT>' ) [ - <NUM_LIT:1> ] <EOL> pkg = pkg . strip ( ) . split ( '<STR_LIT:U+0020>' ) [ <NUM_LIT:0> ] <EOL> if pkg in skip_names : <EOL> continue <EOL> recipe_glob = glob ( pkg + '<STR_LIT>' ) <EOL> if exists ( pkg ) : <EOL> recipe_glob . append ( pkg ) <EOL> if recipe_glob : <EOL> try_again = True <EOL> for recipe_dir in recipe_glob : <EOL> if pkg in to_build_recursive : <EOL> sys . exit ( str ( e ) ) <EOL> print ( error_str ) <EOL> print ( ( "<STR_LIT>" + <EOL> "<STR_LIT>" + <EOL> "<STR_LIT>" ) . format ( pkg ) ) <EOL> add_recipes . append ( recipe_dir ) <EOL> to_build_recursive . append ( pkg ) <EOL> else : <EOL> raise <EOL> recipes . appendleft ( arg ) <EOL> recipes . extendleft ( reversed ( add_recipes ) ) <EOL> if try_again : <EOL> continue <EOL> if not args . notest : <EOL> build . test ( m ) <EOL> binstar_upload = True <EOL> if need_cleanup : <EOL> shutil . rmtree ( recipe_dir ) <EOL> if binstar_upload : <EOL> handle_binstar_upload ( build . bldpkg_path ( m ) , args ) <EOL> already_built . append ( m . pkg_fn ( ) ) <EOL> def args_func ( args , p ) : <EOL> try : <EOL> args . func ( args , p ) <EOL> except RuntimeError as e : <EOL> if '<STR_LIT>' in str ( e ) : <EOL> print_issue_message ( e ) <EOL> raise <EOL> sys . exit ( "<STR_LIT>" % e ) <EOL> except Exception as e : <EOL> print_issue_message ( e ) <EOL> raise <EOL> def print_issue_message ( e ) : <EOL> if e . __class__ . __name__ not in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> message = """<STR_LIT>""" <EOL> print ( message , file = sys . stderr ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
