/
main.py
644 lines (626 loc) · 24.1 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
# -*- coding: utf-8 -*-
#
# Copyright © Spyder Project Contributors
# Licensed under the terms of the MIT License
# (see spyder/__init__.py for details)
"""
Spyder configuration options.
Note: Leave this file free of Qt related imports, so that it can be used to
quickly load a user config file.
"""
import os
import sys
# Local import
from spyder.config.base import CHECK_ALL, EXCLUDED_NAMES
from spyder.config.fonts import MEDIUM, SANS_SERIF
from spyder.config.utils import IMPORT_EXT
from spyder.config.appearance import APPEARANCE
from spyder.plugins.editor.utils.findtasks import TASKS_PATTERN
from spyder.utils.introspection.module_completion import PREFERRED_MODULES
# =============================================================================
# Main constants
# =============================================================================
# Find in files exclude patterns
EXCLUDE_PATTERNS = ['*.csv, *.dat, *.log, *.tmp, *.bak, *.orig']
# Extensions that should be visible in Spyder's file/project explorers
SHOW_EXT = ['.py', '.ipynb', '.dat', '.pdf', '.png', '.svg', '.md', '.yml',
'.yaml']
# Extensions supported by Spyder (Editor or Variable explorer)
USEFUL_EXT = IMPORT_EXT + SHOW_EXT
# Name filters for file/project explorers (excluding files without extension)
NAME_FILTERS = ['README', 'INSTALL', 'LICENSE', 'CHANGELOG']
NAME_FILTERS += ['*' + _ext for _ext in USEFUL_EXT if _ext not in NAME_FILTERS]
# Port used to detect if there is a running instance and to communicate with
# it to open external files
OPEN_FILES_PORT = 21128
# OS Specific
WIN = os.name == 'nt'
MAC = sys.platform == 'darwin'
LINUX = sys.platform.startswith('linux')
CTRL = "Meta" if MAC else "Ctrl"
# Modules to be preloaded for Rope and Jedi
PRELOAD_MDOULES = ', '.join(PREFERRED_MODULES)
# =============================================================================
# Defaults
# =============================================================================
DEFAULTS = [
('main',
{
'opengl': 'software',
'single_instance': True,
'open_files_port': OPEN_FILES_PORT,
'mac_open_file': False,
'normal_screen_resolution': True,
'high_dpi_scaling': False,
'high_dpi_custom_scale_factor': False,
'high_dpi_custom_scale_factors': '1.5',
'vertical_tabs': False,
'prompt_on_exit': False,
'panes_locked': True,
'window/size': (1260, 740),
'window/position': (10, 10),
'window/is_maximized': True,
'window/is_fullscreen': False,
'window/prefs_dialog_size': (1050, 530),
'use_custom_margin': True,
'custom_margin': 0,
'use_custom_cursor_blinking': False,
'show_internal_errors': True,
'check_updates_on_startup': True,
'cursor/width': 2,
'completion/size': (300, 180),
'report_error/remember_token': False,
'show_dpi_message': True,
}),
('toolbar',
{
'enable': True,
'toolbars_visible': True,
'last_visible_toolbars': [],
}),
('statusbar',
{
'show_status_bar': True,
'memory_usage/enable': True,
'memory_usage/timeout': 2000,
'cpu_usage/enable': False,
'cpu_usage/timeout': 2000,
'clock/enable': False,
'clock/timeout': 1000,
}),
('pythonpath_manager',
{
'spyder_pythonpath': [],
}),
('quick_layouts',
{
'place_holder': '',
'names': [],
'order': [],
'active': [],
'ui_names': []
}),
('internal_console',
{
'max_line_count': 300,
'working_dir_history': 30,
'working_dir_adjusttocontents': False,
'wrap': True,
'codecompletion/auto': False,
'external_editor/path': 'SciTE',
'external_editor/gotoline': '-goto:',
}),
('main_interpreter',
{
'default': True,
'custom': False,
'umr/enabled': True,
'umr/verbose': True,
'umr/namelist': [],
'custom_interpreters_list': [],
'custom_interpreter': '',
}),
('ipython_console',
{
'show_banner': True,
'completion_type': 0,
'show_calltips': True,
'ask_before_closing': False,
'show_reset_namespace_warning': True,
'buffer_size': 500,
'pylab': True,
'pylab/autoload': False,
'pylab/backend': 0,
'pylab/inline/figure_format': 0,
'pylab/inline/resolution': 72,
'pylab/inline/width': 6,
'pylab/inline/height': 4,
'pylab/inline/bbox_inches': True,
'startup/run_lines': '',
'startup/use_run_file': False,
'startup/run_file': '',
'greedy_completer': False,
'jedi_completer': False,
'autocall': 0,
'symbolic_math': False,
'in_prompt': '',
'out_prompt': '',
'show_elapsed_time': False,
'ask_before_restart': True,
# This is True because there are libraries like Pyomo
# that generate a lot of Command Prompts while running,
# and that's extremely annoying for Windows users.
'hide_cmd_windows': True,
'pdb_prevent_closing': True,
'pdb_ignore_lib': False,
'pdb_execute_events': True,
'pdb_use_exclamation_mark': True,
'pdb_stop_first_line': True
}),
('variable_explorer',
{
'check_all': CHECK_ALL,
'dataframe_format': '.6g', # No percent sign to avoid problems
# with ConfigParser's interpolation
'excluded_names': EXCLUDED_NAMES,
'exclude_private': True,
'exclude_uppercase': False,
'exclude_capitalized': False,
'exclude_unsupported': False,
'exclude_callables_and_modules': True,
'truncate': True,
'minmax': False,
'show_callable_attributes': True,
'show_special_attributes': False
}),
('plots',
{
'mute_inline_plotting': True,
'show_plot_outline': False,
'auto_fit_plotting': True
}),
('editor',
{
'printer_header/font/family': SANS_SERIF,
'printer_header/font/size': MEDIUM,
'printer_header/font/italic': False,
'printer_header/font/bold': False,
'wrap': False,
'wrapflag': True,
'todo_list': True,
'realtime_analysis': True,
'realtime_analysis/timeout': 2500,
'outline_explorer': True,
'line_numbers': True,
'blank_spaces': False,
'edge_line': True,
'edge_line_columns': '79',
'indent_guides': False,
'code_folding': True,
'show_code_folding_warning': True,
'scroll_past_end': False,
'toolbox_panel': True,
'close_parentheses': True,
'close_quotes': True,
'add_colons': True,
'auto_unindent': True,
'indent_chars': '* *',
'tab_stop_width_spaces': 4,
'check_eol_chars': True,
'convert_eol_on_save': False,
'convert_eol_on_save_to': 'LF',
'tab_always_indent': False,
'intelligent_backspace': True,
'automatic_completions': True,
'automatic_completions_after_chars': 1,
'completions_hint': True,
'completions_hint_after_ms': 500,
'underline_errors': False,
'highlight_current_line': True,
'highlight_current_cell': True,
'occurrence_highlighting': True,
'occurrence_highlighting/timeout': 1500,
'always_remove_trailing_spaces': False,
'add_newline': False,
'always_remove_trailing_newlines': False,
'show_tab_bar': True,
'show_class_func_dropdown': False,
'max_recent_files': 20,
'save_all_before_run': True,
'focus_to_editor': True,
'run_cell_copy': False,
'onsave_analysis': False,
'autosave_enabled': True,
'autosave_interval': 60,
'docstring_type': 'Numpydoc',
'strip_trailing_spaces_on_modify': False,
}),
('historylog',
{
'enable': True,
'wrap': True,
'go_to_eof': True,
'line_numbers': False,
}),
('help',
{
'enable': True,
'max_history_entries': 20,
'wrap': True,
'connect/editor': False,
'connect/ipython_console': False,
'math': True,
'automatic_import': True,
'plain_mode': False,
'rich_mode': True,
'show_source': False,
'locked': False,
}),
('onlinehelp',
{
'enable': True,
'zoom_factor': .8,
'handle_links': False,
'max_history_entries': 20,
}),
('outline_explorer',
{
'enable': True,
'show_fullpath': False,
'show_all_files': False,
'group_cells': True,
'sort_files_alphabetically': False,
'show_comments': True,
'follow_cursor': True,
'display_variables': False
}),
('project_explorer',
{
'name_filters': NAME_FILTERS,
'show_all': True,
'show_hscrollbar': True,
'max_recent_projects': 10,
'visible_if_project_open': True,
'date_column': False,
'single_click_to_open': False,
'show_hidden': True,
'size_column': False,
'type_column': False,
'date_column': False
}),
('explorer',
{
'enable': True,
'name_filters': NAME_FILTERS,
'show_hidden': False,
'single_click_to_open': False,
'size_column': False,
'type_column': False,
'date_column': True
}),
('find_in_files',
{
'enable': True,
'supported_encodings': ["utf-8", "iso-8859-1", "cp1252"],
'exclude': EXCLUDE_PATTERNS,
'exclude_regexp': False,
'search_text_regexp': False,
'search_text': [''],
'search_text_samples': [TASKS_PATTERN],
'more_options': False,
'case_sensitive': False,
'exclude_case_sensitive': False,
'max_results': 1000,
}),
('breakpoints',
{
'enable': True,
}),
('completions',
{
'enable': True,
'enable_code_snippets': True,
'completions_wait_for_ms': 200,
'enabled_providers': {},
'provider_configuration': {},
'request_priorities': {}
}),
('profiler',
{
'enable': True,
}),
('pylint',
{
'enable': True,
'history_filenames': [],
'max_entries': 30,
'project_dir': None,
}),
('workingdir',
{
'working_dir_history': 20,
'console/use_project_or_home_directory': False,
'console/use_cwd': True,
'console/use_fixed_directory': False,
'startup/use_project_or_home_directory': True,
'startup/use_fixed_directory': False,
}),
('tours',
{
'enable': True,
'show_tour_message': True,
}),
('shortcuts',
{
# -- Application --
'_/close pane': "Shift+Ctrl+F4",
'_/lock unlock panes': "Shift+Ctrl+F5",
'_/use next layout': "Shift+Alt+PgDown",
'_/use previous layout': "Shift+Alt+PgUp",
'_/maximize pane': "Ctrl+Alt+Shift+M",
'_/fullscreen mode': "F11",
'_/save current layout': "Shift+Alt+S",
'_/layout preferences': "Shift+Alt+P",
'_/spyder documentation': "F1",
'_/restart': "Shift+Alt+R",
'_/quit': "Ctrl+Q",
'_/file switcher': 'Ctrl+P',
'_/symbol finder': 'Ctrl+Alt+P',
'_/debug': "Ctrl+F5",
'_/debug step over': "Ctrl+F10",
'_/debug continue': "Ctrl+F12",
'_/debug step into': "Ctrl+F11",
'_/debug step return': "Ctrl+Shift+F11",
'_/debug exit': "Ctrl+Shift+F12",
'_/run': "F5",
'_/configure': "Ctrl+F6",
'_/re-run last script': "F6",
# -- Switch to plugin --
'_/switch to help': "Ctrl+Shift+H",
'_/switch to outline_explorer': "Ctrl+Shift+O",
'_/switch to editor': "Ctrl+Shift+E",
'_/switch to historylog': "Ctrl+Shift+L",
'_/switch to onlinehelp': "Ctrl+Shift+D",
'_/switch to project_explorer': "Ctrl+Shift+P",
'_/switch to ipython_console': "Ctrl+Shift+I",
'_/switch to variable_explorer': "Ctrl+Shift+V",
'_/switch to find_in_files': "Ctrl+Shift+F",
'_/switch to explorer': "Ctrl+Shift+X",
'_/switch to plots': "Ctrl+Shift+J" if MAC else "Ctrl+Shift+G",
'_/switch to pylint': "Ctrl+Shift+C",
'_/switch to profiler': "Ctrl+Shift+R",
'_/switch to breakpoints': "Ctrl+Shift+B",
# -- Find/replace --
'find_replace/find text': "Ctrl+F",
'find_replace/find next': "Ctrl+G" if MAC else "F3",
'find_replace/find previous': (
"Ctrl+Shift+G" if MAC else "Shift+F3"),
'find_replace/replace text': "Ctrl+R",
'find_replace/hide find and replace': "Escape",
# -- Editor --
'editor/code completion': CTRL+'+Space',
'editor/duplicate line up': (
"Ctrl+Alt+Up" if WIN else "Shift+Alt+Up"),
'editor/duplicate line down': (
"Ctrl+Alt+Down" if WIN else "Shift+Alt+Down"),
'editor/delete line': 'Ctrl+D',
'editor/transform to uppercase': 'Ctrl+Shift+U',
'editor/transform to lowercase': 'Ctrl+U',
'editor/indent': 'Ctrl+]',
'editor/unindent': 'Ctrl+[',
'editor/move line up': "Alt+Up",
'editor/move line down': "Alt+Down",
'editor/go to new line': "Ctrl+Shift+Return",
'editor/go to definition': "F3" if MAC else "Ctrl+G",
'editor/toggle comment': "Ctrl+1",
'editor/blockcomment': "Ctrl+4",
'editor/unblockcomment': "Ctrl+5",
'editor/start of line': "Meta+A",
'editor/end of line': "Meta+E",
'editor/previous line': "Meta+P",
'editor/next line': "Meta+N",
'editor/previous char': "Meta+B",
'editor/next char': "Meta+F",
'editor/previous word': "Ctrl+Left",
'editor/next word': "Ctrl+Right",
'editor/kill to line end': "Meta+K",
'editor/kill to line start': "Meta+U",
'editor/yank': 'Meta+Y',
'editor/rotate kill ring': 'Shift+Meta+Y',
'editor/kill previous word': 'Meta+Backspace',
'editor/kill next word': 'Meta+D',
'editor/start of document': 'Ctrl+Home',
'editor/end of document': 'Ctrl+End',
'editor/undo': 'Ctrl+Z',
'editor/redo': 'Ctrl+Shift+Z',
'editor/cut': 'Ctrl+X',
'editor/copy': 'Ctrl+C',
'editor/paste': 'Ctrl+V',
'editor/delete': 'Del',
'editor/select all': "Ctrl+A",
'editor/inspect current object': 'Ctrl+I',
'editor/breakpoint': 'F12',
'editor/conditional breakpoint': 'Shift+F12',
'editor/run selection': "F9",
'editor/run to line': 'Shift+F9',
'editor/run from line': CTRL + '+F9',
'editor/go to line': 'Ctrl+L',
'editor/go to previous file': CTRL + '+Shift+Tab',
'editor/go to next file': CTRL + '+Tab',
'editor/cycle to previous file': 'Ctrl+PgUp',
'editor/cycle to next file': 'Ctrl+PgDown',
'editor/new file': "Ctrl+N",
'editor/open last closed':"Ctrl+Shift+T",
'editor/open file': "Ctrl+O",
'editor/save file': "Ctrl+S",
'editor/save all': "Ctrl+Alt+S",
'editor/save as': 'Ctrl+Shift+S',
'editor/close all': "Ctrl+Shift+W",
'editor/last edit location': "Ctrl+Alt+Shift+Left",
'editor/previous cursor position': "Alt+Left",
'editor/next cursor position': "Alt+Right",
'editor/previous warning': "Ctrl+Alt+Shift+,",
'editor/next warning': "Ctrl+Alt+Shift+.",
'editor/zoom in 1': "Ctrl++",
'editor/zoom in 2': "Ctrl+=",
'editor/zoom out': "Ctrl+-",
'editor/zoom reset': "Ctrl+0",
'editor/close file 1': "Ctrl+W",
'editor/close file 2': "Ctrl+F4",
'editor/run cell': CTRL + '+Return',
'editor/run cell and advance': 'Shift+Return',
'editor/debug cell': 'Alt+Shift+Return',
'editor/go to next cell': 'Ctrl+Down',
'editor/go to previous cell': 'Ctrl+Up',
'editor/re-run last cell': 'Alt+Return',
'editor/split vertically': "Ctrl+{",
'editor/split horizontally': "Ctrl+_",
'editor/close split panel': "Alt+Shift+W",
'editor/docstring': "Ctrl+Alt+D",
'editor/autoformatting': "Ctrl+Alt+I",
'editor/show in external file explorer': '',
# -- Internal console --
'console/inspect current object': "Ctrl+I",
'console/clear shell': "Ctrl+L",
'console/clear line': "Shift+Escape",
# -- Pylint --
'pylint/run analysis': "F8",
# -- Profiler --
'profiler/run profiler': "F10",
# -- IPython console --
'ipython_console/new tab': "Ctrl+T",
'ipython_console/reset namespace': "Ctrl+Alt+R",
'ipython_console/restart kernel': "Ctrl+.",
'ipython_console/inspect current object': "Ctrl+I",
'ipython_console/clear shell': "Ctrl+L",
'ipython_console/clear line': "Shift+Escape",
'ipython_console/enter array inline': "Ctrl+Alt+M",
'ipython_console/enter array table': "Ctrl+M",
# -- Array buider --
'array_builder/enter array inline': "Ctrl+Alt+M",
'array_builder/enter array table': "Ctrl+M",
# -- Variable explorer --
'variable_explorer/copy': 'Ctrl+C',
'variable_explorer/search': 'Ctrl+F',
'variable_explorer/refresh': 'Ctrl+R',
# -- Plots --
'plots/copy': 'Ctrl+C',
'plots/previous figure': 'Ctrl+PgUp',
'plots/next figure': 'Ctrl+PgDown',
'plots/save': 'Ctrl+S',
'plots/save all': 'Ctrl+Alt+S',
'plots/close': 'Ctrl+W',
'plots/close all': 'Ctrl+Shift+W',
'plots/zoom in': "Ctrl++",
'plots/zoom out': "Ctrl+-",
# -- Files --
'explorer/copy file': 'Ctrl+C',
'explorer/paste file': 'Ctrl+V',
'explorer/copy absolute path': 'Alt+Shift+C',
'explorer/copy relative path': 'Alt+Shift+D',
# -- Projects --
'project_explorer/copy file': 'Ctrl+C',
'project_explorer/paste file': 'Ctrl+V',
'project_explorer/copy absolute path': 'Alt+Shift+C',
'project_explorer/copy relative path': 'Alt+Shift+D',
# -- Find --
'find_in_files/find in files': 'Alt+Shift+F',
}),
('appearance', APPEARANCE),
]
NAME_MAP = {
# Empty container object means use the rest of defaults
'spyder': [],
# Splitting these files makes sense for projects, we might as well
# apply the same split for the app global config
# These options change on spyder startup or are tied to a specific OS,
# not good for version control
'transient': [
('main', [
'completion/size',
'crash',
'current_version',
'historylog_filename',
'window/position',
'window/prefs_dialog_size',
'window/size',
'window/state',
]
),
('toolbar', [
'last_visible_toolbars',
]
),
('editor', [
'autosave_mapping',
'bookmarks',
'filenames',
'layout_settings',
'recent_files',
'splitter_state',
]
),
('explorer', [
'file_associations',
]),
('find_in_files', [
'path_history'
'search_text',
'exclude_index',
'search_in_index',
]
),
('main_interpreter', [
'custom_interpreters_list',
'custom_interpreter',
'executable',
]
),
('onlinehelp', [
'zoom_factor',
]
),
('outline_explorer', [
'expanded_state',
'scrollbar_position',
],
),
('project_explorer', [
'current_project_path',
'expanded_state',
'recent_projects',
'max_recent_projects',
'scrollbar_position',
]
),
('pythonpath_manager', []),
('quick_layouts', []), # Empty list means use all options
('run', [
'breakpoints',
'configurations',
'defaultconfiguration',
'default/wdir/fixed_directory',
]
),
('workingdir', [
'console/fixed_directory',
'startup/fixed_directory',
]
),
('pylint', [
'history_filenames',
]
),
]
}
# =============================================================================
# Config instance
# =============================================================================
# IMPORTANT NOTES:
# 1. If you want to *change* the default value of a current option, you need to
# do a MINOR update in config version, e.g. from 3.0.0 to 3.1.0
# 2. If you want to *remove* options that are no longer needed in our codebase,
# or if you want to *rename* options, then you need to do a MAJOR update in
# version, e.g. from 3.0.0 to 4.0.0
# 3. You don't need to touch this value if you're just adding a new option
CONF_VERSION = '74.0.0'