-
Notifications
You must be signed in to change notification settings - Fork 218
added support to 'download' sources from git #2555
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 10 commits
0f9ce62
c657745
372b3c6
7baa951
75ef62c
5abd3b7
ed59ede
4ce646f
8ff3559
70c17b3
b8d9a4e
e2f07a0
ed74a75
8dbc954
51a4db3
e205640
b1eec8b
fa0389b
6af5a0c
9c578cd
e3ab8df
55f03be
a0ed138
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,6 +36,7 @@ | |
| :author: Sotiris Fragkiskos (NTUA, CERN) | ||
| :author: Davide Vanzo (ACCRE, Vanderbilt University) | ||
| :author: Damian Alvarez (Forschungszentrum Juelich GmbH) | ||
| :author: Maxime Boissonneault (Compute Canada) | ||
| """ | ||
| import datetime | ||
| import difflib | ||
|
|
@@ -1628,6 +1629,65 @@ def copy(paths, target_path, force_in_dry_run=False): | |
| raise EasyBuildError("Specified path to copy is not an existing file or directory: %s", path) | ||
|
|
||
|
|
||
| def get_source_from_git(filename, targetdir, git_config): | ||
|
||
| """ | ||
| Downloads a git repository, at a specific tag or commit, recursively or not, and make an archive with it | ||
|
|
||
| :param filename: name of the archive to save the code to (must be .tar.gz) | ||
| :param targetdir: target directory where to save the archive to | ||
| :param git_config: dictionary containing url, repo_name, recursive, and one of tag or commit | ||
| """ | ||
| # if a non-empty dictionary was provided, download from git and archive | ||
| if not isinstance(git_config, dict): | ||
| raise EasyBuildError("Found a non null git_config in 'sources', but value is not a dictionary") | ||
mboisson marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| # Making a copy to avoid modifying the object with pops | ||
| git_config = git_config.copy() | ||
| tag = git_config.pop('tag', None) | ||
| url = git_config.pop('url', None) | ||
| repo_name = git_config.pop('repo_name', None) | ||
| commit = git_config.pop('commit', None) | ||
| recursive = git_config.pop('recursive', False) | ||
| if git_config: | ||
| raise EasyBuildError("Found one or more unexpected keys in 'git_config' specification: %s", git_config) | ||
| if not repo_name: | ||
mboisson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| raise EasyBuildError("repo_name not specified in git_config parameter") | ||
| if not tag and not commit: | ||
| raise EasyBuildError("Neither tag nor commit found in git_config parameter") | ||
| if tag and commit: | ||
| raise EasyBuildError("Tag and commit are mutually exclusive in git_config parameter") | ||
| if not url: | ||
| raise EasyBuildError("url not specified in git_config parameter") | ||
| if '.tar.gz' not in filename: | ||
mboisson marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| raise EasyBuildError("git_config only supports filename ending in .tar.gz") | ||
mboisson marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| mkdir(targetdir, parents=True) | ||
| targetpath = os.path.join(targetdir, filename) | ||
|
|
||
| cwd = change_dir(targetdir) | ||
| recursive = " --recursive " if recursive else "" | ||
| if tag: | ||
| cmd = "git clone --branch %s %s %s/%s.git " % (tag, recursive, url, repo_name) | ||
| else: | ||
| cmd = "git clone %s %s/%s.git" % (recursive, url, repo_name) | ||
| (cmdstdouterr, ec) = run.run_cmd(cmd, log_all=True, log_ok=False, simple=False, regexp=False) | ||
mboisson marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| # if a specific commit is asked for, check it out | ||
| if commit: | ||
| change_dir(os.path.join(targetdir, repo_name)) | ||
| recursive = " && git submodule update " if recursive else "" | ||
| cmd = "git checkout %s %s " % (commit, recursive) | ||
| (cmdstdouterr, ec) = run.run_cmd(cmd, log_all=True, log_ok=False, simple=False, regexp=False) | ||
mboisson marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| change_dir(targetdir) | ||
|
|
||
| # create an archive and delete the git repo | ||
| cmd = "tar cfvz %s --exclude-vcs %s && rm -rf %s" % (targetpath, repo_name, repo_name) | ||
|
||
| (cmdstdouterr, ec) = run.run_cmd(cmd, log_all=True, log_ok=False, simple=False, regexp=False) | ||
mboisson marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| change_dir(cwd) | ||
| return targetpath | ||
|
|
||
|
|
||
| def move_file(path, target_path, force_in_dry_run=False): | ||
| """ | ||
| Move a file from path to target_path | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.