def test_download_repo(self): """Test download_repo function.""" # default: download tarball for master branch of hpcugent/easybuild-easyconfigs repo path = gh.download_repo(path=self.test_prefix) repodir = os.path.join(self.test_prefix, 'hpcugent', 'easybuild-easyconfigs-master') self.assertTrue(os.path.samefile(path, repodir)) self.assertTrue(os.path.exists(repodir)) shafile = os.path.join(repodir, 'latest-sha') self.assertTrue(re.match('^[0-9a-f]{40}$', read_file(shafile))) self.assertTrue(os.path.exists(os.path.join(repodir, 'easybuild', 'easyconfigs', 'f', 'foss', 'foss-2015a.eb'))) # existing downloaded repo is not reperformed, except if SHA is different account, repo, branch = 'boegel', 'easybuild-easyblocks', 'develop' repodir = os.path.join(self.test_prefix, account, '%s-%s' % (repo, branch)) latest_sha = gh.fetch_latest_commit_sha(repo, account, branch=branch) # put 'latest-sha' fail in place, check whether repo was (re)downloaded (should not) shafile = os.path.join(repodir, 'latest-sha') write_file(shafile, latest_sha) path = gh.download_repo(repo=repo, branch=branch, account=account, path=self.test_prefix) self.assertTrue(os.path.samefile(path, repodir)) self.assertEqual(os.listdir(repodir), ['latest-sha']) # remove 'latest-sha' file and verify that download was performed os.remove(shafile) path = gh.download_repo(repo=repo, branch=branch, account=account, path=self.test_prefix) self.assertTrue(os.path.samefile(path, repodir)) self.assertTrue('easybuild' in os.listdir(repodir)) self.assertTrue(re.match('^[0-9a-f]{40}$', read_file(shafile))) self.assertTrue(os.path.exists(os.path.join(repodir, 'easybuild', 'easyblocks', '__init__.py')))
def test_download_repo(self): """Test download_repo function.""" if self.github_token is None: print "Skipping test_download_repo, no GitHub token available?" return # default: download tarball for master branch of hpcugent/easybuild-easyconfigs repo path = gh.download_repo(path=self.test_prefix) repodir = os.path.join(self.test_prefix, 'hpcugent', 'easybuild-easyconfigs-master') self.assertTrue(os.path.samefile(path, repodir)) self.assertTrue(os.path.exists(repodir)) shafile = os.path.join(repodir, 'latest-sha') self.assertTrue(re.match('^[0-9a-f]{40}$', read_file(shafile))) self.assertTrue(os.path.exists(os.path.join(repodir, 'easybuild', 'easyconfigs', 'f', 'foss', 'foss-2015a.eb'))) # existing downloaded repo is not reperformed, except if SHA is different account, repo, branch = 'boegel', 'easybuild-easyblocks', 'develop' repodir = os.path.join(self.test_prefix, account, '%s-%s' % (repo, branch)) latest_sha = gh.fetch_latest_commit_sha(repo, account, branch=branch) # put 'latest-sha' fail in place, check whether repo was (re)downloaded (should not) shafile = os.path.join(repodir, 'latest-sha') write_file(shafile, latest_sha) path = gh.download_repo(repo=repo, branch=branch, account=account, path=self.test_prefix) self.assertTrue(os.path.samefile(path, repodir)) self.assertEqual(os.listdir(repodir), ['latest-sha']) # remove 'latest-sha' file and verify that download was performed os.remove(shafile) path = gh.download_repo(repo=repo, branch=branch, account=account, path=self.test_prefix) self.assertTrue(os.path.samefile(path, repodir)) self.assertTrue('easybuild' in os.listdir(repodir)) self.assertTrue(re.match('^[0-9a-f]{40}$', read_file(shafile))) self.assertTrue(os.path.exists(os.path.join(repodir, 'easybuild', 'easyblocks', '__init__.py')))
def test_download_repo(self): """Test download_repo function.""" if self.skip_github_tests: print("Skipping test_download_repo, no GitHub token available?") return cwd = os.getcwd() # default: download tarball for master branch of easybuilders/easybuild-easyconfigs repo path = gh.download_repo(path=self.test_prefix, github_user=GITHUB_TEST_ACCOUNT) repodir = os.path.join(self.test_prefix, 'easybuilders', 'easybuild-easyconfigs-master') self.assertTrue(os.path.samefile(path, repodir)) self.assertTrue(os.path.exists(repodir)) shafile = os.path.join(repodir, 'latest-sha') self.assertTrue(re.match('^[0-9a-f]{40}$', read_file(shafile))) self.assertTrue( os.path.exists( os.path.join(repodir, 'easybuild', 'easyconfigs', 'f', 'foss', 'foss-2019b.eb'))) # current directory should not have changed after calling download_repo self.assertTrue(os.path.samefile(cwd, os.getcwd())) # existing downloaded repo is not reperformed, except if SHA is different account, repo, branch = 'boegel', 'easybuild-easyblocks', 'develop' repodir = os.path.join(self.test_prefix, account, '%s-%s' % (repo, branch)) latest_sha = gh.fetch_latest_commit_sha( repo, account, branch=branch, github_user=GITHUB_TEST_ACCOUNT) # put 'latest-sha' fail in place, check whether repo was (re)downloaded (should not) shafile = os.path.join(repodir, 'latest-sha') write_file(shafile, latest_sha) path = gh.download_repo(repo=repo, branch=branch, account=account, path=self.test_prefix, github_user=GITHUB_TEST_ACCOUNT) self.assertTrue(os.path.samefile(path, repodir)) self.assertEqual(os.listdir(repodir), ['latest-sha']) # remove 'latest-sha' file and verify that download was performed os.remove(shafile) path = gh.download_repo(repo=repo, branch=branch, account=account, path=self.test_prefix, github_user=GITHUB_TEST_ACCOUNT) self.assertTrue(os.path.samefile(path, repodir)) self.assertTrue('easybuild' in os.listdir(repodir)) self.assertTrue(re.match('^[0-9a-f]{40}$', read_file(shafile))) self.assertTrue( os.path.exists( os.path.join(repodir, 'easybuild', 'easyblocks', '__init__.py')))
def review_pr(pr, colored=True, branch='develop'): """ Print multi-diff overview between easyconfigs in specified PR and specified branch. :param pr: pull request number in easybuild-easyconfigs repo to review :param colored: boolean indicating whether a colored multi-diff should be generated :param branch: easybuild-easyconfigs branch to compare with """ tmpdir = tempfile.mkdtemp() download_repo_path = download_repo(branch=branch, path=tmpdir) repo_path = os.path.join(download_repo_path, 'easybuild', 'easyconfigs') pr_files = [ path for path in fetch_easyconfigs_from_pr(pr) if path.endswith('.eb') ] lines = [] ecs, _ = parse_easyconfigs([(fp, False) for fp in pr_files], validate=False) for ec in ecs: files = find_related_easyconfigs(repo_path, ec['ec']) _log.debug("File in PR#%s %s has these related easyconfigs: %s" % (pr, ec['spec'], files)) if files: lines.append(multidiff(ec['spec'], files, colored=colored)) else: lines.extend([ '', "(no related easyconfigs found for %s)\n" % os.path.basename(ec['spec']) ]) return '\n'.join(lines)
def review_pr(paths=None, pr=None, colored=True, branch='develop'): """ Print multi-diff overview between specified easyconfigs or PR and specified branch. :param pr: pull request number in easybuild-easyconfigs repo to review :param paths: path tuples (path, generated) of easyconfigs to review :param colored: boolean indicating whether a colored multi-diff should be generated :param branch: easybuild-easyconfigs branch to compare with """ tmpdir = tempfile.mkdtemp() download_repo_path = download_repo(branch=branch, path=tmpdir) repo_path = os.path.join(download_repo_path, 'easybuild', 'easyconfigs') if pr: pr_files = [path for path in fetch_easyconfigs_from_pr(pr) if path.endswith('.eb')] elif paths: pr_files = paths else: raise EasyBuildError("No PR # or easyconfig path specified") lines = [] ecs, _ = parse_easyconfigs([(fp, False) for fp in pr_files], validate=False) for ec in ecs: files = find_related_easyconfigs(repo_path, ec['ec']) if pr: pr_msg = "PR#%s" % pr else: pr_msg = "new PR" _log.debug("File in %s %s has these related easyconfigs: %s" % (pr_msg, ec['spec'], files)) if files: lines.append(multidiff(ec['spec'], files, colored=colored)) else: lines.extend(['', "(no related easyconfigs found for %s)\n" % os.path.basename(ec['spec'])]) return '\n'.join(lines)
def review_pr(pr, colored=True, branch="develop"): """ Print multi-diff overview between easyconfigs in specified PR and specified branch. @param pr: pull request number in easybuild-easyconfigs repo to review @param colored: boolean indicating whether a colored multi-diff should be generated @param branch: easybuild-easyconfigs branch to compare with """ tmpdir = tempfile.mkdtemp() download_repo_path = download_repo(branch=branch, path=tmpdir) repo_path = os.path.join(download_repo_path, "easybuild", "easyconfigs") pr_files = [path for path in fetch_easyconfigs_from_pr(pr) if path.endswith(".eb")] lines = [] ecs, _ = parse_easyconfigs([(fp, False) for fp in pr_files], validate=False) for ec in ecs: files = find_related_easyconfigs(repo_path, ec["ec"]) _log.debug("File in PR#%s %s has these related easyconfigs: %s" % (pr, ec["spec"], files)) if files: lines.append(multidiff(ec["spec"], files, colored=colored)) else: lines.extend(["", "(no related easyconfigs found for %s)\n" % os.path.basename(ec["spec"])]) return "\n".join(lines)
def review_pr(paths=None, pr=None, colored=True, branch='develop', testing=False): """ Print multi-diff overview between specified easyconfigs or PR and specified branch. :param pr: pull request number in easybuild-easyconfigs repo to review :param paths: path tuples (path, generated) of easyconfigs to review :param colored: boolean indicating whether a colored multi-diff should be generated :param branch: easybuild-easyconfigs branch to compare with :param testing: whether to ignore PR labels (used in test_review_pr) """ pr_target_repo = build_option('pr_target_repo') or GITHUB_EASYCONFIGS_REPO if pr_target_repo != GITHUB_EASYCONFIGS_REPO: raise EasyBuildError( "Reviewing PRs for repositories other than easyconfigs hasn't been implemented yet" ) tmpdir = tempfile.mkdtemp() download_repo_path = download_repo(branch=branch, path=tmpdir) repo_path = os.path.join(download_repo_path, 'easybuild', 'easyconfigs') if pr: pr_files = [ path for path in fetch_easyconfigs_from_pr(pr) if path.endswith('.eb') ] elif paths: pr_files = paths else: raise EasyBuildError("No PR # or easyconfig path specified") lines = [] ecs, _ = parse_easyconfigs([(fp, False) for fp in pr_files], validate=False) for ec in ecs: files = find_related_easyconfigs(repo_path, ec['ec']) if pr: pr_msg = "PR#%s" % pr else: pr_msg = "new PR" _log.debug("File in %s %s has these related easyconfigs: %s" % (pr_msg, ec['spec'], files)) if files: lines.append(multidiff(ec['spec'], files, colored=colored)) else: lines.extend([ '', "(no related easyconfigs found for %s)\n" % os.path.basename(ec['spec']) ]) if pr: file_info = det_file_info(pr_files, download_repo_path) pr_target_account = build_option('pr_target_account') github_user = build_option('github_user') pr_data, _ = fetch_pr_data(pr, pr_target_account, pr_target_repo, github_user) pr_labels = [label['name'] for label in pr_data['labels']] if not testing else [] expected_labels = det_pr_labels(file_info, pr_target_repo) missing_labels = [ label for label in expected_labels if label not in pr_labels ] if missing_labels: lines.extend([ '', "This PR should be labelled with %s" % ', '.join(["'%s'" % ml for ml in missing_labels]) ]) if not pr_data['milestone']: lines.extend(['', "This PR should be associated with a milestone"]) elif '.x' in pr_data['milestone']['title']: lines.extend([ '', "This PR is associated with a generic '.x' milestone, " "it should be associated to the next release milestone once merged" ]) return '\n'.join(lines)