Repository: nf-core/tools

Issue:
Download: Also fetch institutional configs
Now that the institute config files are held in their own repo (see #212), they will not be available for users running offline.

Should be an easy enough fix though - the `nf-core download` command needs to be extended to also download the configs repo and set the base path for the import correctly.


Discussion:
cf: https://github.com/nf-core/configs/issues/1

Resolving patch:
diff --git a/nf_core/download.py b/nf_core/download.py
--- a/nf_core/download.py
+++ b/nf_core/download.py
@@ -64,6 +64,11 @@ def download_workflow(self):
         logging.info("Downloading workflow files from GitHub")
         self.download_wf_files()
 
+        # Download the centralised configs
+        logging.info("Downloading centralised configs from GitHub")
+        self.download_configs()
+        self.wf_use_local_configs()
+
         # Download the singularity images
         if self.singularity:
             logging.debug("Fetching container names for workflow")
@@ -176,6 +181,46 @@ def download_wf_files(self):
             for fname in filelist:
                 os.chmod(os.path.join(dirpath, fname), 0o775)
 
+    def download_configs(self):
+        """Downloads the centralised config profiles from nf-core/configs to :attr:`self.outdir`.
+        """
+        configs_zip_url = "https://github.com/nf-core/configs/archive/master.zip"
+        configs_local_dir = "configs-master"
+        logging.debug("Downloading {}".format(configs_zip_url))
+
+        # Download GitHub zip file into memory and extract
+        url = requests.get(configs_zip_url)
+        zipfile = ZipFile(BytesIO(url.content))
+        zipfile.extractall(self.outdir)
+
+        # Rename the internal directory name to be more friendly
+        os.rename(os.path.join(self.outdir, configs_local_dir), os.path.join(self.outdir, 'configs'))
+
+        # Make downloaded files executable
+        for dirpath, subdirs, filelist in os.walk(os.path.join(self.outdir, 'configs')):
+            for fname in filelist:
+                os.chmod(os.path.join(dirpath, fname), 0o775)
+
+    def wf_use_local_configs(self):
+        """Edit the downloaded nextflow.config file to use the local config files
+        """
+        nfconfig_fn = os.path.join(self.outdir, 'workflow', 'nextflow.config')
+        find_str = 'https://raw.githubusercontent.com/nf-core/configs/${params.custom_config_version}'
+        repl_str = '../configs/'
+        logging.debug("Editing params.custom_config_base in {}".format(nfconfig_fn))
+
+        # Load the nextflow.config file into memory
+        with open(nfconfig_fn, 'r') as nfconfig_fh:
+          nfconfig = nfconfig_fh.read()
+
+        # Replace the target string
+        nfconfig = nfconfig.replace(find_str, repl_str)
+
+        # Write the file out again
+        with open(nfconfig_fn, 'w') as nfconfig_fh:
+          nfconfig_fh.write(nfconfig)
+
+
     def find_container_images(self):
         """ Find container image names for workflow """
 


Test patch:
diff --git a/tests/lint_examples/minimal_working_example/nextflow.config b/tests/lint_examples/minimal_working_example/nextflow.config
--- a/tests/lint_examples/minimal_working_example/nextflow.config
+++ b/tests/lint_examples/minimal_working_example/nextflow.config
@@ -3,6 +3,8 @@ params {
   outdir = './results'
   reads = "data/*.fastq"
   singleEnd = false
+  custom_config_version = 'master'
+  custom_config_base = "https://raw.githubusercontent.com/nf-core/configs/${params.custom_config_version}"
 }
 
 process {
diff --git a/tests/test_download.py b/tests/test_download.py
--- a/tests/test_download.py
+++ b/tests/test_download.py
@@ -3,6 +3,7 @@
 """
 
 import nf_core.list
+import nf_core.utils
 from nf_core.download import DownloadWorkflow
 
 import hashlib
@@ -15,6 +16,8 @@
 import tempfile
 import unittest
 
+PATH_WORKING_EXAMPLE = os.path.join(os.path.dirname(__file__), 'lint_examples/minimal_working_example')
+
 class DownloadTest(unittest.TestCase):
 
     #
@@ -113,6 +116,36 @@ def test_download_wf_files(self):
         download_obj.wf_download_url = "https://github.com/nf-core/methylseq/archive/1.0.zip"
         download_obj.download_wf_files()
 
+    #
+    # Tests for 'download_configs'
+    #
+    def test_download_configs(self):
+        download_obj = DownloadWorkflow(
+            pipeline = "dummy",
+            release = "1.2.0",
+            outdir = tempfile.mkdtemp()
+            )
+        download_obj.download_configs()
+
+    #
+    # Tests for 'wf_use_local_configs'
+    #
+    def test_wf_use_local_configs(self):
+        # Get a workflow and configs
+        test_outdir = tempfile.mkdtemp()
+        download_obj = DownloadWorkflow(
+            pipeline = "dummy",
+            release = "1.2.0",
+            outdir = test_outdir
+            )
+        shutil.copytree(PATH_WORKING_EXAMPLE, os.path.join(test_outdir, 'workflow'))
+        download_obj.download_configs()
+
+        # Test the function
+        download_obj.wf_use_local_configs()
+        wf_config = nf_core.utils.fetch_wf_config(os.path.join(test_outdir, 'workflow'))
+        assert wf_config['params.custom_config_base'] == "'../configs/'"
+
     #
     # Tests for 'find_container_images'
     #