-
Notifications
You must be signed in to change notification settings - Fork 203
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
added support to 'download' sources from git #2555
Conversation
easybuild/framework/easyblock.py
Outdated
cmd = "git clone %s %s/%s.git" % (recursive, url, repo_name) | ||
(cmdstdouterr, ec) = run_cmd(cmd, log_all=True, log_ok=False, simple=False, regexp=False) | ||
if commit: | ||
change_dir(os.path.join(targetdir,repo_name)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing whitespace after ','
easybuild/framework/easyblock.py
Outdated
if not tag and not commit: | ||
raise EasyBuildError("git_config specified, but neither tag nor commit specified") | ||
if tag and commit: | ||
raise EasyBuildError("git_config specified, and both tag and commit specified. Specify only one") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line too long (121 > 120 characters)
easybuild/framework/easyblock.py
Outdated
recursive = git_config.pop('recursive', False) | ||
if git_config: | ||
raise EasyBuildError("Found one or more unexpected keys in 'git_config' specification: %s", | ||
git_config) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
continuation line over-indented for visual indent
easybuild/framework/easyblock.py
Outdated
@@ -559,7 +560,7 @@ def fetch_extension_sources(self, skip_checksums=False): | |||
|
|||
return exts_sources | |||
|
|||
def obtain_file(self, filename, extension=False, urls=None, download_filename=None, force_download=False): | |||
def obtain_file(self, filename, extension=False, urls=None, download_filename=None, force_download=False, git_config={}): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line too long (125 > 120 characters)
easybuild/framework/easyblock.py
Outdated
recursive = git_config.pop('recursive', False) | ||
if git_config: | ||
raise EasyBuildError("Found one or more unexpected keys in 'git_config' specification: %s", | ||
git_config) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
continuation line under-indented for visual indent
easybuild/framework/easyblock.py
Outdated
@@ -559,7 +560,8 @@ def fetch_extension_sources(self, skip_checksums=False): | |||
|
|||
return exts_sources | |||
|
|||
def obtain_file(self, filename, extension=False, urls=None, download_filename=None, force_download=False): | |||
def obtain_file(self, filename, extension=False, urls=None, download_filename=None, force_download=False, | |||
git_config={}): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
continuation line under-indented for visual indent
easybuild/framework/easyblock.py
Outdated
@@ -559,7 +560,8 @@ def fetch_extension_sources(self, skip_checksums=False): | |||
|
|||
return exts_sources | |||
|
|||
def obtain_file(self, filename, extension=False, urls=None, download_filename=None, force_download=False): | |||
def obtain_file(self, filename, extension=False, urls=None, download_filename=None, force_download=False, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
trailing whitespace
easybuild/framework/easyblock.py
Outdated
@@ -559,7 +560,8 @@ def fetch_extension_sources(self, skip_checksums=False): | |||
|
|||
return exts_sources | |||
|
|||
def obtain_file(self, filename, extension=False, urls=None, download_filename=None, force_download=False): | |||
def obtain_file(self, filename, extension=False, urls=None, download_filename=None, force_download=False, | |||
git_config={}): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
continuation line over-indented for visual indent
easybuild/framework/easyblock.py
Outdated
change_dir(targetdir) | ||
cmd = "tar cfvz %s --exclude-vcs %s && rm -rf %s" % (targetpath, repo_name, repo_name) | ||
(cmdstdouterr, ec) = run_cmd(cmd, log_all=True, log_ok=False, simple=False, regexp=False) | ||
return targetpath |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mboisson Quick review: please move this to a dedicated function, the obtain_file
method is already too big as is... Throwing that in filetools
probably makes most sense? And then we also should have a dedicated test for it...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just this or the whole logic to download from git ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would create a function that takes git_config
as an argument, and trim this down to something like:
elif git_config:
return new_function(git_config)
(but find a better name than new_function
, of course...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. Moving it to filetools would require quite a few more parameters, because this bit of code uses a couple of variables internal to easyblock.py :
- srcpaths[0]
- self.name
it also calls change_dir, I'll try to see how I can rework those.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, but that's only 2 parameters to add, that's OK.
change_dir
returns the original dir you were in, you could make sure you restore where you were in the function:
cwd = change_dir(new_dir)
...
change_dir(cwd)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
easybuild/framework/easyblock.py
Outdated
@@ -559,7 +561,8 @@ def fetch_extension_sources(self, skip_checksums=False): | |||
|
|||
return exts_sources | |||
|
|||
def obtain_file(self, filename, extension=False, urls=None, download_filename=None, force_download=False): | |||
def obtain_file(self, filename, extension=False, urls=None, download_filename=None, force_download=False, | |||
git_config={}): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mboisson Using a mutable value like {}
as default value is evil (see https://docs.python-guide.org/writing/gotchas/#mutable-default-arguments).
You have a check if gitconfig
, so just use None
as default value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
easybuild/framework/easyblock.py
Outdated
if not isinstance(git_config, dict): | ||
raise EasyBuildError("Found a non null git_config in 'sources', but value is not a dictionary") | ||
else: | ||
git_config = git_config.copy() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the copy()
? I don't see the point of that...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took this strategy from similar code above (line 347).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, now it clicks... It's done to avoid modifying the value that is passed into obtain_file
with the .pop
s...
Better add a comment to explain that (on line 347 too, while you're at it). ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
easybuild/framework/easyblock.py
Outdated
# 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") | ||
else: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for the else, the raise
makes sure you'll never reach the below...
easybuild/tools/filetools.py
Outdated
(cmdstdouterr, ec) = run.run_cmd(cmd, log_all=True, log_ok=False, simple=False, regexp=False) | ||
change_dir(targetdir) | ||
|
||
#create an archive and delete the git repo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
block comment should start with '# '
easybuild/tools/filetools.py
Outdated
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) | ||
|
||
#if a specific commit is asked for, check it out |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
block comment should start with '# '
easybuild/tools/filetools.py
Outdated
@@ -1627,6 +1628,63 @@ def copy(paths, target_path, force_in_dry_run=False): | |||
else: | |||
raise EasyBuildError("Specified path to copy is not an existing file or directory: %s", path) | |||
|
|||
def get_source_from_git(filename, targetdir, git_config): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expected 2 blank lines, found 1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mboisson We'll also need a dedicated test for get_source_from_git
before this can be merged...
easybuild/tools/filetools.py
Outdated
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mboisson Please use the remove_file
function rather than rm -rf
... :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed in upcoming commit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove_file does not remove a directory recursively, unless I am missing something ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, we need a remove_dir
as well...
Regarding writing a test for the new function, I am quite puzzled how to test this. I guess I could try to download the EasyBuild repo, you are not using submodules. I probably should not test with a real application repository either. Ideas about how/where to start ? |
…emove function + add tests
test/framework/filetools.py
Outdated
run_check() | ||
|
||
|
||
def test_is_sha256_checksum(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
too many blank lines (2)
minor cleanup in get_source_tarball_from_git + add & use remove_dir/remove function + add tests
I merged your PR @boegel even though I don't like merging develop, I don't have enough time to figure out this ninja-level git... I'll just close and remove this branch as soon as it's merged into upstream develop and not merge it with our master branch. |
@mboisson tests fail because of problem in the Travis config which is being fixed in #2584, but also because of using a |
use HTTPS url for test repo in tests to avoid cloning failures in Travis
Going in, right in time to be included in EasyBuild v3.7.0, thanks a lot @mboisson! |
Going in, thanks @mboisson! |
This pull requests allows one to specify a dictionary of the following form to "download" sources from a git repository