Skip to content

Won't run on Windows #159

Closed
Closed

Description

@quentindemetz

I'm getting the following traceback:

(trojan) C:\trojan>Scripts\pre-commit.exe run
Traceback (most recent call last):
  File "C:\trojan\Scripts\pre-commit-script.py", line 9, in <module>
    load_entry_point('pre-commit==0.2.8', 'console_scripts', 'pre-commit')()
  File "C:\trojan\lib\site-packages\pkg_resources.py", line 356, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "C:\trojan\lib\site-packages\pkg_resources.py", line 2431, in load_entry_point
    return ep.load()
  File "C:\trojan\lib\site-packages\pkg_resources.py", line 2147, in load
    ['__name__'])
  File "C:\trojan\lib\site-packages\pre_commit\main.py", line 12, in <module>
    from pre_commit.commands.run import run
  File "C:\trojan\lib\site-packages\pre_commit\commands\run.py", line 11, in <module>
    from pre_commit.output import get_hook_message
  File "C:\trojan\lib\site-packages\pre_commit\output.py", line 11, in <module>
    ['tput', 'cols'], stdout=subprocess.PIPE
  File "C:\Python27\Lib\subprocess.py", line 710, in __init__
    errread, errwrite)
  File "C:\Python27\Lib\subprocess.py", line 958, in _execute_child
    startupinfo)
WindowsError: [Error 2] The system cannot find the file specified

Activity

  1. asottile commented on Sep 2, 2014

    @asottile
    Member

    Unfortunately I think windows support is pretty far from working due to the following things:

    Minimal to run a python based hook:

    • relies heavily on xargs ... | ... for running hooks
    • relies on sourcing an activate file for managing environments
    • relies on tput and ansi escapes for output

    The nice to haves that I don't know will work:

    • node support through nodeenv
    • ruby support through rbenv
  2. quentindemetz commented on Sep 2, 2014

    @quentindemetz
    Author

    Understood ;(

  3. asottile commented on Jan 19, 2015

    @asottile
    Member

    I started trying to get some of tests to pass here: https://github.com/pre-commit/pre-commit/tree/windoze

    The first wall I'm hitting is symlinks, which require elevated privileges by default under windows (wtf).

    I might rethink the one place I'm using symlinks and swap in something like sqlite instead (which might actually make everything simpler?).

    For xargs, etc. I think I can depend on powershell (who would develop on windows without powershell amirite?). Here's some recipes I found from googling: http://five.agency/powershell-tips-for-bash-users/

  4. asottile commented on Jan 19, 2015

    @asottile
    Member

    So I don't forget next time: pytest does not handle coloring well under powershell, use this in pytest.ini:

    [pytest]
    addopts = --color=no
    
  5. asottile commented on Jan 19, 2015

    @asottile
    Member

    Using git-shell (from github's windows downloads), I have pre-commit running! A bunch of the tests fail however and I'm not convinced that using github's tools constitutes supporting windows. But worst-case you can start using some of the hooks. I'm going to keep working on this branch and get more things passing.

  6. bukzor commented on Feb 5, 2015

    @bukzor

    I think it's fair to document git-shell as a dependency.

    There's also MinGW, cygwin. I think git-shell is a customized mingw.

  7. asottile commented on Feb 27, 2015

    @asottile
    Member

    Fixed via #196

    @quentindemetz let me know if this works for you

  8. asottile commented on Feb 27, 2015

    @asottile
    Member

    I've opened #198 #199 #200 #201 #202 for the features I didn't implement in the first pass.

  9. quentindemetz commented on Mar 8, 2015

    @quentindemetz
    Author

    @asottile git-shell is not supported on Windows XP, which is what I'm developing on…too bad

  10. asottile commented on Mar 8, 2015

    @asottile
    Member

    What implementation of git are you using?

  11. quentindemetz commented on Mar 8, 2015

    @quentindemetz
    Author

    I think it's msysgit
    This is the error I'm getting:

    (virtualenv) C:\project > pre-commit run --all-files
    [INFO]←[0m Installing environment for git://github.com/pre-commit/pre-commit-hooks.
    [INFO]←[0m Once installed this environment will be reused.
    [INFO]←[0m This may take a few minutes...
    An unexpected error has occurred: CalledProcessError: Command: ['bash', '-c', ". 'C:\\Documents and Settings\\IEUser\\.pre-commit\\repoobvhtq\\py_env\\Scripts\\activate' && cd 'C:\\Documents and Settings\\IEUser\\.pre-commit\\repoobvhtq\\' && pip install ."]
    Return code: 1
    Expected return code: 0
    Output: (none)
    Errors: (none)
    
    Check the log at ~/.pre-commit/pre-commit.log
    

    I don't know where to find the log mentioned in the last line:

    (virtualenv) C:\project > cd ~
    The system cannot find the path specified.
    

    Thanks

  12. asottile commented on Mar 8, 2015

    @asottile
    Member

    I'm going to grab a VM and see if I can reproduce this. ~ should be equivalent to C:\Documents and Settings\(your user name) on windows

  13. asottile commented on Mar 8, 2015

    @asottile
    Member

    Ah I see the issue. Under Windows XP, msysgit's install doesn't provide an executable named bash. I was however able to get this running and working with "git bash". Does what work for you?

  14. quentindemetz commented on Mar 8, 2015

    @quentindemetz
    Author

    I in fact do have some version of bash installed (I think I also have git bash installed, I'm not quite sure how to tell which is which).
    I've found the log, which isn't much more explanatory:

    An unexpected error has occurred: CalledProcessError: Command: ['bash', '-c', ". 'C:\\Documents and Settings\\IEUser\\.pre-commit\\repoobvhtq\\py_env\\Scripts\\activate' && cd 'C:\\Documents and Settings\\IEUser\\.pre-commit\\repoobvhtq\\' && pip install ."]
    Return code: 1
    Expected return code: 0
    Output: (none)
    Errors: (none)
    
    Traceback (most recent call last):
      File "C:\trojan\lib\site-packages\pre_commit\error_handler.py", line 34, in error_handler
        yield
      File "C:\trojan\lib\site-packages\pre_commit\main.py", line 129, in main
        return run(runner, args)
      File "C:\trojan\lib\site-packages\pre_commit\commands\run.py", line 165, in run
        return _run_hooks(runner, args, write=write, environ=environ)
      File "C:\trojan\lib\site-packages\pre_commit\commands\run.py", line 115, in _run_hooks
        for repo in runner.repositories:
      File "C:\trojan\lib\site-packages\cached_property.py", line 26, in __get__
        value = obj.__dict__[self.func.__name__] = self.func(obj)
      File "C:\trojan\lib\site-packages\pre_commit\runner.py", line 43, in repositories
        repository.require_installed()
      File "C:\trojan\lib\site-packages\pre_commit\repository.py", line 64, in require_installed
        self.install()
      File "C:\trojan\lib\site-packages\pre_commit\repository.py", line 96, in install
        language.install_environment(self.cmd_runner, language_version)
      File "C:\trojan\lib\site-packages\pre_commit\languages\python.py", line 51, in install_environment
        env.run("cd '{prefix}' && pip install .")
      File "C:\trojan\lib\site-packages\pre_commit\languages\helpers.py", line 42, in run
        ['bash', '-c', ' '.join([self.env_prefix, cmd])], **kwargs
      File "C:\trojan\lib\site-packages\pre_commit\prefixed_command_runner.py", line 41, in run
        return cmd_output(*replaced_cmd, __popen=self.__popen, **kwargs)
      File "C:\trojan\lib\site-packages\pre_commit\util.py", line 160, in cmd_output
        returncode, cmd, retcode, output=(stdout, stderr),
    CalledProcessError: Command: ['bash', '-c', ". 'C:\\Documents and Settings\\IEUser\\.pre-commit\\repoobvhtq\\py_env\\Scripts\\activate' && cd 'C:\\Documents and Settings\\IEUser\\.pre-commit\\repoobvhtq\\' && pip install ."]
    Return code: 1
    Expected return code: 0
    Output: (none)
    Errors: (none)
    

    Running the command manually doesn't give many hints:

    (virtualenv) C:\project>bash -c . 'C:\\Documents and Settings\\IEUser\\.pre-commit\\repoobvhtq\\py_env\\Scripts\\activate' && cd 'C:\\Documents and Settings\\IEUser\\.pre-commit\\repoobvhtq\\' && pip install .
    
    (virtualenv) C:\project>echo %errorlevel%
    1
    
  15. quentindemetz commented on Mar 8, 2015

    @quentindemetz
    Author

    Looks like there is no py_env in the 'C:\Documents and Settings\IEUser.pre-commit\repoobvhtq' folder.

  16. asottile commented on Mar 8, 2015

    @asottile
    Member

    Is that running with git bash as your shell or cmd as your shell?

  17. quentindemetz commented on Mar 8, 2015

    @quentindemetz
    Author

    With cmd.
    Looks like it's working with git bash, (some hooks run, others don't, it's complaining about not finding the correct pep8 version, but that's another story).

    Thanks ! Will use git bash from now on !

    (for reference here is the pep8 issue I'm getting)

    Traceback (most recent call last):
      File "c:\DOCUME~1\IEUser\PRE-CO~1\REPOOB~1\py_env\Scripts\end-of-file-fixer-script.py", line 5, in <module>
        from pkg_resources import load_entry_point
      File "C:\DOCUME~1\IEUser\PRE-CO~1\REPOOB~1\py_env\lib\site-packages\pkg_resources.py", line 2829, in <module>
        working_set = WorkingSet._build_master()
      File "C:\DOCUME~1\IEUser\PRE-CO~1\REPOOB~1\py_env\lib\site-packages\pkg_resources.py", line 451, in _build_master
        return cls._build_from_requirements(__requires__)
      File "C:\DOCUME~1\IEUser\PRE-CO~1\REPOOB~1\py_env\lib\site-packages\pkg_resources.py", line 464, in _build_from_requirements
        dists = ws.resolve(reqs, Environment())
      File "C:\DOCUME~1\IEUser\PRE-CO~1\REPOOB~1\py_env\lib\site-packages\pkg_resources.py", line 639, in resolve
        raise DistributionNotFound(req)
    pkg_resources.DistributionNotFound: pep8>=1.5.7,<1.6
    
  18. asottile commented on Mar 8, 2015

    @asottile
    Member

    Just fixed the pep8 conflict here: pre-commit/pre-commit-hooks@4078cbe

  19. quentindemetz commented on Mar 8, 2015

    @quentindemetz
    Author

    Fantastic, was just about to upgrade to the latest release of that repo, looks like I'll need to go as far as HEAD then. Thanks a million

  20. asottile commented on Mar 8, 2015

    @asottile
    Member

    I'm releasing 0.4.1 right now :)

  21. quentindemetz commented on Mar 8, 2015

    @quentindemetz
    Author

    😍

  22. guykisel commented on Mar 9, 2015

    @guykisel

    This might be a stupid idea, but is it possible to embed bash in pre-commit to remove that dependency on windows?

  23. asottile commented on Mar 9, 2015

    @asottile
    Member

    It'd be possible, but I'd rather not bundle all of msysgit when on windows I can expect most if not all of it to be installed :) (plus then I'd have to deal with the licensing issue)

  24. guykisel commented on Mar 9, 2015

    @guykisel

    I just want it to work in http://bliker.github.io/cmder/ on windows :(

    (though it's possible it does actually work and I'm just doing something wrong)

    When I try to use pre-commit in cmder I get this even though cmder supposedly has msysgit bundled in:

    Fix double quoted strings................................................Failed
    hookid: double-quote-string-fixer
    
    C:\Users\gkisel\.pre-commit\repodxm4yi\py_env\Scripts\activate: line 62: basename: command not found
    C:\Users\gkisel\.pre-commit\repodxm4yi\py_env\Scripts\activate: line 67: basename: command not found
    bash: xargs: command not found
    
  25. asottile commented on Apr 16, 2016

    @asottile
    Member

    @guykisel the latest version factors out bash and xargs so it should function better in cmder (0.8.0)

  26. guykisel commented on Apr 16, 2016

    @guykisel

    @asottile awesome! I'll give it a shot on Monday.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions