def handle_requires(requires): pypi_pkgs = [] git_repos = [] for require in requires: if isinstance(require, dict): require_type = require.get(constants.REQUIRE_TYPE, "") if require_type.upper() == constants.GIT_REQUIRE: git_repos.append( GitRequire( git_url=require.get(constants.GIT_URL), branch=require.get(constants.GIT_BRANCH), submodule=require.get( constants.GIT_HAS_SUBMODULE, False ), ) ) elif require_type.upper() == constants.PYPI_REQUIRE: pypi_pkgs.append(require.get(constants.PYPI_PACKAGE_NAME)) else: if is_repo(require): git_repos.append(GitRequire(require)) else: pypi_pkgs.append(require) if pypi_pkgs: pip_install(pypi_pkgs) if git_repos: git_clone(git_repos)
def test_git_clone(fake_check_all): from moban.utils import git_clone git_clone(["https://github.com/my/repo", "https://gitlab.com/my/repo"]) fake_check_all.assert_called_with( ["git", "clone", "https://gitlab.com/my/repo", "repo"] )
def test_git_update_with_submodules(self, fake_repo, local_folder_exists, *_): local_folder_exists.return_value = True git_clone([self.require_with_submodule]) fake_repo.assert_called_with(self.expected_local_repo_path) repo = fake_repo.return_value repo.git.submodule.assert_called_with("update")
def handle_requires(requires): pypi_pkgs = [] git_repos = [] git_repos_with_sub = [] for require in requires: if isinstance(require, dict): require_type = require.get(constants.REQUIRE_TYPE, "") if require_type.upper() == constants.GIT_REQUIRE: submodule_flag = require.get(constants.GIT_HAS_SUBMODULE) if submodule_flag is True: git_repos_with_sub.append(require.get(constants.GIT_URL)) else: git_repos.append(require.get(constants.GIT_URL)) elif require_type.upper() == constants.PYPI_REQUIRE: pypi_pkgs.append(require.get(constants.PYPI_PACKAGE_NAME)) else: if is_repo(require): git_repos.append(require) else: pypi_pkgs.append(require) if pypi_pkgs: pip_install(pypi_pkgs) if git_repos: git_clone(git_repos) if git_repos_with_sub: git_clone(git_repos_with_sub, submodule=True)
def test_git_clone_with_existing_repo(fake_check_all, _, __): from moban.utils import git_clone git_clone( ["https://github.com/my/repo", "https://gitlab.com/my/repo"], submodule=True, ) fake_check_all.assert_called_with(["git", "submodule", "update"])
def test_checkout_new(self, fake_repo, local_folder_exists, *_): local_folder_exists.return_value = False git_clone([self.require]) fake_repo.clone_from.assert_called_with(self.repo, self.expected_local_repo_path, single_branch=True) repo = fake_repo.return_value eq_(repo.git.submodule.called, False)
def test_checkout_new_with_submodules(self, fake_repo, local_folder_exists, *_): local_folder_exists.return_value = False git_clone([self.require_with_submodule]) fake_repo.clone_from.assert_called_with(self.repo, self.expected_local_repo_path, single_branch=True) repo = fake_repo.clone_from.return_value repo.git.submodule.assert_called_with("update", "--init")
def test_git_update(self, fake_repo, local_folder_exists, *_): local_folder_exists.return_value = True git_clone([self.require]) fake_repo.assert_called_with(self.expected_local_repo_path) repo = fake_repo.return_value repo.git.pull.assert_called()