Skip to content

Commit

Permalink
Add task to checkout configuration from repository
Browse files Browse the repository at this point in the history
Change-Id: If77203d5162e64b00cdb79eec918944501746852
  • Loading branch information
adrien-berchet committed Oct 22, 2020
1 parent 10d930b commit b26d226
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"bluepyopt",
"bluepymm",
"diameter_synthesis",
"gitpython",
"h5py",
"joblib",
"luigi",
Expand Down
62 changes: 62 additions & 0 deletions synthesis_workflow/tasks/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
"""Utils luigi tasks."""
import shutil
from pathlib import Path
from tempfile import TemporaryDirectory

import luigi
from git import Repo

from .config import SynthesisConfig
from .luigi_tools import copy_params
from .luigi_tools import ParamLink
from .luigi_tools import WorkflowTask


class GitClone(WorkflowTask):
"""Task to clone a git repository"""

url = luigi.Parameter()
dest = luigi.Parameter()

def run(self):
""""""
Repo.clone_from(self.url, self.output().path)

def output(self):
return luigi.LocalTarget(self.dest)


@copy_params(
tmd_parameters_path=ParamLink(SynthesisConfig),
tmd_distributions_path=ParamLink(SynthesisConfig),
)
class GetOfficialConfiguration(WorkflowTask):
"""Task to get official parameters from the git repository"""

url = luigi.Parameter()
specie = luigi.ChoiceParameter(choices=["rat", "mouse", "human"])
version = luigi.OptionalParameter(default=None)

def run(self):
""""""
with TemporaryDirectory() as tmpdir:
dest = Path(tmpdir) / "tmp_repo"
# Note: can not be called with yield here because of the TemporaryDirectory
GitClone(url=self.url, dest=dest).run()
if self.version is not None:
r = Repo(dest)
r.git.checkout(self.version)
shutil.copy(
dest / "entities" / "bionames" / self.specie / "tmd_parameters.json",
self.tmd_parameters_path,
)
shutil.copy(
dest / "entities" / "bionames" / self.specie / "tmd_distributions.json",
self.tmd_distributions_path,
)

def output(self):
return {
"tmd_parameters": luigi.LocalTarget(self.tmd_parameters_path),
"tmd_distributions": luigi.LocalTarget(self.tmd_distributions_path),
}

0 comments on commit b26d226

Please sign in to comment.