def _get_repo_version(repo_path, variants, variant_config_files=None): ''' Get the version of the first package that appears in the recipes list for the feedstock. ''' saved_working_directory = os.getcwd() os.chdir(os.path.abspath(repo_path)) for variant in variants: build_config_data, _ = build_feedstock.load_package_config( variants=variant, permit_undefined_jinja=True) if build_config_data["recipes"]: for recipe in build_config_data["recipes"]: rendered_recipe = conda_utils.render_yaml( recipe["path"], variants=variant, variant_config_files=variant_config_files, permit_undefined_jinja=True) for meta, _, _ in rendered_recipe: package_version = meta.meta['package']['version'] if package_version and package_version != "None": os.chdir(saved_working_directory) return package_version, meta.meta['package']['name'] os.chdir(saved_working_directory) raise Exception( "Error: Unable to determine current version of the feedstock")
def _get_package_dependencies(path, variant_config_files, variants): """ Return a list of output packages and a list of dependency packages for the recipe at a given path. Uses conda-render to determine this information. """ #pylint: disable=import-outside-toplevel from open_ce import conda_utils metas = conda_utils.render_yaml(path, variants, variant_config_files) # Parse out the package names and dependencies from each variant packages = [] versions = [] run_deps = set() host_deps = set() build_deps = set() test_deps = set() output_files = [] for meta, _, _ in metas: packages.append(_clean_dep(meta.meta['package']['name'])) versions.append(meta.meta['package']['version']) run_deps.update(_clean_deps(meta.meta['requirements'].get('run', []))) host_deps.update(_clean_deps(meta.meta['requirements'].get('host', []))) build_deps.update( _clean_deps(meta.meta['requirements'].get('build', []))) output_files += conda_utils.get_output_file_paths(meta, variants=variants) if 'test' in meta.meta: test_deps.update(_clean_deps(meta.meta['test'].get('requires', []))) return packages, versions, run_deps, host_deps, build_deps, test_deps, output_files
def load_package_config(config_file=None, variants=None, recipe_path=None): ''' Check for a config file. If the user does not provide a recipe config file as an argument, it will be assumed that there is only one recipe to build, and it is in the directory called 'recipe'. ''' # pylint: disable=import-outside-toplevel from open_ce import conda_utils if recipe_path: recipe_name = os.path.basename(os.getcwd()) build_config_data = { 'recipes': [{ 'name': recipe_name, 'path': recipe_path }] } elif not config_file and not os.path.exists( utils.DEFAULT_RECIPE_CONFIG_FILE): recipe_name = os.path.basename(os.getcwd()) build_config_data = { 'recipes': [{ 'name': recipe_name, 'path': 'recipe' }] } else: if not config_file: config_file = utils.DEFAULT_RECIPE_CONFIG_FILE if not os.path.exists(config_file): raise OpenCEError(Error.CONFIG_FILE, config_file) build_config_data = conda_utils.render_yaml(config_file, variants) return build_config_data, config_file
def _validate_config_file(env_file, variants): '''Perform some validation on the environment file after loading it.''' # pylint: disable=import-outside-toplevel from open_ce import conda_utils try: if utils.is_url(env_file): env_file = utils.download_file(env_file) # First, partially render yaml to validate builder version number. version_check_obj = conda_utils.render_yaml( env_file, permit_undefined_jinja=True) if Key.builder_version.name in version_check_obj.keys(): if not conda_utils.version_matches_spec( version_check_obj.get(Key.builder_version.name)): raise OpenCEError( Error.SCHEMA_VERSION_MISMATCH, env_file, version_check_obj.get(Key.builder_version.name), open_ce_version) meta_obj = None try: meta_obj = conda_utils.render_yaml(env_file, variants=variants, schema=_ENV_CONFIG_SCHEMA) if not (Key.packages.name in meta_obj.keys() or Key.imported_envs.name in meta_obj.keys()): raise OpenCEError(Error.CONFIG_CONTENT) meta_obj[Key.opence_env_file_path.name] = env_file except OpenCEError as exc: if Key.builder_version.name not in version_check_obj.keys(): show_warning(Error.SCHEMA_VERSION_NOT_FOUND, env_file, Key.builder_version.name) raise exc return meta_obj except (Exception, SystemExit) as exc: #pylint: disable=broad-except raise OpenCEError(Error.ERROR, "Error in {}:\n {}".format(env_file, str(exc))) from exc
def _get_git_tag_from_env_file(env_file): ''' The way this function copies the env_file to a new location before it reads the env file is to get around an issue with the python jinja library used by conda build which seems to cache the file the first time it is read, even if the file is changed by checking out a new git commit. ''' with open(env_file, mode='r') as file: file_contents = file.read() with tempfile.NamedTemporaryFile(suffix=os.path.basename(env_file), delete=True, mode='w') as renamed_env_file: renamed_env_file.write(file_contents) renamed_env_file.flush() rendered_env_file = render_yaml(renamed_env_file.name, permit_undefined_jinja=True) return rendered_env_file.get(env_config.Key.git_tag_for_env.name, None)
def load_test_file(test_file, variants): """ Load a given test file. Args: test_file (str): Path to the test file to load. """ #pylint: disable=import-outside-toplevel from open_ce import conda_utils if not os.path.exists(test_file): return None test_file_data = conda_utils.render_yaml(test_file, variants, permit_undefined_jinja=True, schema=_TEST_FILE_SCHEMA) return test_file_data
def _validate_config_file(env_file, variants): '''Perform some validation on the environment file after loading it.''' # pylint: disable=import-outside-toplevel from open_ce import conda_utils try: if utils.is_url(env_file): env_file = utils.download_file(env_file) meta_obj = conda_utils.render_yaml(env_file, variants=variants, schema=_ENV_CONFIG_SCHEMA) if not (Key.packages.name in meta_obj.keys() or Key.imported_envs.name in meta_obj.keys()): raise OpenCEError(Error.CONFIG_CONTENT) meta_obj[Key.opence_env_file_path.name] = env_file return meta_obj except (Exception, SystemExit) as exc: #pylint: disable=broad-except raise OpenCEError(Error.ERROR, "Error in {}:\n {}".format(env_file, str(exc))) from exc
def _get_repo_version(repo_path): ''' Get the version of the first package that appears in the recipes list for the feedstock. ''' saved_working_directory = os.getcwd() os.chdir(os.path.abspath(repo_path)) build_config_data, _ = build_feedstock.load_package_config() for recipe in build_config_data["recipes"]: rendered_recipe = conda_utils.render_yaml(recipe["path"]) for meta, _, _ in rendered_recipe: package_version = meta.meta['package']['version'] if package_version and package_version != "None": os.chdir(saved_working_directory) return package_version os.chdir(saved_working_directory) raise Exception( "Error: Unable to determine current version of the feedstock")