ExplodingCabbage / sublime-gitignorer

Sublime plugin that excludes from your Sublime project any files ignored by git
Do What The F*ck You Want To Public License
76 stars 11 forks source link

Add Windows support #1

Closed ExplodingCabbage closed 9 years ago

ExplodingCabbage commented 10 years ago

I have no idea presently what this would require. Currently all the stuff for interacting with Git is done by subprocess calling Unix programs; I don't know anything about the Windows shell, nor how Windows users use Git, so I don't know how easily (if it all) this logic translates to a Windows environment.

Perhaps using https://gitorious.org/git-python for all the Git-interacting code would solve this problem easily?

Rapptz commented 9 years ago

Hi. Just found this project through the Package Control main page.

The only thing that isn't available on Windows right off the bat would be find, right around here. However I don't know why you're using a subprocess for this. Python has functions to loop over the filesystem which would be better than invoking an entire process for this. Such as the os.path library and the os library.

The rest are git subcommands which are expected to be available for Windows users who have git anyway.

ExplodingCabbage commented 9 years ago

here ... I don't know why you're using a subprocess for this. Python has functions to loop over the filesystem which would be better than invoking an entire process for this.

Yeah, I just leapt on the first piece of code I could copy and paste from Google. It does indeed seem - even to me with almost zero knowledge of Python's filesystem APIs - pretty obviously ugly to be invoking Unix programs to perform basic file system operations.

I'll clean it up this afternoon.

ExplodingCabbage commented 9 years ago

This turns out to be a trickier problem than I thought.

The current master version of this plugin will spawn a command prompt window every 5 seconds if run on Windows.

GitPython is not the solution, as I just lost an hour to learn. At least one of its dependencies, async, doesn't support Python 3, which Sublime Text 3 uses - and it's abandoned, so that will never change. It's possible that I could work around this by using the current master version of async instead of an official release version, but I don't want to build a dependency into a hacked-together mish-mash of incomplete libraries with lots of open bugs into my code.

I'll need to figure out how to suppress that command prompt.

Rapptz commented 9 years ago

I looked at how the Git plugin does it and it seems that over here they set shell=True if os.name == "nt". Maybe try that? Along with what they seem to do. I know that the Git plugin works fine on both my Linux and Windows machine without launching a command prompt window.

ExplodingCabbage commented 9 years ago

Hey again @Rapptz. My last comment was more a note for myself, but thanks for the input - it's a helpful sanity check. I took a similar approach to the one you propose on a feature branch I need to polish off tonight and get merged back into master; you can see it here: https://github.com/ExplodingCabbage/sublime-gitignorer/blob/windows_maybe/gitignore_plugin.py

Basically I check for platform.system() == 'Windows' instead of os.name == "nt" and use a STARTUPINFO object to explicitly request no window instead of relying upon this being a side effect of shell=true. I don't know of any downside to doing things my way.

All that's left to polish off this issue is resolving some funkiness with path names:

Issue should all be resolved tonight.