Skip to content

Commit

Permalink
Replace spyder.config.utils.is_anaconda with spyder_kernels.utils.pyt…
Browse files Browse the repository at this point in the history
…honenv.is_conda_env
  • Loading branch information
mrclary committed Oct 14, 2024
1 parent aebd379 commit f7bdf62
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 47 deletions.
12 changes: 2 additions & 10 deletions spyder/config/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,11 @@ def get_edit_extensions():

EDIT_EXTENSIONS = get_edit_extensions()


#==============================================================================
# Detection of OS specific versions
#==============================================================================

def is_ubuntu():
"""Detect if we are running in an Ubuntu-based distribution"""
if sys.platform.startswith('linux') and osp.isfile('/etc/lsb-release'):
Expand Down Expand Up @@ -212,13 +214,3 @@ def is_kde_desktop():
return False
else:
return False


def is_anaconda():
"""
Detect if we are running under Anaconda.
Taken from https://stackoverflow.com/a/47610844/438386
"""
is_conda = osp.exists(osp.join(sys.prefix, 'conda-meta'))
return is_conda
12 changes: 4 additions & 8 deletions spyder/plugins/completion/providers/languageserver/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@
# Local imports
from spyder.api.config.mixins import SpyderConfigurationAccessor
from spyder.config.base import (
DEV, get_conf_path, get_debug_level, is_conda_based_app,
running_under_pytest)
from spyder.config.utils import is_anaconda
DEV, get_conf_path, get_debug_level, running_under_pytest
)
from spyder.plugins.completion.api import (
CLIENT_CAPABILITES, SERVER_CAPABILITES,
TEXT_DOCUMENT_SYNC_OPTIONS, CompletionRequestTypes,
Expand All @@ -42,7 +41,7 @@
from spyder.plugins.completion.providers.languageserver.providers import (
LSPMethodProviderMixIn)
from spyder.utils.misc import getcwd_or_home, select_port

from spyder_kernels.utils.pythonenv import is_conda_env

# Main constants
LOCATION = osp.realpath(osp.join(os.getcwd(),
Expand Down Expand Up @@ -280,10 +279,7 @@ def start_server(self):
# is missing and the user has installed their packages on
# that directory.
# Fixes spyder-ide/spyder#17661
if (
not (is_anaconda() or is_conda_based_app())
and "APPDATA" in os.environ
):
if not is_conda_env(sys.prefix) and "APPDATA" in os.environ:
env.insert("APPDATA", os.environ["APPDATA"])
else:
# There's no need to define a cwd for other servers.
Expand Down
34 changes: 18 additions & 16 deletions spyder/plugins/editor/widgets/editorstack/editorstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@
from spyder.api.widgets.mixins import SpyderWidgetMixin
from spyder.config.base import _, running_under_pytest
from spyder.config.gui import is_dark_interface
from spyder.config.utils import (get_edit_filetypes, get_edit_filters,
get_filter, is_kde_desktop, is_anaconda)
from spyder.config.utils import (
get_edit_filetypes, get_edit_filters, get_filter, is_kde_desktop
)
from spyder.plugins.editor.api.panel import Panel
from spyder.plugins.editor.utils.autosave import AutosaveForStack
from spyder.plugins.editor.utils.editor import get_file_language
Expand All @@ -57,6 +58,7 @@
from spyder.utils.qthelpers import mimedata2url, create_waitspinner
from spyder.utils.stylesheet import PANES_TABBAR_STYLESHEET
from spyder.widgets.tabs import BaseTabs
from spyder_kernels.utils.pythonenv import is_conda_env

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -309,7 +311,7 @@ def __init__(self, parent, actions, use_switcher=True):
self.close_quotes_enabled = True
self.add_colons_enabled = True
self.auto_unindent_enabled = True
self.indent_chars = " "*4
self.indent_chars = " " * 4
self.tab_stop_width_spaces = 4
self.show_class_func_dropdown = False
self.help_enabled = False
Expand Down Expand Up @@ -410,12 +412,12 @@ def copy_relative_path(self):
and osp.splitdrive(getcwd_or_home())[0] != file_drive
):
QMessageBox.warning(
self,
_("No available relative path"),
_("It is not possible to copy a relative path "
"for this file because it is placed in a "
"different drive than your current working "
"directory. Please copy its absolute path.")
self,
_("No available relative path"),
_("It is not possible to copy a relative path "
"for this file because it is placed in a "
"different drive than your current working "
"directory. Please copy its absolute path.")
)
else:
base_path = getcwd_or_home()
Expand Down Expand Up @@ -1296,8 +1298,8 @@ def __setup_menu(self):
)

for new_window_and_close_action in (
self.__get_new_window_and_close_actions()
):
self.__get_new_window_and_close_actions()
):
self.menu.add_action(
new_window_and_close_action,
section=EditorStackMenuSections.NewWindowCloseSection
Expand Down Expand Up @@ -1511,13 +1513,13 @@ def move_editorstack_data(self, start, end):
return
else:
steps = abs(end - start)
direction = (end-start) // steps # +1 for right, -1 for left
direction = (end - start) // steps # +1 for right, -1 for left

data = self.data
self.blockSignals(True)

for i in range(start, end, direction):
data[i], data[i+direction] = data[i+direction], data[i]
data[i], data[i + direction] = data[i + direction], data[i]

self.blockSignals(False)
self.refresh()
Expand Down Expand Up @@ -1654,8 +1656,8 @@ def close_all_right(self):
""" Close all files opened to the right """
num = self.get_stack_index()
n = self.get_stack_count()
for __ in range(num, n-1):
self.close_file(num+1)
for __ in range(num, n - 1):
self.close_file(num + 1)

def close_all_but_this(self):
"""Close all files but the current one"""
Expand Down Expand Up @@ -1970,7 +1972,7 @@ def select_savename(self, original_filename):
# Don't use filters on KDE to not make the dialog incredible
# slow
# Fixes spyder-ide/spyder#4156.
if is_kde_desktop() and not is_anaconda():
if is_kde_desktop() and not is_conda_env(sys.prefix):
filters = ''
selectedfilter = ''
else:
Expand Down
12 changes: 6 additions & 6 deletions spyder/plugins/pylint/main_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
from spyder.api.config.decorators import on_conf_change
from spyder.api.translations import _
from spyder.api.widgets.main_widget import PluginMainWidget
from spyder.config.base import get_conf_path, is_conda_based_app
from spyder.config.utils import is_anaconda
from spyder.config.base import get_conf_path
from spyder.plugins.pylint.utils import get_pylintrc_path
from spyder.plugins.variableexplorer.widgets.texteditor import TextEditor
from spyder.utils.icon_manager import ima
Expand All @@ -43,6 +42,7 @@
is_module_or_package)
from spyder.widgets.onecolumntree import OneColumnTree, OneColumnTreeActions
from spyder.widgets.helperwidgets import PaneEmptyWidget
from spyder_kernels.utils.pythonenv import is_conda_env


# --- Constants
Expand Down Expand Up @@ -229,7 +229,7 @@ def refresh(self):
modname = osp.join(modname, "__init__")

for ext in (".py", ".pyw"):
if osp.isfile(modname+ext):
if osp.isfile(modname + ext):
modname = modname + ext
break

Expand Down Expand Up @@ -384,7 +384,7 @@ def _start(self):
processEnvironment.insert("USERPROFILE", user_profile)
# Needed for Windows installations using standalone Python and pip.
# See spyder-ide/spyder#19385
if not is_conda_based_app() and not is_anaconda():
if not is_conda_env(sys.prefix):
processEnvironment.insert("APPDATA", os.environ.get("APPDATA"))

process.setProcessEnvironment(processEnvironment)
Expand Down Expand Up @@ -998,7 +998,7 @@ def parse_output(self, output):
if i_rate > 0:
i_rate_end = output.find("/10", i_rate)
if i_rate_end > 0:
rate = output[i_rate+len(txt_rate):i_rate_end]
rate = output[i_rate + len(txt_rate):i_rate_end]

# Previous run
previous = ""
Expand All @@ -1007,7 +1007,7 @@ def parse_output(self, output):
i_prun = output.find(txt_prun, i_rate_end)
if i_prun > 0:
i_prun_end = output.find("/10", i_prun)
previous = output[i_prun+len(txt_prun):i_prun_end]
previous = output[i_prun + len(txt_prun):i_prun_end]

return rate, previous, results

Expand Down
10 changes: 5 additions & 5 deletions spyder/plugins/updatemanager/widgets/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@
from spyder.api.config.mixins import SpyderConfigurationAccessor
from spyder.api.translations import _
from spyder.config.base import is_conda_based_app
from spyder.config.utils import is_anaconda
from spyder.plugins.updatemanager.workers import (
WorkerUpdate,
WorkerDownloadInstaller
)
from spyder.utils.conda import find_conda, is_anaconda_pkg
from spyder.utils.programs import get_temp_dir, is_program_installed
from spyder.widgets.helperwidgets import MessageCheckBox
from spyder_kernels.utils.pythonenv import is_conda_env

# Logger setup
logger = logging.getLogger(__name__)
Expand All @@ -52,7 +52,7 @@
SKIP_CHECK_UPDATE = (
sys.executable.startswith(('/usr/bin/', '/usr/local/bin/'))
or (
not is_anaconda()
not is_conda_env(sys.prefix)
and osp.exists(osp.join(get_path('stdlib'), 'EXTERNALLY-MANAGED'))
)
)
Expand Down Expand Up @@ -590,22 +590,22 @@ def confirm_messagebox(parent, message, title, version=None, critical=False,
def manual_update_messagebox(parent, latest_release, channel):
msg = ""
if os.name == "nt":
if is_anaconda():
if is_conda_env(sys.prefix):
msg += _("Run the following command or commands in "
"the Anaconda prompt to update manually:"
"<br><br>")
else:
msg += _("Run the following command in a cmd prompt "
"to update manually:<br><br>")
else:
if is_anaconda():
if is_conda_env(sys.prefix):
msg += _("Run the following command or commands in a "
"terminal to update manually:<br><br>")
else:
msg += _("Run the following command in a terminal to "
"update manually:<br><br>")

if is_anaconda():
if is_conda_env(sys.prefix):
is_pypi = channel == 'pypi'

if is_anaconda_pkg() and not is_pypi:
Expand Down
5 changes: 3 additions & 2 deletions spyder/plugins/updatemanager/workers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import os
import os.path as osp
import shutil
import sys
from time import sleep
import traceback
from zipfile import ZipFile
Expand All @@ -23,9 +24,9 @@
# Local imports
from spyder import __version__
from spyder.config.base import _, is_stable_version, running_in_ci
from spyder.config.utils import is_anaconda
from spyder.utils.conda import get_spyder_conda_channel
from spyder.utils.programs import check_version
from spyder_kernels.utils.pythonenv import is_conda_env

# Logger setup
logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -151,7 +152,7 @@ def start(self):
# If Spyder is installed from defaults channel (pkgs/main), then use
# that channel to get updates. The defaults channel can be far behind
# our latest release
if is_anaconda():
if is_conda_env(sys.prefix):
channel, channel_url = get_spyder_conda_channel()
if channel == "pkgs/main":
url = channel_url + '/channeldata.json'
Expand Down

0 comments on commit f7bdf62

Please sign in to comment.