Skip to content
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

Merged
merged 23 commits into from
Sep 20, 2018

Conversation

mboisson
Copy link
Contributor

This pull requests allows one to specify a dictionary of the following form to "download" sources from a git repository

sources = [{
        'filename':'%(namelower)s-%(version)s.tar.gz',
        'git_config': {
                'tag': 'v%(version)s',
                'repo_name': 'speedseq',
                'url': 'https://github.com/hall-lab',
                'recursive': True,
                }
        }]

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))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing whitespace after ','

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")

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)

recursive = git_config.pop('recursive', False)
if git_config:
raise EasyBuildError("Found one or more unexpected keys in 'git_config' specification: %s",
git_config)

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

@@ -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={}):

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)

recursive = git_config.pop('recursive', False)
if git_config:
raise EasyBuildError("Found one or more unexpected keys in 'git_config' specification: %s",
git_config)

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

@@ -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={}):

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

@@ -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,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trailing whitespace

@@ -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={}):

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

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
Copy link
Member

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...

Copy link
Contributor Author

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 ?

Copy link
Member

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...)

Copy link
Contributor Author

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.

Copy link
Member

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -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={}):
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

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()
Copy link
Member

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...

Copy link
Contributor Author

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).

Copy link
Member

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 .pops...

Better add a comment to explain that (on line 347 too, while you're at it). ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

# 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:
Copy link
Member

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...

@boegel boegel added this to the next release milestone Aug 31, 2018
(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

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 '# '

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

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 '# '

@@ -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):

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

Copy link
Member

@boegel boegel left a 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/framework/easyblock.py Outdated Show resolved Hide resolved
easybuild/framework/easyblock.py Outdated Show resolved Hide resolved
easybuild/tools/filetools.py Outdated Show resolved Hide resolved
easybuild/tools/filetools.py Outdated Show resolved Hide resolved
easybuild/tools/filetools.py Outdated Show resolved Hide resolved
easybuild/tools/filetools.py Outdated Show resolved Hide resolved
easybuild/tools/filetools.py Outdated Show resolved Hide resolved
easybuild/tools/filetools.py 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)
Copy link
Member

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... :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in upcoming commit

Copy link
Contributor Author

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 ?

Copy link
Member

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...

easybuild/tools/filetools.py Outdated Show resolved Hide resolved
@mboisson
Copy link
Contributor Author

mboisson commented Sep 5, 2018

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 ?

run_check()


def test_is_sha256_checksum(self):

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)

@mboisson
Copy link
Contributor Author

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.

@boegel
Copy link
Member

boegel commented Sep 20, 2018

@mboisson tests fail because of problem in the Travis config which is being fixed in #2584, but also because of using a git URL for the testrepository in the tests, which is fixed in ComputeCanada#6

use HTTPS url for test repo in tests to avoid cloning failures in Travis
@boegel boegel modified the milestones: next release, 3.7.0 Sep 20, 2018
@boegel
Copy link
Member

boegel commented Sep 20, 2018

Going in, right in time to be included in EasyBuild v3.7.0, thanks a lot @mboisson!

@boegel
Copy link
Member

boegel commented Sep 20, 2018

Going in, thanks @mboisson!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants