Repository: spyder-ide/spyder

Issue:
Traceback from Editor/Debugger plugin when using same environment to launch different Spyder branches (master vs 5.x)
<!--- **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! --->

## Problem Description

When launching from master (previously having launched from 5.x on the same env) I got a traceback on the Anaconda prompt regarding the Debugger actions from the Editor. Maybe a validation is missing there or something is missing on the `bootstrap.py` script when changing branches? 

### What steps reproduce the problem?

1.  Launch Spyder from the master branch on an env that previously was used to launch the 5.x branch

### What is the expected output? What do you see instead?

No traceback

### Paste Traceback/Error Below (if applicable)
<!--- Copy from error dialog or View > Panes > Internal Console --->

```python-traceback
Traceback (most recent call last):
  File "e:\acer\documentos\spyder\spyder\spyder\plugins\editor\plugin.py", line 1585, in setup_other_windows
    action = self.main.debugger.get_action(action_name)
AttributeError: 'NoneType' object has no attribute 'get_action'
```

## 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: 6.0.0.dev0 02aeb4d82 (conda)
* Python version: 3.10.5 64-bit
* Qt version: 5.15.3
* PyQt5 version: 5.15.4
* Operating System: Windows 10




Discussion:
This happens because the entry point for the Debugger plugin is not installed given that we detect that Spyder is already installed in editable mode. My solution is to run

    pip uninstall spyder
    python bootstrap.py

which reinstalls Spyder and makes the Debugger plugin work. However, that generates a similar traceback when moving back to `5.x`, which requires running the same two commands again.

So, the ideal solution would be to automatically detect that we switched branches to uninstall Spyder automatically before checking/installing it in editable mode. @mrclary, any chance that you could take a look at this one?
I suppose we could write to a file in spyder's config directory that simply records the branch of current bootstrap execution. On bootstrap, the file is read, and if the current branch has changed to/from master then spyder is reinstalled.

What do you guys think?

Resolving patch:
diff --git a/bootstrap.py b/bootstrap.py
--- a/bootstrap.py
+++ b/bootstrap.py
@@ -28,7 +28,11 @@
 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
 
 # ---- Setup logger
 fmt = Formatter('%(asctime)s [%(levelname)s] [%(name)s] -> %(message)s')
@@ -73,15 +77,34 @@
        "Invalid GUI toolkit option '%s'" % args.gui
 
 # ---- Install sub repos
-
 installed_dev_repo = False
 if not args.no_install:
+    prev_branch = None
+    boot_branch_file = Path(get_conf_path("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"
+    boot_branch_file.write_text(branch)
+
+    logger.info("Previous root branch: %s; current root branch: %s",
+                prev_branch, branch)
+
+    if branch != prev_branch:
+        logger.info("Detected root branch change to/from master. "
+                    "Will reinstall Spyder in editable mode.")
+        REPOS["spyder"]["editable"] = False
+
     for name in REPOS.keys():
         if not REPOS[name]['editable']:
             install_repo(name)
             installed_dev_repo = True
         else:
             logger.info("%s installed in editable mode", name)
+
 if installed_dev_repo:
     logger.info("Restarting bootstrap to pick up installed subrepos")
     if '--' in sys.argv:
@@ -138,7 +161,6 @@
 
 # Checking versions (among other things, this has the effect of setting the
 # QT_API environment variable if this has not yet been done just above)
-from spyder import get_versions
 versions = get_versions(reporev=True)
 logger.info("Imported Spyder %s - Revision %s, Branch: %s; "
             "[Python %s %dbits, Qt %s, %s %s on %s]",


Test patch: