Repository: spyder-ide/spyder

Issue:
Spyder doesn't open on MyBinder
### Issue Report Checklist

* [x] Searched the [issues page](https://github.com/spyder-ide/spyder/issues?q=is%3Aissue) for similar reports
* [x] Completed the **Problem Description** & **Steps to Reproduce**

## Problem Description

Spyder never opens in MyBinder sessions launched from this repo presently. 

When the sessions opens and you double click on the Spyder icon on the left side of the screen it doesn't open like it should. Splash screen never comes up and there is no indication though. You just wait forever for nothing, it seems.

### What steps reproduce the problem?

1.  Try opening Spyder in sessions launched from https://mybinder.org/v2/gh/spyder-ide/spyder/master?urlpath=%2Fdesktop (which is the default link on the main page and uses the last commit ([Oct 11](https://github.com/spyder-ide/spyder/commits/master/binder)) by default.). Spyder FAILS to open in the session. It just hangs forever with the splash screen never coming up. No error is shown.

3. If you try launching with the previous commit, Spyder still opens by double-clicking on the icon in such sessions. The splash screen comes up after several seconds and Spyder opens. STILL WORKS using Aug 29th version at https://github.com/spyder-ide/spyder/commit/a3f49fa9ba51f40e6fe1e8d52768265b1da2f21f. The link to launch is:
https://mybinder.org/v2/gh/spyder-ide/spyder/a3f49fa9ba51f40e6fe1e8d52768265b1da2f21f?urlpath=%2Fdesktop

### Underlying cause?

It seems like the change was small in the binder directory, and so there is a chance it is something else **and not simply what was changed there**? I'm not quite sure. I only tried the October 11th commit (actually did it specifically, as well, and not just default) and the August 29th ones because that was only changes showing when I clicking into the binder directory.     

I did note someone else did make an issue post a few days ago saying they were seeing Spyder not opening, but that seemed to get sorted.



Discussion:
Hi @fomightez thanks for the feedback! Checking seems like an error is being raised at launch:

![imagen](https://user-images.githubusercontent.com/16781833/195916427-0bd7f8b6-dcd5-483e-b987-3489d60f5e85.png)

Could this be related with the changes done on the `bootstrap.py`  script recently @ccordoba12 @mrclary ? Maybe we need to change the shortcut to use the home directory as working directory so `spyder` is available as a module?
I did try running that in the terminal, too. I should have added that since I did see that error. But I did that before I saw the old ones were working, and so I didn't know if I was on the right or wrong path there.  
*In theory*, your idea sounds good. However, I still don't see what broke it in the last couple of weeks, and so it's hard to say.  It seemed to work running in the Desktop before and I'm not seeing what would have changed to alter that.
I'm not very familiar with Binder. How do you access it? Where is "the default link on the main page"? How do you build the image for an arbitrary commit or branch?
I tried building it [here](https://github.com/spyder-ide/spyder/pull/15761#issuecomment-1279385574), but it fails to build/launch.
The `launch binder` badge features on the main page right below 'Project status' [here](https://github.com/spyder-ide/spyder#project-status). It equates to the same link I placed above.

To build for specific commits or branches go to the form [here](https://mybinder.org/) and fill it out. Where 'Git ref' is you can specify branch name or commit SHA.

The branch has to exist. Above where you link to the using 'here' in your comment, i.e. [here](https://github.com/spyder-ide/spyder/pull/15761#issuecomment-1279385574), it says "[mwawra](https://github.com/mwawra) deleted the issue-15709-pylint-interpreter branch [2 days ago](https://github.com/spyder-ide/spyder/pull/15761#event-7572155251)"
> The `launch binder` badge features on the main page right below 'Project status' [here](https://github.com/spyder-ide/spyder#project-status). It equates to the same link I placed above.

Aahh! okay, thanks.

> To build for specific commits or branches go to the form [here](https://mybinder.org/) and fill it out. Where 'Git ref' is you can specify branch name or commit SHA.

Yeah, I tried that and it didn't work... do you have a screen shot of a filled out form that yields a successful build?


I tried 5.x
Should be https://mybinder.org/v2/gh/spyder-ide/spyder/5.x?urlpath=%2Fdesktop ?
It starts a JupyterLab application, not a desktop with a Spyder shortcut
Yes, the default form is for general usage. There's other tricks. You want:  
https://mybinder.org/v2/gh/spyder-ide/spyder/5.x?urlpath=%2Fdesktop
> Should be https://mybinder.org/v2/gh/spyder-ide/spyder/5.x?urlpath=%2Fdesktop ?

Nope, I get https://mybinder.org/v2/gh/spyder-ide/spyder/5.x
What am I doing wrong?
So I have to manually add `?urlpath=%2Fdesktop`?
Yes.  
Or you can type `/desktop` in where it says 'Path to a notebook file', but then you still have to change `labpath` to `urlpath`. So you might as well just append.

The Spyder application still never opens with the 5.x branch. 4.x branch is fine.
@fomightez, thanks for your help. I got binder working. I hid our comments just to keep this issue discussion cleaner.
@dalthviz, you are correct; the offending PR is #19742.
There are two issues:
- The recent changes to `bootstrap.py` for detecting changes to/from the master branch use `spyder` utilities. Since the import occurs before `install_dev_repos`, it is implicitly assumed that `spyder` is already installed, which is not the case for the Binder environment. This may also be a problem for other developer environments under certain circumstances.
- The recent changes to `bootstrap.py` have an explicit reference to `'spyder'` as the assumed repository name. Since Binder places the repository contents directly into the home directory, the repository name is not `'spyder'` but `'jovyan'`.

Possible solution:
Remove dependence of `spyder` in `bootstrap.py` prior to invocation of `install_dev_repos`
- Reference to the repository name (`DEVPATH.name`) should be obtained from `install_dev_repos`
- Use `subprocess` directly to invoke `git` instead of `find_git` and `run_program`
- The `boot_branch.txt` file should be placed in the repository at the top level instead of Spyder's configuration directory, and it will have to be `.gitignore`d

Resolving patch:
diff --git a/bootstrap.py b/bootstrap.py
--- a/bootstrap.py
+++ b/bootstrap.py
@@ -28,11 +28,7 @@
 from logging import Formatter, StreamHandler, getLogger
 from pathlib import Path
 
-# Local imports
-from install_dev_repos import REPOS, install_repo
-from spyder import get_versions
-from spyder.config.base import get_conf_path
-from spyder.utils.programs import find_git, run_program
+from install_dev_repos import DEVPATH, REPOS, install_repo
 
 # ---- Setup logger
 fmt = Formatter('%(asctime)s [%(levelname)s] [%(name)s] -> %(message)s')
@@ -80,14 +76,14 @@
 installed_dev_repo = False
 if not args.no_install:
     prev_branch = None
-    boot_branch_file = Path(get_conf_path("boot_branch.txt"))
+    boot_branch_file = DEVPATH / "boot_branch.txt"
     if boot_branch_file.exists():
         prev_branch = boot_branch_file.read_text()
 
-    result, error = run_program(
-        find_git(), ['merge-base', '--fork-point', 'master']
-    ).communicate()
-    branch = "master" if result else "not master"
+    result = subprocess.run(
+        ["/usr/bin/env", "git", "merge-base", "--fork-point", "master"]
+    )
+    branch = "master" if result.stdout else "not master"
     boot_branch_file.write_text(branch)
 
     logger.info("Previous root branch: %s; current root branch: %s",
@@ -96,7 +92,7 @@
     if branch != prev_branch:
         logger.info("Detected root branch change to/from master. "
                     "Will reinstall Spyder in editable mode.")
-        REPOS["spyder"]["editable"] = False
+        REPOS[DEVPATH.name]["editable"] = False
 
     for name in REPOS.keys():
         if not REPOS[name]['editable']:
@@ -114,6 +110,10 @@
     result = subprocess.run([sys.executable, *sys.argv])
     sys.exit(result.returncode)
 
+# Local imports
+# Must follow install_repo in case Spyder was not originally installed.
+from spyder import get_versions
+
 logger.info("Executing Spyder from source checkout")
 
 # Prepare arguments for Spyder's main script


Test patch: