Repository: spyder-ide/spyder

Issue:
Spyder prompts to install command line tools in macOS 
<!--- **PLEASE READ:** When submitting here, please ensure you've completed the following checklist and checked the boxes to confirm. Issue reports without it may be closed. Thanks! --->

### Issue Report Checklist

* [Y ] Searched the [issues page](https://github.com/spyder-ide/spyder/issues?q=is%3Aissue) for similar reports
* [Y] Read the relevant sections of the [Spyder Troubleshooting Guide](https://github.com/spyder-ide/spyder/wiki/Troubleshooting-Guide-and-FAQ) and followed its advice
* [Y] Reproduced the issue after updating with ``conda update spyder`` (or ``pip``, if not using Anaconda)
* [Y ] Could not reproduce inside ``jupyter qtconsole`` (if console-related)
* [Y ] Tried basic troubleshooting (if a bug/error)
    * [Y ] Restarted Spyder
    * [Y ] Reset preferences with ``spyder --reset``
    * [Y ] Reinstalled the latest version of [Anaconda](https://www.anaconda.com/download/)
    * [Y ] Tried the other applicable steps from the Troubleshooting Guide
* [Y ] Completed the **Problem Description**, **Steps to Reproduce** and **Version** sections below


## Problem Description
Installed the new version of spyder today. Everytime i click to a different tab a prompt appears as which asks to install Xcode, saying git is a part of Command Line Developer Tools. plz see the image I have attached. 
Its really annoying and I dont want to install Xcode. What can be done to remove this prompt to appear?


### What steps reproduce the problem?

1. Installed the latest version of spyder, which removed a lot of packages which i reinstalled manually using pip install
2. opening two or more files as different tabs and clicking any of them causes this to appear

## Versions
<!--- You can get this information from Help > About Spyder...
or (if Spyder won't launch) the "conda list" command
from the Anaconda Prompt/Terminal/command line. --->

* Spyder version: 4.1.1
* Python version: 3.7.0 64-bit
* Qt version: 5.12.7
* PyQt version: 5.12.3
* Operating System name/version: MacOs Mojave 10.14.6
![Error](https://user-images.githubusercontent.com/54612259/77912419-25ab1100-72b0-11ea-9a82-e4a49b8ce5df.jpg)





Discussion:
Did you install Spyder using your system Python? 
no the anaconda navigator
Then why did you use pip to install Spyder? I don't get it. 
ok, so first I tried updating through ipython in spyder itself which removed many packages like pandas, matplotlib, seaborn. then i removed it from anaconda navigator and re installed it, so it was a fresh install.
Still using the Python that comes with Anaconda? Or did you remove Anaconda completely? 

Please be more specific. 
Yes I am still using everything else as it is. Spyder was working fine with the older version but the problem started after i planned to update it. at first i tried:
1. pip install --update spyder (this created a lot of problems)
2. Removed spyder from anaconda nav
3. installed spyder from anaconda nav


> pip install --update spyder (this created a lot of problems)

I'm sure it did, and more so since you run it inside Spyder itself. Look, conda and pip packages are binary incompatible, so if you're using Anaconda you should avoid using pip as much as possible.

Besides our IPython console is not meant to run system commands like pip and conda, which must be run in Terminal.app.

Finally, you could have touched your system Python by using pip and that's why you're having this problem now.

Unfortunately we can't help you with the mess you did and the problem you're having now (you're the first person to report something like this). So simply accept to install the command line tools by clicking the Install button. That won't install Xcode, just some utilities that you'll find useful in the future anyway. 
> > pip install --update spyder (this created a lot of problems)
> 
> I'm sure it did, and more so since you run it inside Spyder itself. Look, conda and pip packages are binary incompatible, so if you're using Anaconda you should avoid using pip as much as possible.
> 
> Besides our IPython console is not meant to run system commands like pip and conda, which must be run in Terminal.app.
> 
> Finally, you could have touched your system Python by using pip and that's why you're having this problem now.
> 
> Unfortunately we can't help you with the mess you did and the problem you're having now (you're the first person to report something like this). So simply accept to install the command line tools by clicking the Install button. That won't install Xcode, just some utilities that you'll find useful in the future anyway.



Well, I admit I may have done it the wrong way. But I solved it, by downgrading it to version 3.6.
Thanks anyway.
### Problem Description
I have the same issue as the original poster exactly as previously described. I have a new mac laptop with a fresh install of the command line version of Anaconda3 and Spyder that have been updated using `conda update --all` and `conda update spyder` from the terminal command line. When I try and proceed with the installation, I get an error that says "Can’t install the software because it is not currently available from the Software Update server." I do recognize that I have an Mac OS update available and I am not connected to the App Store. I am borrowing this computer, so I do not plan on updating the OS or connecting to the App Store. Even though the installation fails, the message keeps popping up when I open Spyder and click on open file tabs. 

I recognize that a solution is to downgrade to Spyder 3.6, but I thought it would be useful to open this issue up again for Spyder 4 since in my case it is not due to an incorrect installation or pip usage. 

### Versions
Spyder version: 4.1.5
Python version: 3.8.1 64-bit
Qt version: 5.9.7
PyQt version: 5.9.2
Operating System name/version: MacOs Catalina 10.15.3
Hey @tfetherolf, thanks for the feedback and the details about your setup. I understand the hurdle this is causing for you to use Spyder. I'll reopen the issue and we'll try to fix it for our next release.
Hi @tfetherolf and @pydpyper. I've been trying to figure this out but I haven't really found a way to reproduce this error. However, it seems like the problem is the "git wrapper" mentioned in this issue https://github.com/docksal/docksal/issues/1003

Can you please try running this command `xcode_tools_dir=$(xcode-select -p 2>/dev/null) && ls ${xcode_tools_dir}/usr/bin/git` in your terminal and print here the output. This will give us a way to detect correctly whether git is installed or not and fix this problem in Spyder. 

@juanis2112 I get "Illegal variable name." when I try running that line in terminal, even when adding sudo at the beginning. Looking at the the thread you posted, `which git` does return `/usr/bin/git` and using `git --version` brings up the same pop-up window.

As an update to my previous post, I have my personal laptop back and it has been updated to macOS 10.15.7 and has the same issue. This laptop was returned to me with a factory reset (had to get a bunch of components replaced), so anaconda3+spyder4 were freshly installed on this computer as well. 
Are you using tcsh or csh in your command line? Cause I tried with these two and I get the same error. However it works fine in bash or zsh. Can you try running the command in any of these two?
@juanis2112 I do default use tcsh. I switched to bash and zsh and both successfully ran the xcod_tools_dir line, but there was no output. 
Sorry, my bad. You need to run `echo $?`after the previous command. 
Try: 
```
xcode_tools_dir=$(xcode-select -p 2>/dev/null) && ls ${xcode_tools_dir}/usr/bin/git
echo $?

```

Ah, right! The output is "2". This does not surprise me, since I have not done anything to install git or xcode.
That's great. It means we've figured out a way to check whether git is installed or not. I'll implement the fix as soon as possible so we don't have this error in our next version of spyder (4.2) to be released in November. 

Thank you very much for your help!

Resolving patch:
diff --git a/spyder/utils/programs.py b/spyder/utils/programs.py
--- a/spyder/utils/programs.py
+++ b/spyder/utils/programs.py
@@ -38,6 +38,7 @@
 from spyder.utils.misc import get_python_executable
 
 
+HERE = osp.abspath(osp.dirname(__file__))
 WINDOWS = os.name == 'nt'
 
 
@@ -1104,3 +1105,15 @@ def get_interpreter_info(path):
         out = ''
         err = ''
     return out.strip()
+
+
+def find_git():
+    """Find git executable in the system."""
+    if sys.platform == 'darwin':
+        proc = subprocess.run(
+            osp.join(HERE, "check-git.sh"), capture_output=True)
+        if proc.returncode != 0:
+            return None
+        return find_program('git')
+    else:
+        return find_program('git')
diff --git a/spyder/utils/vcs.py b/spyder/utils/vcs.py
--- a/spyder/utils/vcs.py
+++ b/spyder/utils/vcs.py
@@ -124,7 +124,7 @@ def get_git_revision(repopath):
     error
     """
     try:
-        git = programs.find_program('git')
+        git = programs.find_git()
         assert git is not None and osp.isdir(osp.join(repopath, '.git'))
         commit = programs.run_program(git, ['rev-parse', '--short', 'HEAD'],
                                       cwd=repopath).communicate()
@@ -163,7 +163,7 @@ def get_git_refs(repopath):
     if os.path.isfile(repopath):
         repopath = os.path.dirname(repopath)
 
-    git = programs.find_program('git')
+    git = programs.find_git()
 
     if git:
         try:


Test patch: