Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Won't run on Windows #159

Closed
quentindemetz opened this issue Sep 2, 2014 · 26 comments
Closed

Won't run on Windows #159

quentindemetz opened this issue Sep 2, 2014 · 26 comments

Comments

@quentindemetz
Copy link

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
@asottile
Copy link
Member

asottile commented Sep 2, 2014

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

@quentindemetz
Copy link
Author

Understood ;(

@asottile
Copy link
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/

@asottile
Copy link
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

@asottile
Copy link
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.

@bukzor
Copy link

bukzor commented Feb 5, 2015

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.

@asottile
Copy link
Member

Fixed via #196

@quentindemetz let me know if this works for you

@asottile
Copy link
Member

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

@quentindemetz
Copy link
Author

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

@asottile
Copy link
Member

asottile commented Mar 8, 2015

What implementation of git are you using?

@quentindemetz
Copy link
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

@asottile
Copy link
Member

asottile commented Mar 8, 2015

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

@asottile
Copy link
Member

asottile commented Mar 8, 2015

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?

@quentindemetz
Copy link
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

@quentindemetz
Copy link
Author

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

@asottile
Copy link
Member

asottile commented Mar 8, 2015

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

@quentindemetz
Copy link
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

@asottile
Copy link
Member

asottile commented Mar 8, 2015

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

@quentindemetz
Copy link
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

@asottile
Copy link
Member

asottile commented Mar 8, 2015

I'm releasing 0.4.1 right now :)

@quentindemetz
Copy link
Author

😍

@guykisel
Copy link

guykisel commented Mar 9, 2015

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

@asottile
Copy link
Member

asottile commented Mar 9, 2015

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)

@guykisel
Copy link

guykisel commented Mar 9, 2015

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

@asottile
Copy link
Member

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

@guykisel
Copy link

@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
Labels
None yet
Development

No branches or pull requests

4 participants