prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  problem with nfcore_cache.sqlite within /tmp
  Hi all,
  I think will be a nice idea to have the nfcore_cache.sqlite within a subfolder in tmp because if two users use the program at the same time the privileges will prevent to use the tool.
  
  For example I cannot even use nf-core --help 
  
  Luca
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `nf_core/utils.py`
  Content:
  ```
  1 #!/usr/bin/env python
  2 """
  3 Common utility functions for the nf-core python package.
  4 """
  5 
  6 import datetime
  7 import json
  8 import logging
  9 import os
  10 import subprocess
  11 import tempfile
  12 
  13 def fetch_wf_config(wf_path, wf=None):
  14     """Uses Nextflow to retrieve the the configuration variables
  15     from a Nextflow workflow.
  16 
  17     Args:
  18         wf_path (str): Nextflow workflow file system path.
  19 
  20     Returns:
  21         dict: Workflow configuration settings.
  22     """
  23 
  24     config = dict()
  25     cache_fn = None
  26     cache_basedir = None
  27     cache_path = None
  28 
  29     # Build a cache directory if we can
  30     if os.path.isdir(os.path.join(os.getenv("HOME"), '.nextflow')):
  31         cache_basedir = os.path.join(os.getenv("HOME"), '.nextflow', 'nf-core')
  32         if not os.path.isdir(cache_basedir):
  33             os.mkdir(cache_basedir)
  34 
  35     # If we're given a workflow object with a commit, see if we have a cached copy
  36     if cache_basedir and wf and wf.full_name and wf.commit_sha:
  37         cache_fn = '{}-{}.json'.format(wf.full_name.replace(os.path.sep, '-'), wf.commit_sha)
  38         cache_path = os.path.join(cache_basedir, cache_fn)
  39         if os.path.isfile(cache_path):
  40             logging.debug("Found a config cache, loading: {}".format(cache_path))
  41             with open(cache_path, 'r') as fh:
  42                 config = json.load(fh)
  43             return config
  44 
  45 
  46     # Call `nextflow config` and pipe stderr to /dev/null
  47     try:
  48         with open(os.devnull, 'w') as devnull:
  49             nfconfig_raw = subprocess.check_output(['nextflow', 'config', '-flat', wf_path], stderr=devnull)
  50     except OSError as e:
  51         if e.errno == os.errno.ENOENT:
  52             raise AssertionError("It looks like Nextflow is not installed. It is required for most nf-core functions.")
  53     except subprocess.CalledProcessError as e:
  54         raise AssertionError("`nextflow config` returned non-zero error code: %s,\n   %s", e.returncode, e.output)
  55     else:
  56         for l in nfconfig_raw.splitlines():
  57             ul = l.decode('utf-8')
  58             k, v = ul.split(' = ', 1)
  59             config[k] = v
  60 
  61     # If we can, save a cached copy
  62     if cache_path:
  63         logging.debug("Saving config cache: {}".format(cache_path))
  64         with open(cache_path, 'w') as fh:
  65             json.dump(config, fh, indent=4)
  66 
  67     return config
  68 
  69 
  70 def setup_requests_cachedir():
  71     """Sets up local caching for faster remote HTTP requests.
  72 
  73     Caching directory will be generated by tempfile.gettempdir() under
  74     a nfcore_cache subdir.
  75     """
  76     # Only import it if we need it
  77     import requests_cache
  78 
  79     cachedir = os.path.join(tempfile.gettempdir(), 'nfcore_cache')
  80     if not os.path.exists(cachedir):
  81         os.mkdir(cachedir)
  82     requests_cache.install_cache(
  83         os.path.join(cachedir, 'nfcore_cache'),
  84         expire_after=datetime.timedelta(hours=1),
  85         backend='sqlite',
  86     )
  87     # Make world-writeable so that multi-user installations work
  88     os.chmod(cachedir, 0o777)
  89     os.chmod(os.path.join(cachedir, 'nfcore_cache.sqlite'), 0o777)
  90
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/nf_core/utils.py b/nf_core/utils.py
  --- a/nf_core/utils.py
  +++ b/nf_core/utils.py
  @@ -8,7 +8,6 @@
   import logging
   import os
   import subprocess
  -import tempfile
   
   def fetch_wf_config(wf_path, wf=None):
       """Uses Nextflow to retrieve the the configuration variables
  @@ -70,20 +69,18 @@
   def setup_requests_cachedir():
       """Sets up local caching for faster remote HTTP requests.
   
  -    Caching directory will be generated by tempfile.gettempdir() under
  -    a nfcore_cache subdir.
  +    Caching directory will be set up in the user's home directory under
  +    a .nfcore_cache subdir.
       """
       # Only import it if we need it
       import requests_cache
  +    
   
  -    cachedir = os.path.join(tempfile.gettempdir(), 'nfcore_cache')
  +    cachedir = os.path.join(os.getenv("HOME"), os.path.join('.nfcore', 'cache'))
       if not os.path.exists(cachedir):
  -        os.mkdir(cachedir)
  +        os.makedirs(cachedir)
       requests_cache.install_cache(
  -        os.path.join(cachedir, 'nfcore_cache'),
  +        os.path.join(cachedir, 'github_info'),
           expire_after=datetime.timedelta(hours=1),
           backend='sqlite',
       )
  -    # Make world-writeable so that multi-user installations work
  -    os.chmod(cachedir, 0o777)
  -    os.chmod(os.path.join(cachedir, 'nfcore_cache.sqlite'), 0o777)
  
verification_info: {"golden_diff": "diff --git a/nf_core/utils.py b/nf_core/utils.py\n--- a/nf_core/utils.py\n+++ b/nf_core/utils.py\n@@ -8,7 +8,6 @@\n import logging\n import os\n import subprocess\n-import tempfile\n \n def fetch_wf_config(wf_path, wf=None):\n     \"\"\"Uses Nextflow to retrieve the the configuration variables\n@@ -70,20 +69,18 @@\n def setup_requests_cachedir():\n     \"\"\"Sets up local caching for faster remote HTTP requests.\n \n-    Caching directory will be generated by tempfile.gettempdir() under\n-    a nfcore_cache subdir.\n+    Caching directory will be set up in the user's home directory under\n+    a .nfcore_cache subdir.\n     \"\"\"\n     # Only import it if we need it\n     import requests_cache\n+    \n \n-    cachedir = os.path.join(tempfile.gettempdir(), 'nfcore_cache')\n+    cachedir = os.path.join(os.getenv(\"HOME\"), os.path.join('.nfcore', 'cache'))\n     if not os.path.exists(cachedir):\n-        os.mkdir(cachedir)\n+        os.makedirs(cachedir)\n     requests_cache.install_cache(\n-        os.path.join(cachedir, 'nfcore_cache'),\n+        os.path.join(cachedir, 'github_info'),\n         expire_after=datetime.timedelta(hours=1),\n         backend='sqlite',\n     )\n-    # Make world-writeable so that multi-user installations work\n-    os.chmod(cachedir, 0o777)\n-    os.chmod(os.path.join(cachedir, 'nfcore_cache.sqlite'), 0o777)\n", "issue": "problem with nfcore_cache.sqlite within /tmp\nHi all,\r\nI think will be a nice idea to have the nfcore_cache.sqlite within a subfolder in tmp because if two users use the program at the same time the privileges will prevent to use the tool.\r\n\r\nFor example I cannot even use nf-core --help \r\n\r\nLuca\n", "before_files": [{"content": "#!/usr/bin/env python\n\"\"\"\nCommon utility functions for the nf-core python package.\n\"\"\"\n\nimport datetime\nimport json\nimport logging\nimport os\nimport subprocess\nimport tempfile\n\ndef fetch_wf_config(wf_path, wf=None):\n    \"\"\"Uses Nextflow to retrieve the the configuration variables\n    from a Nextflow workflow.\n\n    Args:\n        wf_path (str): Nextflow workflow file system path.\n\n    Returns:\n        dict: Workflow configuration settings.\n    \"\"\"\n\n    config = dict()\n    cache_fn = None\n    cache_basedir = None\n    cache_path = None\n\n    # Build a cache directory if we can\n    if os.path.isdir(os.path.join(os.getenv(\"HOME\"), '.nextflow')):\n        cache_basedir = os.path.join(os.getenv(\"HOME\"), '.nextflow', 'nf-core')\n        if not os.path.isdir(cache_basedir):\n            os.mkdir(cache_basedir)\n\n    # If we're given a workflow object with a commit, see if we have a cached copy\n    if cache_basedir and wf and wf.full_name and wf.commit_sha:\n        cache_fn = '{}-{}.json'.format(wf.full_name.replace(os.path.sep, '-'), wf.commit_sha)\n        cache_path = os.path.join(cache_basedir, cache_fn)\n        if os.path.isfile(cache_path):\n            logging.debug(\"Found a config cache, loading: {}\".format(cache_path))\n            with open(cache_path, 'r') as fh:\n                config = json.load(fh)\n            return config\n\n\n    # Call `nextflow config` and pipe stderr to /dev/null\n    try:\n        with open(os.devnull, 'w') as devnull:\n            nfconfig_raw = subprocess.check_output(['nextflow', 'config', '-flat', wf_path], stderr=devnull)\n    except OSError as e:\n        if e.errno == os.errno.ENOENT:\n            raise AssertionError(\"It looks like Nextflow is not installed. It is required for most nf-core functions.\")\n    except subprocess.CalledProcessError as e:\n        raise AssertionError(\"`nextflow config` returned non-zero error code: %s,\\n   %s\", e.returncode, e.output)\n    else:\n        for l in nfconfig_raw.splitlines():\n            ul = l.decode('utf-8')\n            k, v = ul.split(' = ', 1)\n            config[k] = v\n\n    # If we can, save a cached copy\n    if cache_path:\n        logging.debug(\"Saving config cache: {}\".format(cache_path))\n        with open(cache_path, 'w') as fh:\n            json.dump(config, fh, indent=4)\n\n    return config\n\n\ndef setup_requests_cachedir():\n    \"\"\"Sets up local caching for faster remote HTTP requests.\n\n    Caching directory will be generated by tempfile.gettempdir() under\n    a nfcore_cache subdir.\n    \"\"\"\n    # Only import it if we need it\n    import requests_cache\n\n    cachedir = os.path.join(tempfile.gettempdir(), 'nfcore_cache')\n    if not os.path.exists(cachedir):\n        os.mkdir(cachedir)\n    requests_cache.install_cache(\n        os.path.join(cachedir, 'nfcore_cache'),\n        expire_after=datetime.timedelta(hours=1),\n        backend='sqlite',\n    )\n    # Make world-writeable so that multi-user installations work\n    os.chmod(cachedir, 0o777)\n    os.chmod(os.path.join(cachedir, 'nfcore_cache.sqlite'), 0o777)\n", "path": "nf_core/utils.py"}], "after_files": [{"content": "#!/usr/bin/env python\n\"\"\"\nCommon utility functions for the nf-core python package.\n\"\"\"\n\nimport datetime\nimport json\nimport logging\nimport os\nimport subprocess\n\ndef fetch_wf_config(wf_path, wf=None):\n    \"\"\"Uses Nextflow to retrieve the the configuration variables\n    from a Nextflow workflow.\n\n    Args:\n        wf_path (str): Nextflow workflow file system path.\n\n    Returns:\n        dict: Workflow configuration settings.\n    \"\"\"\n\n    config = dict()\n    cache_fn = None\n    cache_basedir = None\n    cache_path = None\n\n    # Build a cache directory if we can\n    if os.path.isdir(os.path.join(os.getenv(\"HOME\"), '.nextflow')):\n        cache_basedir = os.path.join(os.getenv(\"HOME\"), '.nextflow', 'nf-core')\n        if not os.path.isdir(cache_basedir):\n            os.mkdir(cache_basedir)\n\n    # If we're given a workflow object with a commit, see if we have a cached copy\n    if cache_basedir and wf and wf.full_name and wf.commit_sha:\n        cache_fn = '{}-{}.json'.format(wf.full_name.replace(os.path.sep, '-'), wf.commit_sha)\n        cache_path = os.path.join(cache_basedir, cache_fn)\n        if os.path.isfile(cache_path):\n            logging.debug(\"Found a config cache, loading: {}\".format(cache_path))\n            with open(cache_path, 'r') as fh:\n                config = json.load(fh)\n            return config\n\n\n    # Call `nextflow config` and pipe stderr to /dev/null\n    try:\n        with open(os.devnull, 'w') as devnull:\n            nfconfig_raw = subprocess.check_output(['nextflow', 'config', '-flat', wf_path], stderr=devnull)\n    except OSError as e:\n        if e.errno == os.errno.ENOENT:\n            raise AssertionError(\"It looks like Nextflow is not installed. It is required for most nf-core functions.\")\n    except subprocess.CalledProcessError as e:\n        raise AssertionError(\"`nextflow config` returned non-zero error code: %s,\\n   %s\", e.returncode, e.output)\n    else:\n        for l in nfconfig_raw.splitlines():\n            ul = l.decode('utf-8')\n            k, v = ul.split(' = ', 1)\n            config[k] = v\n\n    # If we can, save a cached copy\n    if cache_path:\n        logging.debug(\"Saving config cache: {}\".format(cache_path))\n        with open(cache_path, 'w') as fh:\n            json.dump(config, fh, indent=4)\n\n    return config\n\n\ndef setup_requests_cachedir():\n    \"\"\"Sets up local caching for faster remote HTTP requests.\n\n    Caching directory will be set up in the user's home directory under\n    a .nfcore_cache subdir.\n    \"\"\"\n    # Only import it if we need it\n    import requests_cache\n    \n\n    cachedir = os.path.join(os.getenv(\"HOME\"), os.path.join('.nfcore', 'cache'))\n    if not os.path.exists(cachedir):\n        os.makedirs(cachedir)\n    requests_cache.install_cache(\n        os.path.join(cachedir, 'github_info'),\n        expire_after=datetime.timedelta(hours=1),\n        backend='sqlite',\n    )\n", "path": "nf_core/utils.py"}]}