Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# --- Executing Spyder
if args.show_console:
print("(Deprecated) --show console does nothing, now the default behavior "
"is to show the console, use --hide-console if you want to hide it")
if args.hide_console and os.name == 'nt':
print("0x. Hiding parent console (Windows only)")
sys.argv.append("--hide-console") # Windows only: show parent console
# Reset temporary config directory if starting in --safe-mode
if args.safe_mode or os.environ.get('SPYDER_SAFE_MODE'):
from spyder.config.base import get_conf_path # analysis:ignore
conf_dir = get_conf_path()
if osp.isdir(conf_dir):
shutil.rmtree(conf_dir)
print("04. Running Spyder")
from spyder.app import start # analysis:ignore
time_lapse = time.time() - time_start
print("Bootstrap completed in "
+ time.strftime("%H:%M:%S.", time.gmtime(time_lapse))
# gmtime() converts float into tuple, but loses milliseconds
+ ("%.4f" % time_lapse).split('.')[1])
start.main()
' '.join(self.server_args)))
creation_flags = 0
if WINDOWS:
creation_flags = subprocess.CREATE_NEW_PROCESS_GROUP
self.lsp_server = subprocess.Popen(
self.server_args,
stdout=self.lsp_server_log,
stderr=subprocess.STDOUT,
creationflags=creation_flags)
# self.transport_args += self.server_args
self.stdout_log = subprocess.PIPE
self.stderr_log = subprocess.PIPE
if DEV:
stderr_log_file = 'lsp_client_{0}.log'.format(self.language)
log_file = get_conf_path(osp.join('lsp_logs', stderr_log_file))
if not osp.exists(osp.dirname(log_file)):
os.makedirs(osp.dirname(log_file))
self.stderr_log = open(log_file, 'w')
new_env = dict(os.environ)
python_path = os.pathsep.join(sys.path)[1:]
new_env['PYTHONPATH'] = python_path
self.transport_args = map(str, self.transport_args)
self.transport_client = subprocess.Popen(self.transport_args,
stdout=self.stdout_log,
stderr=self.stderr_log,
env=new_env)
fid = self.zmq_in_socket.getsockopt(zmq.FD)
self.notifier = QSocketNotifier(fid, QSocketNotifier.Read, self)
# self.notifier.activated.connect(self.debug_print)
getcwd_or_home (except for Python, see below).
"""
path = None
# Get path of the current project
if self.main and self.main.projects:
path = self.main.projects.get_active_project_path()
if not path:
# We can't use getcwd_or_home for LSP servers because if it
# returns home and you have a lot of files on it
# then computing completions takes a long time
# and blocks the LSP server.
# Instead we use an empty directory inside our config one,
# just like we did for Rope in Spyder 3.
path = get_conf_path('lsp_root_path')
if not osp.exists(path):
os.mkdir(path)
return path
from qtpy.QtCore import QThread, Signal
# Local imports
from spyder.config.base import get_conf_path, DEBUG
from spyder.utils.debug import log_last_error
from spyder.utils.bsdsocket import read_packet, write_packet
from spyder.utils.misc import select_port
LOG_FILENAME = get_conf_path('introspection.log')
DEBUG_INTROSPECTION = DEBUG >= 2
if DEBUG_INTROSPECTION:
import logging
logging.basicConfig(filename=get_conf_path('introspection_debug.log'),
level=logging.DEBUG)
SPYDER_PORT = 20128
class IntrospectionServer(threading.Thread):
"""Introspection server"""
def __init__(self):
threading.Thread.__init__(self)
self.shells = {}
self.setDaemon(True)
global SPYDER_PORT
self.port = SPYDER_PORT = select_port(default_port=SPYDER_PORT)
SPYDER_PORT += 1
def register(self, shell):
def get_autosave_filename(self, filename):
"""
Get name of autosave file for specified file name.
This function uses the dict in `self.name_mapping`. If `filename` is
in the mapping, then return the corresponding autosave file name.
Otherwise, construct a unique file name and update the mapping.
Args:
filename (str): original file name
"""
try:
autosave_filename = self.name_mapping[filename]
except KeyError:
autosave_dir = get_conf_path('autosave')
if not osp.isdir(autosave_dir):
try:
os.mkdir(autosave_dir)
except EnvironmentError as error:
action = _('Error while creating autosave directory')
msgbox = AutosaveErrorDialog(action, error)
msgbox.exec_if_enabled()
autosave_filename = self.create_unique_autosave_filename(
filename, autosave_dir)
self.name_mapping[filename] = autosave_filename
self.save_autosave_mapping()
logger.debug('New autosave file name')
return autosave_filename
def create_new_client(self, give_focus=True, filename='', is_cython=False,
is_pylab=False, is_sympy=False, given_name=None):
"""Create a new client"""
self.master_clients += 1
client_id = dict(int_id=to_text_string(self.master_clients),
str_id='A')
cf = self._new_connection_file()
show_elapsed_time = self.get_option('show_elapsed_time')
reset_warning = self.get_option('show_reset_namespace_warning')
ask_before_restart = self.get_option('ask_before_restart')
client = ClientWidget(self, id_=client_id,
history_filename=get_conf_path('history.py'),
config_options=self.config_options(),
additional_options=self.additional_options(
is_pylab=is_pylab,
is_sympy=is_sympy),
interpreter_versions=self.interpreter_versions(),
connection_file=cf,
menu_actions=self.menu_actions,
options_button=self.options_button,
show_elapsed_time=show_elapsed_time,
reset_warning=reset_warning,
given_name=given_name,
ask_before_restart=ask_before_restart,
css_path=self.css_path)
# Change stderr_dir if requested
if self.test_dir is not None:
logger = logging.getLogger(__name__)
WINPDB_PATH = programs.find_program('winpdb')
class Editor(SpyderPluginWidget):
"""
Multi-file Editor widget
"""
CONF_SECTION = 'editor'
CONFIGWIDGET_CLASS = EditorConfigPage
CONF_FILE = False
TEMPFILE_PATH = get_conf_path('temp.py')
TEMPLATE_PATH = get_conf_path('template.py')
DISABLE_ACTIONS_WHEN_HIDDEN = False # SpyderPluginWidget class attribute
# Signals
run_in_current_ipyclient = Signal(str, str, str,
bool, bool, bool, bool, bool)
run_cell_in_ipyclient = Signal(str, object, str, bool)
debug_cell_in_ipyclient = Signal(str, object, str, bool)
exec_in_extconsole = Signal(str, bool)
redirect_stdio = Signal(bool)
open_dir = Signal(str)
breakpoints_saved = Signal()
run_in_current_extconsole = Signal(str, str, str, bool, bool)
open_file_update = Signal(str)
# This signal is fired for any focus change among all editor stacks
sig_editor_focus_changed = Signal()
def get_previous_config_fpath(self):
"""
Override method.
Return the last configuration file used if found.
"""
fpath = self.get_config_fpath()
previous_paths = [
# >= 51.0.0
fpath,
# < 51.0.0
os.path.join(get_conf_path(), 'spyder.ini'),
]
for fpath in previous_paths:
if osp.isfile(fpath):
break
return fpath
def _filename_global(self):
"""Create a .ini filename located in user home directory.
This .ini files stores the global spyder preferences.
"""
if self.subfolder is None:
config_file = osp.join(get_home_dir(), '.%s.ini' % self.name)
return config_file
else:
folder = get_conf_path()
# Save defaults in a "defaults" dir of .spyder2 to not pollute it
if 'defaults' in self.name:
folder = osp.join(folder, 'defaults')
if not osp.isdir(folder):
os.mkdir(folder)
config_file = osp.join(folder, '%s.ini' % self.name)
return config_file