def create_exports(build_data): """ Create a dict of environment variables for the build script """ conda_root_prefix = get_conda_root_prefix() build_item = build_data['build_item_info'] build = build_data['build_info'] api_site = build['api_endpoint'] exports = { # The build number as MAJOR.MINOR 'BINSTAR_BUILD': build_item['build_no'], 'BINSTAR_BUILD_MAJOR': build['build_no'], 'BINSTAR_BUILD_MINOR': build_item['sub_build_no'], # the engine from the engine tag 'BINSTAR_ENGINE': build_item.get('engine'), # the platform from the platform tag 'BINSTAR_PLATFORM': build_item.get('platform', 'linux-64'), 'BINSTAR_API_SITE': api_site, 'BINSTAR_OWNER': build_data['owner']['login'], 'BINSTAR_PACKAGE': build_data['package']['name'], 'BINSTAR_BUILD_ID': build['_id'], 'CONDA_BUILD_DIR': os.path.join(conda_root_prefix, 'conda-bld', build_item.get('platform', 'linux-64')), 'BUILD_BASE': 'builds', 'BUILD_ENV_DIR': 'build_envs', } build_env = build_item.get('env') if isinstance(build_env, (str, unicode)): _build_env = {} for item in shlex.split(build_env): if '=' in item: key, value = item.split('=', 1) _build_env[key] = value build_env = _build_env if isinstance(build_env, dict): exports.update(build_env) return exports
def main(): parser = ArgumentParser(description=__doc__) parser.parse_args() root_env = get_conda_root_prefix() build_root = os.path.join(root_env, 'conda-bld') if os.path.isdir(build_root): print("Removing conda build root %s" % build_root) rm_rf(build_root) else: print("Conda build root %s does not exist" % build_root)
def add_parser(subparsers, name='worker', description='Run a build worker to build jobs off of a binstar build queue', epilog=__doc__): parser = subparsers.add_parser(name, help=description, description=description, epilog=epilog ) conda_platform = get_platform() parser.add_argument('queue', metavar='OWNER/QUEUE', help='The queue to pull builds from') parser.add_argument('-p', '--platform', default=conda_platform, help='The platform this worker is running on (default: %(default)s)') parser.add_argument('--hostname', default=platform.node(), help='The host name the worker should use (default: %(default)s)') parser.add_argument('--dist', default=get_dist(), help='The operating system distribution the worker should use (default: %(default)s)') parser.add_argument('--cwd', default='.', help='The root directory this build should use (default: "%(default)s")') parser.add_argument('-t', '--max-job-duration', type=int, metavar='SECONDS', dest='timeout', help='Force jobs to stop after they exceed duration (default: %(default)s)', default=60 * 60 * 60) dgroup = parser.add_argument_group('development options') dgroup.add_argument("--conda-build-dir", default=os.path.join(get_conda_root_prefix(), 'conda-bld', '{args.platform}'), help="[Advanced] The conda build directory (default: %(default)s)", ) dgroup.add_argument('--show-new-procs', action='store_true', dest='show_new_procs', help='Print any process that started during the build ' 'and is still running after the build finished') dgroup.add_argument('-c', '--clean', action='store_true', help='Clean up an existing workers session') dgroup.add_argument('-f', '--fail', action='store_true', help='Exit main loop on any un-handled exception') dgroup.add_argument('-1', '--one', action='store_true', help='Exit main loop after only one build') dgroup.add_argument('--push-back', action='store_true', help='Developers only, always push the build *back* onto the build queue') dgroup.add_argument('--status-file', help='If given, binstar will update this file with the time it last checked the anaconda server for updates') parser.set_defaults(main=main) return parser
def test_finds_conda(self, listdir, isdir): def list_dir(dirname): print("dirname", dirname) if dirname == '/a/bin': return [CONDA_EXE, 'not_conda'] else: return ['not_conda'] listdir.side_effect = list_dir prefix = get_conda_root_prefix() self.assertTrue(prefix in ('/a', "C:\\a"))
def create_exports(build_data, working_dir): """ Create a dict of environment variables for the build script """ conda_root_prefix = get_conda_root_prefix() build_item = build_data['build_item_info'] build = build_data['build_info'] api_site = build['api_endpoint'] engine = build_item.get('engine') CONDA_NPY = '' if 'numpy' in engine: npy_version = engine.split('numpy')[1].split() if npy_version: CONDA_NPY = "".join(npy_version[0].split('.')[:2]) CONDA_NPY = CONDA_NPY.replace('=', '') exports = { # The build number as MAJOR.MINOR 'BINSTAR_BUILD': build_item['build_no'], 'BINSTAR_BUILD_MAJOR': build['build_no'], 'BINSTAR_BUILD_MINOR': build_item['sub_build_no'], # the engine from the engine tag 'BINSTAR_ENGINE': engine, # the platform from the platform tag 'BINSTAR_PLATFORM': build_item.get('platform', 'linux-64'), 'BINSTAR_API_SITE': api_site, 'BINSTAR_OWNER': build_data['owner']['login'], 'BINSTAR_PACKAGE': build_data['package']['name'], 'BINSTAR_BUILD_ID': build['_id'], 'CONDA_BUILD_DIR': os.path.join(conda_root_prefix, 'conda-bld', build_item.get('platform', 'linux-64')), 'WORKING_DIR': working_dir, 'CONDA_NPY': CONDA_NPY, } build_env = build_item.get('envvars', build_item.get('env')) if isinstance(build_env, (str, unicode)): _build_env = {} for item in shlex.split(build_env): if '=' in item: key, value = item.split('=', 1) _build_env[key] = value build_env = _build_env if isinstance(build_env, dict): exports.update(build_env) return exports
def main(): parser = ArgumentParser(description=__doc__) parser.parse_args() root_env = get_conda_root_prefix() build_root = os.path.join(root_env, 'conda-bld') has_access = os.access(build_root, os.W_OK) if not has_access: build_root = os.path.join(os.path.expanduser('~'), 'conda-bld') if os.path.isdir(build_root): print("Removing conda build root {}".format(build_root)) rm_rf(build_root) else: print("Conda build root {} does not exist".format(build_root))
def add_parser(subparsers, name='run', description='Run a build worker to build jobs off of a binstar build queue', epilog=__doc__, default_func=main): parser = subparsers.add_parser(name, help=description, description=description, epilog=epilog ) parser.add_argument('worker_id', help="worker_id that was given in anaconda build register") parser.add_argument('-f', '--fail', action='store_true', help='Exit main loop on any un-handled exception') parser.add_argument('-1', '--one', action='store_true', help='Exit main loop after only one build') parser.add_argument('--push-back', action='store_true', help='Developers only, always push the build *back* ' + \ 'onto the build queue') dgroup = parser.add_argument_group('development options') conda_prefix = get_conda_root_prefix() if conda_prefix: default_build_dir = os.path.join(conda_prefix, 'conda-bld', '{platform}') else: default_build_dir = None dgroup.add_argument("--conda-build-dir", default=default_build_dir, help="[Advanced] The conda build directory (default: %(default)s)", ) dgroup.add_argument('--show-new-procs', action='store_true', dest='show_new_procs', help='Print any process that started during the build ' 'and is still running after the build finished') dgroup.add_argument('--status-file', help='If given, binstar will update this file with the ' + \ 'time it last checked the anaconda server for updates') parser.add_argument('--cwd', default=os.path.abspath('.'), type=os.path.abspath, help='The root directory this build should use (default: "%(default)s")') parser.add_argument('-t', '--max-job-duration', type=int, metavar='SECONDS', dest='timeout', help='Force jobs to stop after they exceed duration (default: %(default)s)', default=60 * 60) parser.set_defaults(main=default_func) return parser
def add_parser( subparsers, name='run', description='Run a build worker to build jobs off of a binstar build queue', epilog=__doc__, default_func=main): parser = subparsers.add_parser(name, help=description, description=description, epilog=epilog) parser.add_argument( 'worker_id', help="worker_id that was given in anaconda build register") parser.add_argument('-f', '--fail', action='store_true', help='Exit main loop on any un-handled exception') parser.add_argument('-1', '--one', action='store_true', help='Exit main loop after only one build') parser.add_argument('--push-back', action='store_true', help='Developers only, always push the build *back* ' + \ 'onto the build queue') dgroup = parser.add_argument_group('development options') conda_prefix = get_conda_root_prefix() if conda_prefix: default_build_dir = os.path.join(conda_prefix, 'conda-bld', '{platform}') else: default_build_dir = None dgroup.add_argument( "--conda-build-dir", default=default_build_dir, help="[Advanced] The conda build directory (default: %(default)s)", ) dgroup.add_argument('--show-new-procs', action='store_true', dest='show_new_procs', help='Print any process that started during the build ' 'and is still running after the build finished') dgroup.add_argument('--status-file', help='If given, binstar will update this file with the ' + \ 'time it last checked the anaconda server for updates') parser.add_argument( '--cwd', default=os.path.abspath('.'), type=os.path.abspath, help='The root directory this build should use (default: "%(default)s")' ) parser.add_argument( '-t', '--max-job-duration', type=int, metavar='SECONDS', dest='timeout', help= 'Force jobs to stop after they exceed duration (default: %(default)s)', default=60 * 60) parser.set_defaults(main=default_func) return parser
def add_parser( subparsers, name='worker', description='Run a build worker to build jobs off of a binstar build queue', epilog=__doc__): parser = subparsers.add_parser(name, help=description, description=description, epilog=epilog) conda_platform = get_platform() parser.add_argument('queue', metavar='OWNER/QUEUE', help='The queue to pull builds from') parser.add_argument( '-p', '--platform', default=conda_platform, help='The platform this worker is running on (default: %(default)s)') parser.add_argument( '--hostname', default=platform.node(), help='The host name the worker should use (default: %(default)s)') parser.add_argument( '--dist', default=get_dist(), help= 'The operating system distribution the worker should use (default: %(default)s)' ) parser.add_argument( '--cwd', default='.', help='The root directory this build should use (default: "%(default)s")' ) parser.add_argument( '-t', '--max-job-duration', type=int, metavar='SECONDS', dest='timeout', help= 'Force jobs to stop after they exceed duration (default: %(default)s)', default=60 * 60 * 60) dgroup = parser.add_argument_group('development options') dgroup.add_argument( "--conda-build-dir", default=os.path.join(get_conda_root_prefix(), 'conda-bld', '{args.platform}'), help="[Advanced] The conda build directory (default: %(default)s)", ) dgroup.add_argument('--show-new-procs', action='store_true', dest='show_new_procs', help='Print any process that started during the build ' 'and is still running after the build finished') dgroup.add_argument('-c', '--clean', action='store_true', help='Clean up an existing workers session') dgroup.add_argument('-f', '--fail', action='store_true', help='Exit main loop on any un-handled exception') dgroup.add_argument('-1', '--one', action='store_true', help='Exit main loop after only one build') dgroup.add_argument( '--push-back', action='store_true', help= 'Developers only, always push the build *back* onto the build queue') parser.set_defaults(main=main) return parser
def test_finds_conda(self, listdir, isdir): listdir.return_value = [CONDA_EXE, 'not_conda'] prefix = get_conda_root_prefix() self.assertEqual(prefix, '/a')
def test_path_does_not_exist(self): prefix = get_conda_root_prefix() self.assertIsNone(prefix)
def test_path_does_not_exist(self, listdir): listdir.return_value = [] prefix = get_conda_root_prefix() self.assertIsNone(prefix)