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

Spyder is unable to detect git if installed with msysgit (Microsoft Windows PC's) #1333

Closed
spyder-bot opened this issue Feb 17, 2015 · 21 comments

Comments

@spyder-bot
Copy link
Collaborator

From bwanama...@gmail.com on 2013-03-26T02:47:01Z

Please note that reporting bugs from Spyder's help menu ("?" > "Report
issue...") will fill version details for Spyder, Python and Qt in this description for you.

What steps will reproduce the problem?

  1. right click on project with .git
    1. select commit
    2. or select browse repository What is the expected output? What do you see instead? expected: if msysgit is installed with default settings and not on path, then user receives message: please install git gui or gitk
      instead: git-gui or gitk opens What version of the product are you using? On what operating system? spyder-2.1.13.1
      windows 7 x64, windows xp x64
      python-2.7.3 (amd64)
      msysgit-1.8.1.2

Please provide any additional information below

. Here is a patch that can be used on any system.

  • It adds shell commands to the list of git tool commands in the SCM_INFOS global,
  • looks for msysgit if run_scm_tool is passed with infos['name'] == 'git' and adds msysgit's path to os.environ['PATH'],
  • and wraps run_program in try-except-else block that catches WindowsError, since gitk is a shell program, continues to the next pair of (name, args) in infos[tool] but raises error if winerror != 193 (%1 is not valid win32 application)

I also posted about this here: https://groups.google.com/forum/?fromgroups=#!topic/spyderlib/5X6uVWiKTow spyderlib_utils_scm.patch (also attached)
--- /c/Python27/lib/site-packages/spyderlib/utils/scm.orig Sat Jan 5 06:31:28 2013
+++ /c/Python27/lib/site-packages/spyderlib/utils/scm.py Tue Mar 26 00:10:05 2013
@@ -6,6 +6,7 @@

"""SCM utilities"""

+import os
import os.path as osp

Local imports

@@ -22,8 +23,10 @@
('hgtk', ['log']) )
),
'.git': dict(name="git",

  •                      commit=( ('git', ['gui']), ),
    
  •                      browse=( ('gitk', []), )
    
  •                      commit=( ('git', ['gui']),
    
  •                               ('sh', ['--login', '-c', 'git gui']), ),
    
  •                      browse=( ('gitk', []),
    
  •                               ('sh', ['--login', '-c', 'gitk']) )
                       ),
          }
    

@@ -59,10 +62,28 @@
Supported SCM tools: 'commit', 'browse'
Return False if the SCM tool is not installed"""
infos = get_scm_infos(get_scm_root(path))

  • if git and windows, then check for msysgit and add to path

  • if infos['name'] == 'git' and os.name == 'nt':
  •    if os.environ["PROCESSOR_ARCHITECTURE"] == "AMD64":
    
  •        programfiles = "%PROGRAMFILES(X86)%"
    
  •    else:
    
  •        programfiles = "%PROGRAMFILES%"
    
  •    programfiles = osp.expandvars(programfiles)
    
  •    git_bin_path = osp.join(programfiles, 'Git', 'bin')
    
  •    windows_path = os.environ['PATH']
    
  •    os.environ['PATH'] = os.pathsep.join([windows_path, git_bin_path])
    
    for name, args in infos[tool]:
    if programs.find_program(name):
  •        programs.run_program(name, args, cwd=path)
    
  •        return
    
  •        try:
    
  •            programs.run_program(name, args, cwd=path)
    
  •        except WindowsError as windows_error:
    
  •            if windows_error.winerror == 193:
    
  •                # [Error 193] %1 is not a valid Win32 application
    
  •                continue
    
  •            else:
    
  •                raise windows_error
    
  •        else:
    
  •            return
    
    else:
    raise RuntimeError(_("Please install the %s tool named '%s'")
    % (infos['name'], name))

Attachment: spyderlib_utils_scm.patch

Original issue: http://code.google.com/p/spyderlib/issues/detail?id=1333

@spyder-bot spyder-bot added this to the v2.2.1 milestone Feb 17, 2015
@spyder-bot
Copy link
Collaborator Author

From bwanama...@gmail.com on 2013-03-26T01:44:44Z

It also makes sense to add:

if git_bin_path.lower() not in windows_path.lower().split(os.pathsep):

before changing the path, so that people who have add msysgit to their windows path, don't need to add it again!

e.g.

@@ -59,10 +62,28 @@
Supported SCM tools: 'commit', 'browse'
Return False if the SCM tool is not installed"""
infos = get_scm_infos(get_scm_root(path))

  • if git and windows, then check for msysgit and add to path

  • if infos['name'] == 'git' and os.name == 'nt':
  •    if os.environ["PROCESSOR_ARCHITECTURE"] == "AMD64":
    
  •        programfiles = "%PROGRAMFILES(X86)%"
    
  •    else:
    
  •        programfiles = "%PROGRAMFILES%"
    
  •    programfiles = osp.expandvars(programfiles)
    
  •    git_bin_path = osp.join(programfiles, 'Git', 'bin')
    
  •    windows_path = os.environ['PATH']
    
  •    if git_bin_path.lower() not in windows_path.lower().split(os.pathsep):
    
  •        os.environ['PATH'] = os.pathsep.join([windows_path, git_bin_path])
    
    for name, args in infos[tool]:
    if programs.find_program(name):
  •        programs.run_program(name, args, cwd=path)
    
  •        return
    
  •        try:
    
  •            programs.run_program(name, args, cwd=path)
    
  •        except WindowsError as windows_error:
    
  •            if windows_error.winerror == 193:
    
  •                # [Error 193] %1 is not a valid Win32 application
    
  •                continue
    
  •            else:
    
  •                raise windows_error
    
  •        else:
    
  •            return
    
    else:
    raise RuntimeError(_("Please install the %s tool named '%s'")
    % (infos['name'], name))

@spyder-bot
Copy link
Collaborator Author

From bwanama...@gmail.com on 2013-03-26T01:47:19Z

note also if you have added ssh-agent to your .bashrc, then you will have to view the attached windows console to enter your passphrase when prompted. This is under view menu.

@spyder-bot
Copy link
Collaborator Author

From bwanama...@gmail.com on 2013-04-02T10:48:32Z

I've attached an updated patch (_r2) which adds the check for msysgit in path, before adding it, so that it isn't added if it is already in the path.

I've tested it on windows 7 x64 and it works, I will try to make sure it also works on ubuntu-12.10 later, but I don't see why it wouldn't as it only adds the commands for windows, and adds the path if it is a windows machine.

also would need testing on windows x86 machine.

here is the text:

--- scm.orig Sat Jan 5 06:31:28 2013
+++ scm.py Tue Apr 2 10:22:35 2013
@@ -6,6 +6,7 @@

"""SCM utilities"""

+import os
import os.path as osp

Local imports

@@ -22,8 +23,10 @@
('hgtk', ['log']) )
),
'.git': dict(name="git",

  •                      commit=( ('git', ['gui']), ),
    
  •                      browse=( ('gitk', []), )
    
  •                      commit=( ('git', ['gui']),
    
  •                               ('sh', ['--login', '-c', 'git gui']), ),
    
  •                      browse=( ('gitk', []),
    
  •                               ('sh', ['--login', '-c', 'gitk']) )
                       ),
          }
    

@@ -59,10 +62,29 @@
Supported SCM tools: 'commit', 'browse'
Return False if the SCM tool is not installed"""
infos = get_scm_infos(get_scm_root(path))

  • if git and windows, then check for msysgit and add to path

  • if infos['name'] == 'git' and os.name == 'nt':
  •    if os.environ["PROCESSOR_ARCHITECTURE"] == "AMD64":
    
  •        programfiles = "%PROGRAMFILES(X86)%"
    
  •    else:
    
  •        programfiles = "%PROGRAMFILES%"
    
  •    programfiles = osp.expandvars(programfiles)
    
  •    git_bin_path = osp.join(programfiles, 'Git', 'bin')
    
  •    windows_path = os.environ['PATH']
    
  •    if git_bin_path.lower() not in windows_path.lower().split(os.pathsep):
    
  •        os.environ['PATH'] = os.pathsep.join([windows_path, git_bin_path])
    
    for name, args in infos[tool]:
    if programs.find_program(name):
  •        programs.run_program(name, args, cwd=path)
    
  •        return
    
  •        try:
    
  •            programs.run_program(name, args, cwd=path)
    
  •        except WindowsError as windows_error:
    
  •            if windows_error.winerror == 193:
    
  •                # [Error 193] %1 is not a valid Win32 application
    
  •                continue
    
  •            else:
    
  •                raise windows_error
    
  •        else:
    
  •            return
    
    else:
    raise RuntimeError(_("Please install the %s tool named '%s'")
    % (infos['name'], name))

Attachment: spyderlib_utils_scm_r2.patch

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2013-04-11T11:25:27Z

Thanks a lot for the patch! I'll review and merge it after 2.2 is released. Thanks for your patience.

Labels: OpSys-Windows Cat-ProjectExplorer MS-v2.2

@spyder-bot
Copy link
Collaborator Author

From jed.lud...@gmail.com on 2013-04-29T15:08:37Z

Labels: MS-v2.2.1

@spyder-bot
Copy link
Collaborator Author

From jed.lud...@gmail.com on 2013-04-29T15:10:06Z

Labels: -MS-v2.2

@spyder-bot
Copy link
Collaborator Author

From bwanama...@gmail.com on 2013-05-28T20:54:03Z

I hope this (or another approach to integrate git scm) happens at some indeterminate point in the near future. Thanks!

Here the latest patch. I tried to stay true to the approach used in the original scm.py file. There are 3 edit's plus the import of os.
(1) The first edit adds msysgit commands for git-gui and gitk using sh.exe to the commit and bowse tuples.
(2) The next set of edits check for windows, OS-arch (x86 or x64) and adds Git to the user's path if it's not already.
(3) Finally "run_program" is wrapped in a try-except block to catch and skip Window's error 193, which indicates that the binary is not a native win32 application. Gitk and git-gui need to be run via sh.exe, so continue the for loop and advance to the next options, which are the same commands called via sh.exe. Voila! Gitk and git-gui now work in windows, without any fuss.

The only catch is if the user has added the classic cygwin ssh-agent/ssh-add-key script to their .bashrc and their ssh key has a passphrase, in which case they should use the option to view the terminal window from the spyderlib menu bar, and enter their ssh passphrase for the first use.

Hope that helps the review process along!

Attachment: spyderlib.utils.scm.py.patch

@spyder-bot
Copy link
Collaborator Author

From jed.lud...@gmail.com on 2013-06-01T13:56:49Z

I've been reviewing this patch, and I have a couple of questions.

First, is the primary need for this patch because git isn't on the Windows path? If so, is there a particular reason why simply adding it to your path isn't an option?

Second, I'm not sure it's safe to assume that all x64 systems will have msysgit installed in 'Program Files'. In my case, I actually have 32-bit msysgit installed on my x64 Windows 7. So there may need to be some different magic there to find git.

@spyder-bot
Copy link
Collaborator Author

From jed.lud...@gmail.com on 2013-06-01T22:08:02Z

After looking further, it seems the msysgit installer typically adds c:\Program Files\Git\cmd to the Windows path rather then c:\Program Files\Git\bin when you ask for it to add itself to the path at install time. That folder contains Windows executables for git.exe and gitk.exe. If we pointed to these commands instead of sh.exe in \bin there would be no need to handle the windows error. Not sure how the ssh key business would behave. Were you specifically trying to run the git commands through sh.exe as opposed to the Windows flavors of git.exe and gitk.exe?

And I'm still a little confused about the original issue report. Should the "expected" and "instead" descriptions actually be swapped with each other? Just trying to make sure I really understand the problem we are trying to solve.

@spyder-bot
Copy link
Collaborator Author

From bwanama...@gmail.com on 2013-06-01T22:27:30Z

Responses inline

(Microsoft Windows PC's)

Windows path? If so, is there a particular reason why simply adding it to
your path isn't an option?

Yes and no. One of the two binaries (git-gui) is a native win32
application, but the other (gitk) is a shell script and and throws a
Windows error when called from subprocess, but if called from sh.exe it
runs fine. So no, just adding the Git bin folder does not solve the problem.
The Git bin folder also contains several MSYS versions of Linux utilities
like find which conflict with MS Windows utilities that happen to have
the same name, so it's not recommended to add it to the widows path.
Instead it's used in an MSYS shell "Git-Bash" or apps like TortoiseGit know
its path, or have an option to set its path.

msysgit installed in 'Program Files'. In my case, I actually have 32-bit
msysgit installed on my x64 Windows 7. So there may need to be some
different magic there to find git.

msysgit is an x86 application, not x64, so the default install folder on
x86 should be Program Files and on x64 would be Program Files (x86).
Those are the folders used in the patch, it checks the os.environ
ARCHITECTURE key for amd64 or x86. True tho there should be a way to
override this b/c user may choose different install location.

@spyder-bot
Copy link
Collaborator Author

From bwanama...@gmail.com on 2013-06-01T22:36:30Z

(Microsoft Windows PC's)

c:\Program Files\Git\cmd to the Windows path rather then c:\Program
Files\Git\bin when you ask for it to add itself to the path at install
time. That folder contains Windows executables for git.exe and gitk.exe. If
we pointed to these commands instead of sh.exe in \bin there would be no
need to handle the windows error. Not sure how the ssh key business would
behave. Were you specifically trying to run the git commands through sh.exe
as opposed to the Windows flavors of git.exe and gitk.exe?

Didn't know about git/cmd folder. So there's a win32 version of gitk, I'll
have to check if that's on my machine. I've never used the 'add git to my
path' installation option b/c it conflicts with windows utilities like
find. Users are specifically warned of this during msysgit installation
with nasty red text. I think most users will opt to either add the path to
os.environ["path"] after starting spyder or just jockey between git bash
and spyder.

the "expected" and "instead" descriptions actually be swapped with each
other? Just trying to make sure I really understand the problem we are
trying to solve.

Oops. My bad. I reversed expected and instead. IE: "expected" should have
been "gitk or gitgui open" & "instead" should have been "if git/bin not on
path, then message says pls. install git". So sorry!

@spyder-bot
Copy link
Collaborator Author

From jed.lud...@gmail.com on 2013-06-01T23:02:05Z

Yes, I remember the scary red text at install time. It looks as though adding this \cmd directory might be a less invasive option since only git.exe and gitk.exe get added to the path instead of everything below \bin. Please do check to see if the \cmd path is available on your install. This seems like a better place to be pointing Spyder since it contains native executables for the commands in question.

@spyder-bot
Copy link
Collaborator Author

From bwanama...@gmail.com on 2013-06-01T23:10:03Z

(Microsoft Windows PC's)

adding this \cmd directory might be a less invasive option since only
git.exe and gitk.exe get added to the path instead of everything below
\bin. Please do check to see if the \cmd path is available on your install.
This seems like a better place to be pointing Spyder since it contains
native executables for the commands in question.

Cool, so we can leave the original spyder git comnands alone, (IE do
not add sh.exe) and then just add git/cmd to os.environ["path"] if it's
not already there.

Not calling sh.exe would skip the cygwin ssh-agent script b/c it's in
bashrc.

Then the only question left is do we assume git/cmd is always in either
"Program Files" for 32-bit windows and "Program Files (x86)" for 64-bit
windows, or is there an option somewhere for users to override that?

@spyder-bot
Copy link
Collaborator Author

From bwanama...@gmail.com on 2013-06-02T09:45:58Z

I will check if my msysgit install has git/cmd and if so I'll add it to my
windows path w/o any spyder patches and close this issue. Thx.

@spyder-bot
Copy link
Collaborator Author

From bwanama...@gmail.com on 2013-06-03T10:29:36Z

Jed,
Thanks!
For me (on MS Windows) adding "C:\Program Files (x86)\Git\cmd" to my MS Windows Path completely resolved this issues without any side effects. If you agree, I think this issue can be closed, and maybe a note in the wiki and/or documentation should be added.

--Mark
" http://www.codinghorror.com/blog/2007/05/the-best-code-is-no-code-at-all.html "

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2013-06-10T09:18:37Z

Jed, do you agree with Mark's suggestion?

The thing is changing env vars on Windows it's no so easy. Perhaps we should report an issue with msysgit guys so they add that dir to PATH with their installer?

Cc: jed.lud...@gmail.com

@spyder-bot
Copy link
Collaborator Author

From jed.lud...@gmail.com on 2013-06-10T18:19:25Z

Yes, I agree that solving this problem without adding code is the right approach. I haven't had an opportunity to add some documentation yet.

The msysgit installer already has a provision for modifying the Windows path, but the user has to make a decision about it. See attached. The second option does the trick.

@spyder-bot
Copy link
Collaborator Author

From jed.lud...@gmail.com on 2013-06-10T18:21:00Z

Sorry. Attachment didn't take the last time.

Attachment: git_install_dialog.PNG

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2013-06-28T05:51:49Z

Jed, could you please take a look at this one? I think a very simple wiki page explaining how to install msysgit so that Spyder can detect it would be enough.

@spyder-bot
Copy link
Collaborator Author

From jed.lud...@gmail.com on 2013-07-03T09:11:19Z

This issue was updated by revision 6c2a7a424f60 .

Added version control integration subsection to Project Explorer section of the
documentation. Includes comments about correctly configuring msysgit on
Windows so that git and gitk commands are on the system path.

Status: Fixed

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2013-07-06T21:50:21Z

Summary: Spyder is unable to detect git if installed with msysgit (Microsoft Windows PC's) (was: patch for msysgit (Microsoft Windows PC's))

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

No branches or pull requests

1 participant