spyder-ide / spyder

Official repository for Spyder - The Scientific Python Development Environment
https://www.spyder-ide.org
MIT License
8.31k stars 1.61k forks source link

Define a section in the API for extras and utilities #4397

Open rlaverde opened 7 years ago

rlaverde commented 7 years ago

I'm opening this issue to make a list of utilities that could be used by plugins and could be exposed in the api

As @goanpeca says here "I think we should only allow importing from api when doing a plugin"

At the moment I found the followings functions and modules being used by plugins (and aren't in the API yet):

from spyder.config.base import _, get_translation, get_conf_path, DEV
from spyder.config.gui import set_shortcut, config_shortcut

from spyder.utils import icon_manager as ima
from spyder.utils.qthelpers import create_action, create_toolbutton, add_actions, get_icon

from spyder.widgets.tabs import Tabs
from spyder.widgets.comboboxes import PythonModulesComboBox
from spyder.widgets.variableexplorer.texteditor import TextEditor
from spyder.widgets.browser import WebView, FrameWebView

from spyder.plugins.runconfig import get_run_configuration

from spyder.utils import programs
from spyder.utils.misc import add_pathlist_to_PYTHONPATH, get_python_executable, select_port

from spyder.py3compat import getcwd, to_text_string, is_text_string

which ones we will exposes through the api? and how we will organize them?

goanpeca commented 7 years ago
# I would dump all shareable widgets in 
spyder.api.widgets

# py3 compatibility
spyder.api.py3compat

# For the rest
spyder.api.utils

@ccordoba12 thoughts?

ccordoba12 commented 7 years ago

I wouldn't like to move things so abruptly. Instead, I thought the idea of the api module was just to expose things from our internal modules, instead of moving things there.

goanpeca commented 7 years ago

No @ccordoba12 you got it wrong, what we mean is to have a way to import ths things from the api module not to move stuff TO the api module. This has the advantage of exposing only stuff form the api and keeping signatures and other things for backwards compatibility.

# spyder.api.utils

import spyder.utils

def method_to_expose(arg1, arg2):
    # Example that preserves api even if internal method changed order of args for eample
    return spyder.utils.method_to_expose(arg2, arg1)

We definitely want to discourage for users creating plugins to import stuff from everywhere in Spyder. If we limit to api then we can do it gradually as needed and support only that.

ccordoba12 commented 7 years ago

Yep, that's what I understood. So then, please go ahead @rlaverde.