def test_get_repo_git_tag_options(mocker, capsys): ''' Test for `_get_repo` that verifies `git_tag` and `git_tag_for_env` priorities. ''' env_file1 = os.path.join(test_dir, 'test-env1.yaml') mock_build_tree = TestBuildTree([env_file1], "3.6", "cpu", "openmpi", "10.2") dir_tracker = helpers.DirTracker() mocker.patch('os.getcwd', side_effect=dir_tracker.mocked_getcwd) mocker.patch('os.chdir', side_effect=dir_tracker.validate_chdir) mocker.patch('os.system', return_value=0, side_effect=(lambda x: helpers.validate_cli( x, possible_expect=["git clone", "git checkout"]))) possible_variants = utils.make_variants("3.6", "cpu", "openmpi", "10.2") for variant in possible_variants: # test-env1.yaml has defined "git_tag" and "git_tag_for_env". env_config_data_list = env_config.load_env_config_files([env_file1], variant) for env_config_data in env_config_data_list: packages = env_config_data.get(env_config.Key.packages.name, []) for package in packages: _, _ = mock_build_tree._get_repo(env_config_data, package) validate_git_tags(mock_build_tree._git_tag_for_env, env_config_data, package, capsys) # Setting git_tag_for_env in BuildTree should override whatever is in the config file mock_build_tree._git_tag_for_env = "test_tag_for_all" env_config_data_list = env_config.load_env_config_files([env_file1], variant) for env_config_data in env_config_data_list: packages = env_config_data.get(env_config.Key.packages.name, []) for package in packages: _, _ = mock_build_tree._get_repo(env_config_data, package) validate_git_tags(mock_build_tree._git_tag_for_env, env_config_data, package, capsys) # Setting git_tag_for_env in BuildTree back to Default and no git tags # specified in the config file too. mocker.patch('os.system', return_value=0, side_effect=(lambda x: helpers.validate_cli( x, possible_expect=["git clone", "git apply"], reject=["git checkout"]))) mock_build_tree._git_tag_for_env = None env_file2 = os.path.join(test_dir, 'test-env3.yaml') env_config_data_list = env_config.load_env_config_files([env_file2], variant) for env_config_data in env_config_data_list: packages = env_config_data.get(env_config.Key.packages.name, []) for package in packages: _, _ = mock_build_tree._get_repo(env_config_data, package) validate_git_tags(mock_build_tree._git_tag_for_env, env_config_data, package, capsys)
def validate_env(args): '''Entry Function''' variants = utils.make_variants(args.python_versions, args.build_types, args.mpi_types) for variant in variants: try: env_config.load_env_config_files(args.env_config_file, variant) except OpenCEError as exc: raise OpenCEError(Error.VALIDATE_ENV, args.env_config_file, str(variant), exc.msg) from exc
def validate_env(arg_strings=None): ''' Entry function. ''' parser = make_parser() args = parser.parse_args(arg_strings) variants = utils.make_variants(args.python_versions, args.build_types, args.mpi_types) for variant in variants: try: env_config.load_env_config_files(args.env_config_file, variant) except OpenCEError as exc: raise OpenCEError(Error.VALIDATE_ENV, args.env_config_file, str(variant), exc.msg) from exc
def _create_all_recipes(self, variants): #pylint: disable=too-many-branches ''' Create a recipe dictionary for each recipe needed for a given environment file. ''' env_config_data_list = env_config.load_env_config_files( self._env_config_files, variants) packages_seen = set() recipes = [] external_deps = [] # Create recipe dictionaries for each repository in the environment file for env_config_data in env_config_data_list: packages = env_config_data.get(env_config.Key.packages.name, []) if not packages: packages = [] for package in packages: if _make_hash(package) in packages_seen: continue # If the feedstock value starts with any of the SUPPORTED_GIT_PROTOCOLS, treat it as a url. Otherwise # combine with git_location and append "-feedstock.git" feedstock_value = package[env_config.Key.feedstock.name] if any( feedstock_value.startswith(protocol) for protocol in utils.SUPPORTED_GIT_PROTOCOLS): git_url = feedstock_value if not git_url.endswith(".git"): git_url += ".git" repository = os.path.splitext(os.path.basename(git_url))[0] else: git_url = "{}/{}-feedstock.git".format( self._git_location, feedstock_value) repository = feedstock_value + "-feedstock" # Check if the directory for the feedstock already exists. # If it doesn't attempt to clone the repository. if self._repository_folder: repo_dir = os.path.join(self._repository_folder, repository) else: repo_dir = repository if not os.path.exists(repo_dir): self._clone_repo(git_url, repo_dir, env_config_data, package.get('git_tag')) recipes += _create_recipes( repo_dir, package.get('recipes'), [os.path.abspath(self._conda_build_config)], variants, env_config_data.get(env_config.Key.channels.name, None)) packages_seen.add(_make_hash(package)) current_deps = env_config_data.get( env_config.Key.external_dependencies.name, []) if current_deps: external_deps += current_deps return recipes, external_deps
def test_get_repo_for_nonexisting_patch(mocker): ''' Test for `_get_repo` that verifies exception is thrown when patch application fails ''' env_file = os.path.join(test_dir, 'test-env3.yaml') mock_build_tree = TestBuildTree([env_file], "3.6", "cpu", "openmpi", "10.2") dir_tracker = helpers.DirTracker() mocker.patch('os.getcwd', side_effect=dir_tracker.mocked_getcwd) mocker.patch('os.chdir', side_effect=dir_tracker.validate_chdir) mocker.patch('os.system', side_effect=(lambda x: helpers.validate_cli( x, expect=["git apply"], ignore=["git clone", "git checkout"], retval=1))) possible_variants = utils.make_variants("3.6", "cpu", "openmpi", "10.2") for variant in possible_variants: # test-env3.yaml has defined "patches". env_config_data_list = env_config.load_env_config_files([env_file], variant) for env_config_data in env_config_data_list: packages = env_config_data.get(env_config.Key.packages.name, []) for package in packages: # "package211" has specified a non-existing patch if package.get(env_config.Key.feedstock.name) == "package211": with pytest.raises(OpenCEError) as exc: _, _ = mock_build_tree._get_repo( env_config_data, package) assert "Failed to apply patch " in str(exc.value)
def test_get_repo_with_patches(mocker, capsys): ''' Test for `_get_repo` that verifies `patches` field ''' env_file = os.path.join(test_dir, 'test-env3.yaml') mock_build_tree = TestBuildTree([env_file], "3.6", "cpu", "openmpi", "10.2") dir_tracker = helpers.DirTracker() mocker.patch('os.getcwd', side_effect=dir_tracker.mocked_getcwd) mocker.patch('os.chdir', side_effect=dir_tracker.validate_chdir) mocker.patch( 'os.system', return_value=0, side_effect=(lambda x: helpers.validate_cli( x, expect=["git apply"], ignore=["git clone", "git checkout"]))) possible_variants = utils.make_variants("3.6", "cpu", "openmpi", "10.2") for variant in possible_variants: # test-env3.yaml has specified "patches". env_config_data_list = env_config.load_env_config_files([env_file], variant) for env_config_data in env_config_data_list: packages = env_config_data.get(env_config.Key.packages.name, []) for package in packages: # "package211" has specified a non-existing patch if package.get(env_config.Key.feedstock.name) != "package211": _, _ = mock_build_tree._get_repo(env_config_data, package) captured = capsys.readouterr() assert "Patch apply command: git apply" in captured.out
def validate_env(arg_strings=None): ''' Entry function. ''' parser = make_parser() args = parser.parse_args(arg_strings) variants = { 'python': utils.parse_arg_list(args.python_versions), 'build_type': utils.parse_arg_list(args.build_types) } retval, _ = env_config.load_env_config_files(args.env_config_file, variants) return retval
def validate_env(arg_strings=None): ''' Entry function. ''' parser = make_parser() args = parser.parse_args(arg_strings) variants = [{ 'python': py_vers, 'build_type': build_type } for py_vers in utils.parse_arg_list(args.python_versions) for build_type in utils.parse_arg_list(args.build_types)] retval = 0 for variant in variants: result, _ = env_config.load_env_config_files(args.env_config_file, variant) retval += result return retval
def _create_all_recipes(self, variants): ''' Create a recipe dictionary for each recipe needed for a given environment file. ''' result, env_config_data_list = env_config.load_env_config_files( self._env_config_files, variants) if result != 0: return result, [] packages_seen = set() recipes = [] # Create recipe dictionaries for each repository in the environment file for env_config_data in env_config_data_list: packages = env_config_data.get('packages', []) if not packages: packages = [] for package in packages: if _make_hash(package) in packages_seen: continue # Check if the directory for the feedstock already exists. # If it doesn't attempt to clone the repository. repository = package['feedstock'] + "-feedstock" if self._repository_folder: repo_dir = os.path.join(self._repository_folder, repository) else: repo_dir = repository if not os.path.exists(repo_dir): result = self._clone_repo(repo_dir, env_config_data, package.get('git_tag')) if result != 0: return result, [] recipes += _create_recipes( repo_dir, package.get('recipes'), [os.path.abspath(self._conda_build_config)], variants, env_config_data.get('channels', None)) packages_seen.add(_make_hash(package)) return result, recipes
def _create_all_commands(self, variants): ''' Create a recipe dictionary for each recipe needed for a given environment file. ''' env_config_data_list = env_config.load_env_config_files( self._env_config_files, variants) packages_seen = set() build_commands = [] external_deps = [] test_commands = dict() # Create recipe dictionaries for each repository in the environment file for env_config_data in env_config_data_list: packages = env_config_data.get(env_config.Key.packages.name, []) if not packages: packages = [] for package in packages: if _make_hash(package) in packages_seen: continue repository, repo_dir = self._get_repo(env_config_data, package) runtime_package = package.get( env_config.Key.packages.runtime_package.name, True) repo_build_commands, repo_test_commands = _create_commands( repo_dir, runtime_package, package.get('recipes'), [os.path.abspath(self._conda_build_config)], variants, env_config_data.get(env_config.Key.channels.name, None), self._test_labels) build_commands += repo_build_commands if repo_test_commands and not repository in self._test_commands: test_commands[repository] = repo_test_commands packages_seen.add(_make_hash(package)) current_deps = env_config_data.get( env_config.Key.external_dependencies.name, []) if current_deps: external_deps += current_deps return build_commands, external_deps, test_commands