prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Cygwin and msys2 bash activator compatibility
  **Issue**
  
  Run the following via msys2:
  
  ```
  $ /c/Users/builder/AppData/Local/Programs/Python/Python39/Scripts/virtualenv.exe --no-pip --no-setuptools --no-wheel -p /c/Users/builder/AppData/Local/Programs/Python/Python39/python.exe /tmp/tmp.uw7eZfvJIO
  $ source /tmp/tmp.uw7eZfvJIO/Scripts/activate
  $ python
  python: command not found
  ```
  
  The content of `/tmp/tmp.uw7eZfvJIO/Scripts/activate` contains `VIRTUAL_ENV='C:\tools\msys64\tmp\tmp.uw7eZfvJIO'`, but it's expected to be `VIRTUAL_ENV='/c/tools/msys64/tmp/tmp.uw7eZfvJIO'`, thus it can't locate `python`.
  
  I believe the legacy version handles this correctly here: https://github.com/pypa/virtualenv/blob/4c9899f471139670b0f1bfd359c37a67c507447d/virtualenv.py#L1742-L1748
  
  which contains:
  
  `VIRTUAL_ENV="$(if [ "$OSTYPE" "==" "cygwin" ]; then cygpath -u 'C:\tools\msys64\tmp\tmp.uw7eZfvJIO'; else echo '/C/tools/msys64/tmp/tmp.uw7eZfvJIO'; fi;)"`
  
  **Environment**
  
  Provide at least:
  - OS: Windows 7, using msys2 v20200903.0.0
  
  </issue>
  <code>
  [start of src/virtualenv/activation/via_template.py]
  1 from __future__ import absolute_import, unicode_literals
  2 
  3 import os
  4 import sys
  5 from abc import ABCMeta, abstractmethod
  6 
  7 from six import add_metaclass
  8 
  9 from virtualenv.util.six import ensure_text
  10 
  11 from .activator import Activator
  12 
  13 if sys.version_info >= (3, 7):
  14     from importlib.resources import read_binary
  15 else:
  16     from importlib_resources import read_binary
  17 
  18 
  19 @add_metaclass(ABCMeta)
  20 class ViaTemplateActivator(Activator):
  21     @abstractmethod
  22     def templates(self):
  23         raise NotImplementedError
  24 
  25     def generate(self, creator):
  26         dest_folder = creator.bin_dir
  27         replacements = self.replacements(creator, dest_folder)
  28         generated = self._generate(replacements, self.templates(), dest_folder, creator)
  29         if self.flag_prompt is not None:
  30             creator.pyenv_cfg["prompt"] = self.flag_prompt
  31         return generated
  32 
  33     def replacements(self, creator, dest_folder):
  34         return {
  35             "__VIRTUAL_PROMPT__": "" if self.flag_prompt is None else self.flag_prompt,
  36             "__VIRTUAL_ENV__": ensure_text(str(creator.dest)),
  37             "__VIRTUAL_NAME__": creator.env_name,
  38             "__BIN_NAME__": ensure_text(str(creator.bin_dir.relative_to(creator.dest))),
  39             "__PATH_SEP__": ensure_text(os.pathsep),
  40         }
  41 
  42     def _generate(self, replacements, templates, to_folder, creator):
  43         generated = []
  44         for template in templates:
  45             text = self.instantiate_template(replacements, template, creator)
  46             dest = to_folder / self.as_name(template)
  47             # use write_bytes to avoid platform specific line normalization (\n -> \r\n)
  48             dest.write_bytes(text.encode("utf-8"))
  49             generated.append(dest)
  50         return generated
  51 
  52     def as_name(self, template):
  53         return template.name
  54 
  55     def instantiate_template(self, replacements, template, creator):
  56         # read content as binary to avoid platform specific line normalization (\n -> \r\n)
  57         binary = read_binary(self.__module__, str(template))
  58         text = binary.decode("utf-8", errors="strict")
  59         for key, value in replacements.items():
  60             value = self._repr_unicode(creator, value)
  61             text = text.replace(key, value)
  62         return text
  63 
  64     @staticmethod
  65     def _repr_unicode(creator, value):
  66         # by default we just let it be unicode
  67         return value
  68
  [end of src/virtualenv/activation/via_template.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/src/virtualenv/activation/via_template.py b/src/virtualenv/activation/via_template.py
  --- a/src/virtualenv/activation/via_template.py
  +++ b/src/virtualenv/activation/via_template.py
  @@ -1,7 +1,9 @@
   from __future__ import absolute_import, unicode_literals
   
   import os
  +import re
   import sys
  +import sysconfig
   from abc import ABCMeta, abstractmethod
   
   from six import add_metaclass
  @@ -31,9 +33,17 @@
           return generated
   
       def replacements(self, creator, dest_folder):
  +        current_platform = sysconfig.get_platform()
  +        platforms = ["mingw", "cygwin", "msys"]
  +        if any(platform in current_platform for platform in platforms):
  +            pattern = re.compile("^([A-Za-z]):(.*)")
  +            match = pattern.match(str(creator.dest))
  +            virtual_env = "/" + match.group(1).lower() + match.group(2)
  +        else:
  +            virtual_env = str(creator.dest)
           return {
               "__VIRTUAL_PROMPT__": "" if self.flag_prompt is None else self.flag_prompt,
  -            "__VIRTUAL_ENV__": ensure_text(str(creator.dest)),
  +            "__VIRTUAL_ENV__": ensure_text(virtual_env),
               "__VIRTUAL_NAME__": creator.env_name,
               "__BIN_NAME__": ensure_text(str(creator.bin_dir.relative_to(creator.dest))),
               "__PATH_SEP__": ensure_text(os.pathsep),
  
verification_info: {"golden_diff": "diff --git a/src/virtualenv/activation/via_template.py b/src/virtualenv/activation/via_template.py\n--- a/src/virtualenv/activation/via_template.py\n+++ b/src/virtualenv/activation/via_template.py\n@@ -1,7 +1,9 @@\n from __future__ import absolute_import, unicode_literals\n \n import os\n+import re\n import sys\n+import sysconfig\n from abc import ABCMeta, abstractmethod\n \n from six import add_metaclass\n@@ -31,9 +33,17 @@\n         return generated\n \n     def replacements(self, creator, dest_folder):\n+        current_platform = sysconfig.get_platform()\n+        platforms = [\"mingw\", \"cygwin\", \"msys\"]\n+        if any(platform in current_platform for platform in platforms):\n+            pattern = re.compile(\"^([A-Za-z]):(.*)\")\n+            match = pattern.match(str(creator.dest))\n+            virtual_env = \"/\" + match.group(1).lower() + match.group(2)\n+        else:\n+            virtual_env = str(creator.dest)\n         return {\n             \"__VIRTUAL_PROMPT__\": \"\" if self.flag_prompt is None else self.flag_prompt,\n-            \"__VIRTUAL_ENV__\": ensure_text(str(creator.dest)),\n+            \"__VIRTUAL_ENV__\": ensure_text(virtual_env),\n             \"__VIRTUAL_NAME__\": creator.env_name,\n             \"__BIN_NAME__\": ensure_text(str(creator.bin_dir.relative_to(creator.dest))),\n             \"__PATH_SEP__\": ensure_text(os.pathsep),\n", "issue": "Cygwin and msys2 bash activator compatibility\n**Issue**\r\n\r\nRun the following via msys2:\r\n\r\n```\r\n$ /c/Users/builder/AppData/Local/Programs/Python/Python39/Scripts/virtualenv.exe --no-pip --no-setuptools --no-wheel -p /c/Users/builder/AppData/Local/Programs/Python/Python39/python.exe /tmp/tmp.uw7eZfvJIO\r\n$ source /tmp/tmp.uw7eZfvJIO/Scripts/activate\r\n$ python\r\npython: command not found\r\n```\r\n\r\nThe content of `/tmp/tmp.uw7eZfvJIO/Scripts/activate` contains `VIRTUAL_ENV='C:\\tools\\msys64\\tmp\\tmp.uw7eZfvJIO'`, but it's expected to be `VIRTUAL_ENV='/c/tools/msys64/tmp/tmp.uw7eZfvJIO'`, thus it can't locate `python`.\r\n\r\nI believe the legacy version handles this correctly here: https://github.com/pypa/virtualenv/blob/4c9899f471139670b0f1bfd359c37a67c507447d/virtualenv.py#L1742-L1748\r\n\r\nwhich contains:\r\n\r\n`VIRTUAL_ENV=\"$(if [ \"$OSTYPE\" \"==\" \"cygwin\" ]; then cygpath -u 'C:\\tools\\msys64\\tmp\\tmp.uw7eZfvJIO'; else echo '/C/tools/msys64/tmp/tmp.uw7eZfvJIO'; fi;)\"`\r\n\r\n**Environment**\r\n\r\nProvide at least:\r\n- OS: Windows 7, using msys2 v20200903.0.0\n", "before_files": [{"content": "from __future__ import absolute_import, unicode_literals\n\nimport os\nimport sys\nfrom abc import ABCMeta, abstractmethod\n\nfrom six import add_metaclass\n\nfrom virtualenv.util.six import ensure_text\n\nfrom .activator import Activator\n\nif sys.version_info >= (3, 7):\n    from importlib.resources import read_binary\nelse:\n    from importlib_resources import read_binary\n\n\n@add_metaclass(ABCMeta)\nclass ViaTemplateActivator(Activator):\n    @abstractmethod\n    def templates(self):\n        raise NotImplementedError\n\n    def generate(self, creator):\n        dest_folder = creator.bin_dir\n        replacements = self.replacements(creator, dest_folder)\n        generated = self._generate(replacements, self.templates(), dest_folder, creator)\n        if self.flag_prompt is not None:\n            creator.pyenv_cfg[\"prompt\"] = self.flag_prompt\n        return generated\n\n    def replacements(self, creator, dest_folder):\n        return {\n            \"__VIRTUAL_PROMPT__\": \"\" if self.flag_prompt is None else self.flag_prompt,\n            \"__VIRTUAL_ENV__\": ensure_text(str(creator.dest)),\n            \"__VIRTUAL_NAME__\": creator.env_name,\n            \"__BIN_NAME__\": ensure_text(str(creator.bin_dir.relative_to(creator.dest))),\n            \"__PATH_SEP__\": ensure_text(os.pathsep),\n        }\n\n    def _generate(self, replacements, templates, to_folder, creator):\n        generated = []\n        for template in templates:\n            text = self.instantiate_template(replacements, template, creator)\n            dest = to_folder / self.as_name(template)\n            # use write_bytes to avoid platform specific line normalization (\\n -> \\r\\n)\n            dest.write_bytes(text.encode(\"utf-8\"))\n            generated.append(dest)\n        return generated\n\n    def as_name(self, template):\n        return template.name\n\n    def instantiate_template(self, replacements, template, creator):\n        # read content as binary to avoid platform specific line normalization (\\n -> \\r\\n)\n        binary = read_binary(self.__module__, str(template))\n        text = binary.decode(\"utf-8\", errors=\"strict\")\n        for key, value in replacements.items():\n            value = self._repr_unicode(creator, value)\n            text = text.replace(key, value)\n        return text\n\n    @staticmethod\n    def _repr_unicode(creator, value):\n        # by default we just let it be unicode\n        return value\n", "path": "src/virtualenv/activation/via_template.py"}]}