Repository: pre-commit/pre-commit

Issue:
Docker language fails on Windows - os.getuid()
[`docker_cmd`](https://github.com/pre-commit/pre-commit/blob/0cf2638b3b6a2cfde89cb7013e61b2d4a3e12875/pre_commit/languages/docker.py#L80) in languages/docker.py uses `os.getuid()` and `os.getgid()` that don't exist in Python on Windows.

A hook that uses Docker on Windows fails to execute with

```
An unexpected error has occurred: AttributeError: module 'os' has no attribute 'getuid'
Traceback (most recent call last):
  File "C:\Python36\lib\site-packages\pre_commit\error_handler.py", line 46, in error_handler
    yield
  File "C:\Python36\lib\site-packages\pre_commit\main.py", line 294, in main
    return run(args.config, store, args)
  File "C:\Python36\lib\site-packages\pre_commit\commands\run.py", line 293, in run
    return _run_hooks(config, hooks, args, environ)
  File "C:\Python36\lib\site-packages\pre_commit\commands\run.py", line 214, in _run_hooks
    retval |= _run_single_hook(classifier, hook, args, skips, cols)
  File "C:\Python36\lib\site-packages\pre_commit\commands\run.py", line 124, in _run_single_hook
    tuple(filenames) if hook.pass_filenames else (),
  File "C:\Python36\lib\site-packages\pre_commit\repository.py", line 100, in run
    return lang.run_hook(self, file_args)
  File "C:\Python36\lib\site-packages\pre_commit\languages\docker.py", line 99, in run_hook
    cmd = docker_cmd() + entry_tag + cmd_rest
  File "C:\Python36\lib\site-packages\pre_commit\languages\docker.py", line 80, in docker_cmd
    '-u', '{}:{}'.format(os.getuid(), os.getgid()),
AttributeError: module 'os' has no attribute 'getuid'
```

The same hook works fine in Windows Subsystem for Linux.


Discussion:
makes sense, I haven't been able to get testing for docker on windows set up just yet -- not sure what the right thing to put for that argument is to be honest.  The current support suggests only [macos and linux](https://pre-commit.com/#docker) for now

I'd be open to a patch if you'd like to get one working!

Resolving patch:
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
@@ -73,11 +73,18 @@ def install_environment(
         os.mkdir(directory)
 
 
+def get_docker_user():  # pragma: windows no cover
+    try:
+        return '{}:{}'.format(os.getuid(), os.getgid())
+    except AttributeError:
+        return '1000:1000'
+
+
 def docker_cmd():  # pragma: windows no cover
     return (
         'docker', 'run',
         '--rm',
-        '-u', '{}:{}'.format(os.getuid(), os.getgid()),
+        '-u', get_docker_user(),
         # https://docs.docker.com/engine/reference/commandline/run/#mount-volumes-from-container-volumes-from
         # The `Z` option tells Docker to label the content with a private
         # unshared label. Only the current container can use a private volume.


Test patch:
diff --git a/tests/languages/docker_test.py b/tests/languages/docker_test.py
--- a/tests/languages/docker_test.py
+++ b/tests/languages/docker_test.py
@@ -13,3 +13,14 @@ def test_docker_is_running_process_error():
         side_effect=CalledProcessError(*(None,) * 4),
     ):
         assert docker.docker_is_running() is False
+
+
+def test_docker_fallback_user():
+    def invalid_attribute():
+        raise AttributeError
+    with mock.patch.multiple(
+        'os', create=True,
+        getuid=invalid_attribute,
+        getgid=invalid_attribute,
+    ):
+        assert docker.get_docker_user() == '1000:1000'