-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add task to checkout configuration from repository
Change-Id: If77203d5162e64b00cdb79eec918944501746852
- Loading branch information
1 parent
10d930b
commit b26d226
Showing
2 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
"bluepyopt", | ||
"bluepymm", | ||
"diameter_synthesis", | ||
"gitpython", | ||
"h5py", | ||
"joblib", | ||
"luigi", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
} |