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

PR: Find internal plugins in plugin module for Spyder installs #13400

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,24 +284,24 @@ def run(self):
'explorer = spyder.plugins.explorer.plugin:Explorer',
('fallback_completion = spyder.plugins.completion.fallback.plugin:'
'FallbackPlugin'),
'findinfiles = spyder.plugins.findinfiles.plugin:FindInFiles',
'find_in_files = spyder.plugins.findinfiles.plugin:FindInFiles',
'help = spyder.plugins.help.plugin:Help',
'history = spyder.plugins.history.plugin:HistoryLog',
'ipythonconsole = spyder.plugins.ipythonconsole.plugin:IPythonConsole',
'historylog = spyder.plugins.history.plugin:HistoryLog',
'ipython_console = spyder.plugins.ipythonconsole.plugin:IPythonConsole',
('kite_completion = spyder.plugins.completion.kite.plugin:'
'KiteCompletionPlugin'),
'onlinehelp = spyder.plugins.onlinehelp.plugin:OnlineHelp',
'outlineexplorer = spyder.plugins.outlineexplorer.plugin:OutlineExplorer',
'outline_explorer = spyder.plugins.outlineexplorer.plugin:OutlineExplorer',
'plots = spyder.plugins.plots.plugin:Plots',
'profiler = spyder.plugins.profiler.plugin:Profiler',
'projects = spyder.plugins.projects.plugin:Projects',
'project_explorer = spyder.plugins.projects.plugin:Projects',
'pylint = spyder.plugins.pylint.plugin:Pylint',
('lsp_completion = spyder.plugins.completion.languageserver.plugin:'
'LanguageServerPlugin'),
'python = spyder.plugins.python.plugin:Python',
('variableexplorer = spyder.plugins.variableexplorer.plugin:'
('variable_explorer = spyder.plugins.variableexplorer.plugin:'
'VariableExplorer'),
('workingdirectory = spyder.plugins.workingdirectory.plugin:'
('workingdir = spyder.plugins.workingdirectory.plugin:'
'WorkingDirectory'),
]

Expand Down
40 changes: 35 additions & 5 deletions spyder/app/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ def find_internal_plugins():
internal_plugins = {}
# If DEV, look for entry points in setup.py file for internal plugins
# and then look on the system for the rest
if DEV is not None or running_under_pytest():
HERE = os.path.abspath(os.path.dirname(__file__))
base_path = os.path.dirname(os.path.dirname(HERE))
setup_path = os.path.join(base_path, "setup.py")
HERE = os.path.abspath(os.path.dirname(__file__))
base_path = os.path.dirname(os.path.dirname(HERE))
setup_path = os.path.join(base_path, "setup.py")
if (DEV is not None or running_under_pytest()
and os.path.isfile(setup_path)):
if not os.path.isfile(setup_path):
raise Exception(
'No "setup.py" file found and running in DEV mode!')
Expand Down Expand Up @@ -76,6 +77,34 @@ def find_internal_plugins():
internal_plugins[name] = getattr(mod, class_name, None)
except (ModuleNotFoundError, ImportError):
pass
else:
import spyder.plugins as plugin_mod

plugins_path = os.path.dirname(plugin_mod.__file__)
for folder in os.listdir(plugins_path):
plugin_path = os.path.join(plugins_path, folder)
init_path = os.path.join(plugin_path, "__init__.py")
if (os.path.isdir(plugin_path) and os.path.isfile(init_path)
and not folder.startswith("io_")):
spec = importlib.util.spec_from_file_location(folder,
init_path)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
for plugin_class in getattr(module, "PLUGIN_CLASSES", []):
internal_plugins[plugin_class.NAME] = plugin_class

# TODO: Remove after migration is finished
internal_plugins["editor"] = None
internal_plugins["explorer"] = None
internal_plugins["project_explorer"] = None
internal_plugins["code_completion"] = None
internal_plugins["kite"] = None
internal_plugins["fallback"] = None
internal_plugins["ipython_console"] = None
internal_plugins["lsp"] = None
internal_plugins["pylint"] = None
internal_plugins["variable_explorer"] = None
internal_plugins["outline_explorer"] = None

return internal_plugins

Expand Down Expand Up @@ -118,7 +147,8 @@ def find_external_plugins():
external_plugins[name] = plugin_class
if name != plugin_class.NAME:
raise SpyderAPIError(
"Entry point name and plugin.NAME do not match!"
"Entry point name '{0}' and plugin.NAME '{1}' "
"do not match!".format(name, plugin_class.NAME)
)
except (ModuleNotFoundError, ImportError) as error:
print("%s: %s" % (name, str(error)), file=STDERR)
Expand Down
8 changes: 3 additions & 5 deletions spyder/plugins/breakpoints/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
# (see spyder/__init__.py for details)
# -----------------------------------------------------------------------------

from spyder.plugins.breakpoints.plugin import Breakpoints

# =============================================================================
# The following statement is required to register this 3rd party plugin:
# =============================================================================

from .plugin import Breakpoints as PLUGIN_CLASS
# The following statement is required to be able to grab internal plugins.
PLUGIN_CLASSES = [Breakpoints]
5 changes: 5 additions & 0 deletions spyder/plugins/console/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,8 @@

Internal Console Plugin.
"""

from spyder.plugins.console.plugin import Console

# The following statement is required to be able to grab internal plugins.
PLUGIN_CLASSES = [Console]
5 changes: 5 additions & 0 deletions spyder/plugins/findinfiles/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@

Find in files plugin.
"""

from spyder.plugins.findinfiles.plugin import FindInFiles

# The following statement is required to be able to grab internal plugins.
PLUGIN_CLASSES = [FindInFiles]
5 changes: 5 additions & 0 deletions spyder/plugins/help/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@

Help plugin using a WebView
"""

from spyder.plugins.help.plugin import Help

# The following statement is required to be able to grab internal plugins.
PLUGIN_CLASSES = [Help]
5 changes: 5 additions & 0 deletions spyder/plugins/history/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@

History plugin.
"""

from spyder.plugins.history.plugin import HistoryLog

# The following statement is required to be able to grab internal plugins.
PLUGIN_CLASSES = [HistoryLog]
5 changes: 5 additions & 0 deletions spyder/plugins/onlinehelp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@
"""
Spyder Online help plugin using Pydoc.
"""

from spyder.plugins.onlinehelp.plugin import OnlineHelp

# The following statement is required to be able to grab internal plugins.
PLUGIN_CLASSES = [OnlineHelp]
5 changes: 5 additions & 0 deletions spyder/plugins/plots/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@

Plots plugin
"""

from spyder.plugins.plots.plugin import Plots

# The following statement is required to be able to grab internal plugins.
PLUGIN_CLASSES = [Plots]
8 changes: 3 additions & 5 deletions spyder/plugins/profiler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
# (see spyder/__init__.py for details)
# -----------------------------------------------------------------------------

from spyder.plugins.profiler.plugin import Profiler

# =============================================================================
# The following statement is required to register this 3rd party plugin:
# =============================================================================

from .plugin import Profiler as PLUGIN_CLASS
# The following statement is required to be able to grab internal plugins.
PLUGIN_CLASSES = [Profiler]
7 changes: 1 addition & 6 deletions spyder/plugins/pylint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,4 @@
# (see spyder/__init__.py for details)
# -----------------------------------------------------------------------------


# =============================================================================
# The following statement is required to register this 3rd party plugin:
# =============================================================================

from .plugin import Pylint as PLUGIN_CLASS
from spyder.plugins.pylint.plugin import Pylint as PLUGIN_CLASS
5 changes: 5 additions & 0 deletions spyder/plugins/workingdirectory/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@
"""
Spyder Working Directory plugin.
"""

from spyder.plugins.workingdirectory.plugin import WorkingDirectory

# The following statement is required to be able to grab internal plugins.
PLUGIN_CLASSES = [WorkingDirectory]