prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  `docker build` argument order is invalid on old versions of Docker
  We do: `docker build . --tag thing --label thing`
  
  But this produces an error on Docker 1.11.2:
  ```
  ckuehl@dev4-uswest1cdevc:~/proj/pre-commit$ docker build . --tag thing --label thing
  docker: "build" requires 1 argument.
  See 'docker build --help'.
  
  Usage:  docker build [OPTIONS] PATH | URL | -
  
  Build an image from a Dockerfile
  ```
  
  The path needs to go at the end on 1.11.2, but it works on 1.13.0 as-is. We should probably just change the order of the arguments to make every version happy.
  
  </issue>
  <code>
  [start of pre_commit/languages/docker.py]
  1 from __future__ import absolute_import
  2 from __future__ import unicode_literals
  3 
  4 import hashlib
  5 import os
  6 
  7 from pre_commit import five
  8 from pre_commit.languages import helpers
  9 from pre_commit.util import CalledProcessError
  10 from pre_commit.util import clean_path_on_failure
  11 from pre_commit.util import cmd_output
  12 from pre_commit.xargs import xargs
  13 
  14 
  15 ENVIRONMENT_DIR = 'docker'
  16 PRE_COMMIT_LABEL = 'PRE_COMMIT'
  17 
  18 
  19 def md5(s):  # pragma: windows no cover
  20     return hashlib.md5(five.to_bytes(s)).hexdigest()
  21 
  22 
  23 def docker_tag(repo_cmd_runner):  # pragma: windows no cover
  24     return 'pre-commit-{}'.format(
  25         md5(os.path.basename(repo_cmd_runner.path()))
  26     ).lower()
  27 
  28 
  29 def docker_is_running():  # pragma: windows no cover
  30     try:
  31         return cmd_output('docker', 'ps')[0] == 0
  32     except CalledProcessError:
  33         return False
  34 
  35 
  36 def assert_docker_available():  # pragma: windows no cover
  37     assert docker_is_running(), (
  38         'Docker is either not running or not configured in this environment'
  39     )
  40 
  41 
  42 def build_docker_image(repo_cmd_runner, **kwargs):  # pragma: windows no cover
  43     pull = kwargs.pop('pull')
  44     assert not kwargs, kwargs
  45     cmd = (
  46         'docker', 'build', '.',
  47         '--tag', docker_tag(repo_cmd_runner),
  48         '--label', PRE_COMMIT_LABEL,
  49     )
  50     if pull:
  51         cmd += ('--pull',)
  52     helpers.run_setup_cmd(repo_cmd_runner, cmd)
  53 
  54 
  55 def install_environment(
  56         repo_cmd_runner,
  57         version='default',
  58         additional_dependencies=(),
  59 ):  # pragma: windows no cover
  60     assert repo_cmd_runner.exists('Dockerfile'), (
  61         'No Dockerfile was found in the hook repository'
  62     )
  63     helpers.assert_version_default('docker', version)
  64     helpers.assert_no_additional_deps('docker', additional_dependencies)
  65     assert_docker_available()
  66 
  67     directory = repo_cmd_runner.path(
  68         helpers.environment_dir(ENVIRONMENT_DIR, 'default'),
  69     )
  70 
  71     # Docker doesn't really have relevant disk environment, but pre-commit
  72     # still needs to cleanup it's state files on failure
  73     with clean_path_on_failure(directory):
  74         build_docker_image(repo_cmd_runner, pull=True)
  75         os.mkdir(directory)
  76 
  77 
  78 def run_hook(repo_cmd_runner, hook, file_args):  # pragma: windows no cover
  79     assert_docker_available()
  80     # Rebuild the docker image in case it has gone missing, as many people do
  81     # automated cleanup of docker images.
  82     build_docker_image(repo_cmd_runner, pull=False)
  83 
  84     hook_cmd = helpers.to_cmd(hook)
  85     entry_executable, cmd_rest = hook_cmd[0], hook_cmd[1:]
  86 
  87     cmd = (
  88         'docker', 'run',
  89         '--rm',
  90         '-u', '{}:{}'.format(os.getuid(), os.getgid()),
  91         '-v', '{}:/src:rw'.format(os.getcwd()),
  92         '--workdir', '/src',
  93         '--entrypoint', entry_executable,
  94         docker_tag(repo_cmd_runner)
  95     ) + cmd_rest
  96 
  97     return xargs(cmd, file_args)
  98
  [end of pre_commit/languages/docker.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/pre_commit/languages/docker.py b/pre_commit/languages/docker.py
  --- a/pre_commit/languages/docker.py
  +++ b/pre_commit/languages/docker.py
  @@ -43,12 +43,14 @@
       pull = kwargs.pop('pull')
       assert not kwargs, kwargs
       cmd = (
  -        'docker', 'build', '.',
  +        'docker', 'build',
           '--tag', docker_tag(repo_cmd_runner),
           '--label', PRE_COMMIT_LABEL,
       )
       if pull:
           cmd += ('--pull',)
  +    # This must come last for old versions of docker.  See #477
  +    cmd += ('.',)
       helpers.run_setup_cmd(repo_cmd_runner, cmd)
  
verification_info: {"golden_diff": "diff --git a/pre_commit/languages/docker.py b/pre_commit/languages/docker.py\n--- a/pre_commit/languages/docker.py\n+++ b/pre_commit/languages/docker.py\n@@ -43,12 +43,14 @@\n     pull = kwargs.pop('pull')\n     assert not kwargs, kwargs\n     cmd = (\n-        'docker', 'build', '.',\n+        'docker', 'build',\n         '--tag', docker_tag(repo_cmd_runner),\n         '--label', PRE_COMMIT_LABEL,\n     )\n     if pull:\n         cmd += ('--pull',)\n+    # This must come last for old versions of docker.  See #477\n+    cmd += ('.',)\n     helpers.run_setup_cmd(repo_cmd_runner, cmd)\n", "issue": "`docker build` argument order is invalid on old versions of Docker\nWe do: `docker build . --tag thing --label thing`\r\n\r\nBut this produces an error on Docker 1.11.2:\r\n```\r\nckuehl@dev4-uswest1cdevc:~/proj/pre-commit$ docker build . --tag thing --label thing\r\ndocker: \"build\" requires 1 argument.\r\nSee 'docker build --help'.\r\n\r\nUsage:  docker build [OPTIONS] PATH | URL | -\r\n\r\nBuild an image from a Dockerfile\r\n```\r\n\r\nThe path needs to go at the end on 1.11.2, but it works on 1.13.0 as-is. We should probably just change the order of the arguments to make every version happy.\n", "before_files": [{"content": "from __future__ import absolute_import\nfrom __future__ import unicode_literals\n\nimport hashlib\nimport os\n\nfrom pre_commit import five\nfrom pre_commit.languages import helpers\nfrom pre_commit.util import CalledProcessError\nfrom pre_commit.util import clean_path_on_failure\nfrom pre_commit.util import cmd_output\nfrom pre_commit.xargs import xargs\n\n\nENVIRONMENT_DIR = 'docker'\nPRE_COMMIT_LABEL = 'PRE_COMMIT'\n\n\ndef md5(s):  # pragma: windows no cover\n    return hashlib.md5(five.to_bytes(s)).hexdigest()\n\n\ndef docker_tag(repo_cmd_runner):  # pragma: windows no cover\n    return 'pre-commit-{}'.format(\n        md5(os.path.basename(repo_cmd_runner.path()))\n    ).lower()\n\n\ndef docker_is_running():  # pragma: windows no cover\n    try:\n        return cmd_output('docker', 'ps')[0] == 0\n    except CalledProcessError:\n        return False\n\n\ndef assert_docker_available():  # pragma: windows no cover\n    assert docker_is_running(), (\n        'Docker is either not running or not configured in this environment'\n    )\n\n\ndef build_docker_image(repo_cmd_runner, **kwargs):  # pragma: windows no cover\n    pull = kwargs.pop('pull')\n    assert not kwargs, kwargs\n    cmd = (\n        'docker', 'build', '.',\n        '--tag', docker_tag(repo_cmd_runner),\n        '--label', PRE_COMMIT_LABEL,\n    )\n    if pull:\n        cmd += ('--pull',)\n    helpers.run_setup_cmd(repo_cmd_runner, cmd)\n\n\ndef install_environment(\n        repo_cmd_runner,\n        version='default',\n        additional_dependencies=(),\n):  # pragma: windows no cover\n    assert repo_cmd_runner.exists('Dockerfile'), (\n        'No Dockerfile was found in the hook repository'\n    )\n    helpers.assert_version_default('docker', version)\n    helpers.assert_no_additional_deps('docker', additional_dependencies)\n    assert_docker_available()\n\n    directory = repo_cmd_runner.path(\n        helpers.environment_dir(ENVIRONMENT_DIR, 'default'),\n    )\n\n    # Docker doesn't really have relevant disk environment, but pre-commit\n    # still needs to cleanup it's state files on failure\n    with clean_path_on_failure(directory):\n        build_docker_image(repo_cmd_runner, pull=True)\n        os.mkdir(directory)\n\n\ndef run_hook(repo_cmd_runner, hook, file_args):  # pragma: windows no cover\n    assert_docker_available()\n    # Rebuild the docker image in case it has gone missing, as many people do\n    # automated cleanup of docker images.\n    build_docker_image(repo_cmd_runner, pull=False)\n\n    hook_cmd = helpers.to_cmd(hook)\n    entry_executable, cmd_rest = hook_cmd[0], hook_cmd[1:]\n\n    cmd = (\n        'docker', 'run',\n        '--rm',\n        '-u', '{}:{}'.format(os.getuid(), os.getgid()),\n        '-v', '{}:/src:rw'.format(os.getcwd()),\n        '--workdir', '/src',\n        '--entrypoint', entry_executable,\n        docker_tag(repo_cmd_runner)\n    ) + cmd_rest\n\n    return xargs(cmd, file_args)\n", "path": "pre_commit/languages/docker.py"}]}