prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  nodeenv try to download non existing tar.gz prebuilt under Cygwin
  Hi,
  
  Strange issue: I suspect a recent change broke this as it used to work last week, on another Windows computer with Cygwin.
  
  Bug reproduction: `pre-commit run` using e.g. https://github.com/Lucas-C/pre-commit-hooks-html v1.1.0
  
  `pre-commit` execute the following command under the hood, a command that also fails if I execute it manually:
  ```
  nodeenv --prebuilt /cygdrive/c/Users/admin/.pre-commit/repoYHJ85q/node_env-default
  ```
  The error is the following:
  ```
  urllib2.HTTPError: HTTP Error 404: Not Found
  ```
  The `tar.gz` it tries to install is https://nodejs.org/dist/v7.2.1/node-v7.2.1-cygwin_nt-6.1-x64.tar.gz, which does not exist. My guess is that `nodeenv` should use the Windows prebuilts instead: https://nodejs.org/dist/v7.2.1/node-v7.2.1-win-x64.zip This is because `platform.system()` is used: https://github.com/ekalinin/nodeenv/blob/master/nodeenv.py#L503
  
  I'm going to ask for help on the https://github.com/ekalinin/nodeenv project, but do you have any hint at what the root cause could be here ?
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `pre_commit/languages/node.py`
  Content:
  ```
  1 from __future__ import unicode_literals
  2 
  3 import contextlib
  4 import os
  5 import sys
  6 
  7 from pre_commit.envcontext import envcontext
  8 from pre_commit.envcontext import Var
  9 from pre_commit.languages import helpers
  10 from pre_commit.util import clean_path_on_failure
  11 from pre_commit.xargs import xargs
  12 
  13 
  14 ENVIRONMENT_DIR = 'node_env'
  15 get_default_version = helpers.basic_get_default_version
  16 healthy = helpers.basic_healthy
  17 
  18 
  19 def get_env_patch(venv):  # pragma: windows no cover
  20     return (
  21         ('NODE_VIRTUAL_ENV', venv),
  22         ('NPM_CONFIG_PREFIX', venv),
  23         ('npm_config_prefix', venv),
  24         ('NODE_PATH', os.path.join(venv, 'lib', 'node_modules')),
  25         ('PATH', (os.path.join(venv, 'bin'), os.pathsep, Var('PATH'))),
  26     )
  27 
  28 
  29 @contextlib.contextmanager
  30 def in_env(repo_cmd_runner, language_version):  # pragma: windows no cover
  31     envdir = repo_cmd_runner.path(
  32         helpers.environment_dir(ENVIRONMENT_DIR, language_version),
  33     )
  34     with envcontext(get_env_patch(envdir)):
  35         yield
  36 
  37 
  38 def install_environment(
  39         repo_cmd_runner, version, additional_dependencies,
  40 ):  # pragma: windows no cover
  41     additional_dependencies = tuple(additional_dependencies)
  42     assert repo_cmd_runner.exists('package.json')
  43     directory = helpers.environment_dir(ENVIRONMENT_DIR, version)
  44 
  45     env_dir = repo_cmd_runner.path(directory)
  46     with clean_path_on_failure(env_dir):
  47         cmd = [
  48             sys.executable, '-m', 'nodeenv', '--prebuilt',
  49             '{{prefix}}{}'.format(directory),
  50         ]
  51 
  52         if version != 'default':
  53             cmd.extend(['-n', version])
  54 
  55         repo_cmd_runner.run(cmd)
  56 
  57         with in_env(repo_cmd_runner, version):
  58             helpers.run_setup_cmd(
  59                 repo_cmd_runner,
  60                 ('npm', 'install', '-g', '.') + additional_dependencies,
  61             )
  62 
  63 
  64 def run_hook(repo_cmd_runner, hook, file_args):  # pragma: windows no cover
  65     with in_env(repo_cmd_runner, hook['language_version']):
  66         return xargs(helpers.to_cmd(hook), file_args)
  67
  ```
  --- 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/pre_commit/languages/node.py b/pre_commit/languages/node.py
  --- a/pre_commit/languages/node.py
  +++ b/pre_commit/languages/node.py
  @@ -17,10 +17,11 @@
   
   
   def get_env_patch(venv):  # pragma: windows no cover
  +    config = os.path.join(venv, 'bin') if sys.platform == 'cygwin' else venv
       return (
           ('NODE_VIRTUAL_ENV', venv),
  -        ('NPM_CONFIG_PREFIX', venv),
  -        ('npm_config_prefix', venv),
  +        ('NPM_CONFIG_PREFIX', config),
  +        ('npm_config_prefix', config),
           ('NODE_PATH', os.path.join(venv, 'lib', 'node_modules')),
           ('PATH', (os.path.join(venv, 'bin'), os.pathsep, Var('PATH'))),
       )
  
verification_info: {"golden_diff": "diff --git a/pre_commit/languages/node.py b/pre_commit/languages/node.py\n--- a/pre_commit/languages/node.py\n+++ b/pre_commit/languages/node.py\n@@ -17,10 +17,11 @@\n \n \n def get_env_patch(venv):  # pragma: windows no cover\n+    config = os.path.join(venv, 'bin') if sys.platform == 'cygwin' else venv\n     return (\n         ('NODE_VIRTUAL_ENV', venv),\n-        ('NPM_CONFIG_PREFIX', venv),\n-        ('npm_config_prefix', venv),\n+        ('NPM_CONFIG_PREFIX', config),\n+        ('npm_config_prefix', config),\n         ('NODE_PATH', os.path.join(venv, 'lib', 'node_modules')),\n         ('PATH', (os.path.join(venv, 'bin'), os.pathsep, Var('PATH'))),\n     )\n", "issue": "nodeenv try to download non existing tar.gz prebuilt under Cygwin\nHi,\r\n\r\nStrange issue: I suspect a recent change broke this as it used to work last week, on another Windows computer with Cygwin.\r\n\r\nBug reproduction: `pre-commit run` using e.g. https://github.com/Lucas-C/pre-commit-hooks-html v1.1.0\r\n\r\n`pre-commit` execute the following command under the hood, a command that also fails if I execute it manually:\r\n```\r\nnodeenv --prebuilt /cygdrive/c/Users/admin/.pre-commit/repoYHJ85q/node_env-default\r\n```\r\nThe error is the following:\r\n```\r\nurllib2.HTTPError: HTTP Error 404: Not Found\r\n```\r\nThe `tar.gz` it tries to install is https://nodejs.org/dist/v7.2.1/node-v7.2.1-cygwin_nt-6.1-x64.tar.gz, which does not exist. My guess is that `nodeenv` should use the Windows prebuilts instead: https://nodejs.org/dist/v7.2.1/node-v7.2.1-win-x64.zip This is because `platform.system()` is used: https://github.com/ekalinin/nodeenv/blob/master/nodeenv.py#L503\r\n\r\nI'm going to ask for help on the https://github.com/ekalinin/nodeenv project, but do you have any hint at what the root cause could be here ?\n", "before_files": [{"content": "from __future__ import unicode_literals\n\nimport contextlib\nimport os\nimport sys\n\nfrom pre_commit.envcontext import envcontext\nfrom pre_commit.envcontext import Var\nfrom pre_commit.languages import helpers\nfrom pre_commit.util import clean_path_on_failure\nfrom pre_commit.xargs import xargs\n\n\nENVIRONMENT_DIR = 'node_env'\nget_default_version = helpers.basic_get_default_version\nhealthy = helpers.basic_healthy\n\n\ndef get_env_patch(venv):  # pragma: windows no cover\n    return (\n        ('NODE_VIRTUAL_ENV', venv),\n        ('NPM_CONFIG_PREFIX', venv),\n        ('npm_config_prefix', venv),\n        ('NODE_PATH', os.path.join(venv, 'lib', 'node_modules')),\n        ('PATH', (os.path.join(venv, 'bin'), os.pathsep, Var('PATH'))),\n    )\n\n\n@contextlib.contextmanager\ndef in_env(repo_cmd_runner, language_version):  # pragma: windows no cover\n    envdir = repo_cmd_runner.path(\n        helpers.environment_dir(ENVIRONMENT_DIR, language_version),\n    )\n    with envcontext(get_env_patch(envdir)):\n        yield\n\n\ndef install_environment(\n        repo_cmd_runner, version, additional_dependencies,\n):  # pragma: windows no cover\n    additional_dependencies = tuple(additional_dependencies)\n    assert repo_cmd_runner.exists('package.json')\n    directory = helpers.environment_dir(ENVIRONMENT_DIR, version)\n\n    env_dir = repo_cmd_runner.path(directory)\n    with clean_path_on_failure(env_dir):\n        cmd = [\n            sys.executable, '-m', 'nodeenv', '--prebuilt',\n            '{{prefix}}{}'.format(directory),\n        ]\n\n        if version != 'default':\n            cmd.extend(['-n', version])\n\n        repo_cmd_runner.run(cmd)\n\n        with in_env(repo_cmd_runner, version):\n            helpers.run_setup_cmd(\n                repo_cmd_runner,\n                ('npm', 'install', '-g', '.') + additional_dependencies,\n            )\n\n\ndef run_hook(repo_cmd_runner, hook, file_args):  # pragma: windows no cover\n    with in_env(repo_cmd_runner, hook['language_version']):\n        return xargs(helpers.to_cmd(hook), file_args)\n", "path": "pre_commit/languages/node.py"}], "after_files": [{"content": "from __future__ import unicode_literals\n\nimport contextlib\nimport os\nimport sys\n\nfrom pre_commit.envcontext import envcontext\nfrom pre_commit.envcontext import Var\nfrom pre_commit.languages import helpers\nfrom pre_commit.util import clean_path_on_failure\nfrom pre_commit.xargs import xargs\n\n\nENVIRONMENT_DIR = 'node_env'\nget_default_version = helpers.basic_get_default_version\nhealthy = helpers.basic_healthy\n\n\ndef get_env_patch(venv):  # pragma: windows no cover\n    config = os.path.join(venv, 'bin') if sys.platform == 'cygwin' else venv\n    return (\n        ('NODE_VIRTUAL_ENV', venv),\n        ('NPM_CONFIG_PREFIX', config),\n        ('npm_config_prefix', config),\n        ('NODE_PATH', os.path.join(venv, 'lib', 'node_modules')),\n        ('PATH', (os.path.join(venv, 'bin'), os.pathsep, Var('PATH'))),\n    )\n\n\n@contextlib.contextmanager\ndef in_env(repo_cmd_runner, language_version):  # pragma: windows no cover\n    envdir = repo_cmd_runner.path(\n        helpers.environment_dir(ENVIRONMENT_DIR, language_version),\n    )\n    with envcontext(get_env_patch(envdir)):\n        yield\n\n\ndef install_environment(\n        repo_cmd_runner, version, additional_dependencies,\n):  # pragma: windows no cover\n    additional_dependencies = tuple(additional_dependencies)\n    assert repo_cmd_runner.exists('package.json')\n    directory = helpers.environment_dir(ENVIRONMENT_DIR, version)\n\n    env_dir = repo_cmd_runner.path(directory)\n    with clean_path_on_failure(env_dir):\n        cmd = [\n            sys.executable, '-m', 'nodeenv', '--prebuilt',\n            '{{prefix}}{}'.format(directory),\n        ]\n\n        if version != 'default':\n            cmd.extend(['-n', version])\n\n        repo_cmd_runner.run(cmd)\n\n        with in_env(repo_cmd_runner, version):\n            helpers.run_setup_cmd(\n                repo_cmd_runner,\n                ('npm', 'install', '-g', '.') + additional_dependencies,\n            )\n\n\ndef run_hook(repo_cmd_runner, hook, file_args):  # pragma: windows no cover\n    with in_env(repo_cmd_runner, hook['language_version']):\n        return xargs(helpers.to_cmd(hook), file_args)\n", "path": "pre_commit/languages/node.py"}]}