Repository navigation
Expand file tree
/
Copy pathsublime_as_ide.html
More file actions
328 lines (223 loc) · 17.9 KB
/
Copy pathsublime_as_ide.html
File metadata and controls
328 lines (223 loc) · 17.9 KB
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
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Turning Sublime Text Into a Lightweight Python IDE — Python 210 6.0 documentation</title>
<script type="text/javascript" src="../../_static/js/modernizr.min.js"></script>
<script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
<script src="../../_static/jquery.js"></script>
<script src="../../_static/underscore.js"></script>
<script src="../../_static/doctools.js"></script>
<script src="../../_static/language_data.js"></script>
<script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script type="text/javascript" src="../../_static/js/theme.js"></script>
<link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="../../genindex.html" />
<link rel="search" title="Search" href="../../search.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" style="background: #4b2e83" >
<a href="../../index.html">
<img src="../../_static/UWPCE_logo_full.png" class="logo" alt="Logo"/>
</a>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../topics/index.html">Introduction to Python</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../MultipleInheritance.html">15.1.1. Multiple Inheritance</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../index.html">Python 210</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content style-external-links">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../index.html">Docs</a> »</li>
<li>Turning Sublime Text Into a Lightweight Python IDE</li>
<li class="wy-breadcrumbs-aside">
<a href="../../_sources/modules/dev_environment/sublime_as_ide.rst.txt" rel="nofollow"> View page source</a>
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<div class="section" id="turning-sublime-text-into-a-lightweight-python-ide">
<span id="sublime-as-ide"></span><h1>Turning Sublime Text Into a Lightweight Python IDE<a class="headerlink" href="#turning-sublime-text-into-a-lightweight-python-ide" title="Permalink to this headline">¶</a></h1>
<p>A solid text editor is a developer’s best friend. You use it constantly and it
becomes like a second pair of hands. The keyboard commands you use daily
become so ingrained in your muscle memory that you stop thinking about them
entirely.</p>
<p>With Sublime Text, it’s possible to turn your text editor into the functional
equivalent of a Python IDE. The best part is you don’t have to install an IDE
to do it.</p>
<p><a class="reference external" href="http://www.sublimetext.com/">http://www.sublimetext.com/</a></p>
<div class="section" id="requirements">
<h2>Requirements<a class="headerlink" href="#requirements" title="Permalink to this headline">¶</a></h2>
<p>Here are <em>my</em> requirements for an ‘IDE’:</p>
<ul class="simple">
<li><p>It should provide excellent, configurable syntax colorization.</p></li>
<li><p>It should allow for robust tab completion.</p></li>
<li><p>It should perform automatic code linting to help avoid silly mistakes and conform to good style.</p></li>
</ul>
<p>And some more advanced features that you may want later:</p>
<ul class="simple">
<li><p>It should offer the ability to jump to the definition of symbols in other
files.</p></li>
<li><p>It should be able to interact with a Python interpreter such that when
debugging, the editor will follow along with the debugger.</p></li>
</ul>
</div>
<div class="section" id="which-version">
<h2>Which Version?<a class="headerlink" href="#which-version" title="Permalink to this headline">¶</a></h2>
<p>Use version 3 – it is updated now and again, so make sure to get the latest.</p>
<p><em>Use Sublime Version 3</em></p>
</div>
<div class="section" id="basic-settings">
<h2>Basic Settings<a class="headerlink" href="#basic-settings" title="Permalink to this headline">¶</a></h2>
<p>All configuration in Sublime Text is done via <a class="reference external" href="http://www.json.org">JSON</a>. It’s simple to learn. Go and read that link then return here.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>JSON is very similar to Python dict and list literals. Though it has its root in Javascript, it is also used in a wide variety of applications, and is well supported by Python. But a key difference is that it does not allow trailing commas after items in lists – so be careful.</p>
</div>
<p>There are a number of <a class="reference external" href="http://www.sublimetext.com/docs/3/settings.html">different levels of configuration</a> in Sublime Text. You will most often work on settings at the user level.</p>
<p>Open <code class="docutils literal notranslate"><span class="pre">Preferences</span></code> -> <code class="docutils literal notranslate"><span class="pre">Settings</span></code></p>
<p>On a Mac, you can find it under:</p>
<p><code class="docutils literal notranslate"><span class="pre">Sublime</span> <span class="pre">Text</span></code> -> <code class="docutils literal notranslate"><span class="pre">Preferences</span></code> -> <code class="docutils literal notranslate"><span class="pre">Settings</span></code></p>
<p>Sublime will open up a split window – “default” and “user” – you can look through the default ones to see all the setting you might want to override, and then copy things from default by putting them in the user file.</p>
<p>The preferences file is simply a JSON text file you edit like any other text file.</p>
<p>Here’s a reasonable set of preliminary settings (theme, color scheme and font are quite personal, find ones that suit you.):</p>
<div class="highlight-javascript notranslate"><div class="highlight"><pre><span></span><span class="p">{</span>
<span class="s2">"auto_indent"</span><span class="o">:</span> <span class="kc">true</span><span class="p">,</span>
<span class="s2">"color_scheme"</span><span class="o">:</span> <span class="s2">"Packages/User/Monokai (Flake8Lint).tmTheme"</span><span class="p">,</span>
<span class="s2">"draw_white_space"</span><span class="o">:</span> <span class="s2">"all"</span><span class="p">,</span>
<span class="s2">"font_face"</span><span class="o">:</span> <span class="s2">"inconsolata"</span><span class="p">,</span>
<span class="s2">"font_size"</span><span class="o">:</span> <span class="mi">23</span><span class="p">,</span>
<span class="s2">"indent_to_bracket"</span><span class="o">:</span> <span class="kc">true</span><span class="p">,</span>
<span class="s2">"rulers"</span><span class="o">:</span>
<span class="p">[</span>
<span class="mi">79</span><span class="p">,</span>
<span class="mi">95</span>
<span class="p">],</span>
<span class="s2">"theme"</span><span class="o">:</span> <span class="s2">"Adaptive.sublime-theme"</span><span class="p">,</span>
<span class="s2">"smart_indent"</span><span class="o">:</span> <span class="kc">true</span><span class="p">,</span>
<span class="s2">"tab_size"</span><span class="o">:</span> <span class="mi">4</span><span class="p">,</span>
<span class="s2">"translate_tabs_to_spaces"</span><span class="o">:</span> <span class="kc">true</span><span class="p">,</span>
<span class="s2">"use_tab_stops"</span><span class="o">:</span> <span class="kc">true</span><span class="p">,</span>
<span class="s2">"trailing_spaces_modified_lines_only"</span><span class="o">:</span> <span class="kc">true</span><span class="p">,</span>
<span class="s2">"trim_automatic_white_space"</span><span class="o">:</span> <span class="kc">true</span><span class="p">,</span>
<span class="s2">"trim_trailing_white_space_on_save"</span><span class="o">:</span> <span class="kc">true</span><span class="p">,</span>
<span class="s2">"word_wrap"</span><span class="o">:</span> <span class="kc">false</span><span class="p">,</span>
<span class="s2">"wrap_width"</span><span class="o">:</span> <span class="mi">95</span>
<span class="p">}</span>
</pre></div>
</div>
<p><strong>NOTE:</strong> Especially important is the setting <code class="docutils literal notranslate"><span class="pre">translate_tabs_to_spaces</span></code>, which ensures that any time you hit a tab key, the single <tab> character is replaced by four <space> characters. In Python this is <strong>vital</strong>!</p>
<p>If you do nothing else, add <code class="docutils literal notranslate"><span class="pre">translate_tabs_to_spaces</span></code> to your config!</p>
</div>
<div class="section" id="extending-the-editor">
<h2>Extending the Editor<a class="headerlink" href="#extending-the-editor" title="Permalink to this headline">¶</a></h2>
<p>Most of the requirements above go beyond basic editor functionality. So we’ll use Plugins.</p>
<p>Sublime Text comes with a great system for <a class="reference external" href="https://sublime.wbond.net">Package Control</a>.
It handles installing and uninstalling plugins, and even updates installed plugins for you.
You can also manually install plugins that haven’t made it to the big-time yet, including <a class="reference external" href="http://docs.sublimetext.info/en/latest/extensibility/plugins.html">ones you write yourself</a>.
Happily, the plugin system is based on Python!</p>
<p>To install a plugin using Package Control, open the <code class="docutils literal notranslate"><span class="pre">command</span> <span class="pre">palette</span></code> with <code class="docutils literal notranslate"><span class="pre">shift-super-P</span></code> (<code class="docutils literal notranslate"><span class="pre">ctrl-shift-P</span></code> on Windows/Linux).
The <code class="docutils literal notranslate"><span class="pre">super</span></code> key is <code class="docutils literal notranslate"><span class="pre">command</span></code> or <code class="docutils literal notranslate"><span class="pre">⌘</span></code> on OS X.
When the palette opens, typing <code class="docutils literal notranslate"><span class="pre">install</span></code> will bring up the <code class="docutils literal notranslate"><span class="pre">Package</span> <span class="pre">Control:</span> <span class="pre">Install</span> <span class="pre">Package</span></code> command.
Hit <code class="docutils literal notranslate"><span class="pre">enter</span></code> to select it.</p>
<a class="reference internal image-reference" href="../../_images/pc_menu.png"><img alt="The package control command in the command palette." class="align-center" src="../../_images/pc_menu.png" style="width: 600px;" /></a>
<p>After you select the command, Sublime Text fetches an updated list of packages from the network. It might take a second or two for the list to appear. When it does, start to type the name of the package you want. Sublime Text filters the list and shows you what you want to see. To install a plugin, select it with the mouse, or use arrow keys to navigate the list and hit <code class="docutils literal notranslate"><span class="pre">enter</span></code> when your plugin is highlighted.</p>
<a class="reference internal image-reference" href="../../_images/plugin_list.png"><img alt="../../_images/plugin_list.png" class="align-center" src="../../_images/plugin_list.png" style="width: 600px;" /></a>
</div>
<div class="section" id="useful-plugins">
<h2>Useful Plugins<a class="headerlink" href="#useful-plugins" title="Permalink to this headline">¶</a></h2>
<p>Here are the plugins I’ve installed to achieve the requirements above.</p>
<div class="section" id="anaconda">
<h3>Anaconda<a class="headerlink" href="#anaconda" title="Permalink to this headline">¶</a></h3>
<p>There are a bunch of Python-related plugins available. However, Anaconda is a nice package that provides most of the features you want, so plan on using just that one.</p>
<p>Not to be confused with the scientific Python distribution – the Anaconda sublime plugin is a full featured package to turn Sublime into a pretty full IDE:</p>
<p><a class="reference external" href="http://damnwidget.github.io/anaconda/">http://damnwidget.github.io/anaconda/</a></p>
<p>There are nifty instructions on that page.</p>
<p>By default, Anaconda uses the python interpreter that is in your <code class="docutils literal notranslate"><span class="pre">PATH</span></code> environment variable. So, the most important configuration option is the python_interpreter option that allows you to use a different Python interpreter, for example, one that resides in a virtual environment, or python3 vs python2.</p>
<p>If you get the right Python when you type “python” at a raw command line, then you are OK. But if not you may need to re-configure it.</p>
<p>{“python_interpreter”: “~/.virtualenvs/myproject/bin/python”}</p>
<blockquote>
<div><p>Note: for detailed information about how to properly configure Anaconda to get the maximum of it, follow <a class="reference external" href="http://damnwidget.github.io/anaconda/anaconda_settings/">“Configure Anaconda the Right Way”</a>.</p>
</div></blockquote>
</div>
<div class="section" id="a-few-settings-you-ll-want-to-change">
<h3>A few settings you’ll want to change<a class="headerlink" href="#a-few-settings-you-ll-want-to-change" title="Permalink to this headline">¶</a></h3>
<p>There are a few setting you may want to change:</p>
<ul>
<li><p>max line length for the linter: default is 72, which is pretty short these day. I use 95:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="s2">"pep8_max_line_length"</span><span class="p">:</span> <span class="mi">95</span><span class="p">,</span>
</pre></div>
</div>
</li>
</ul>
</div>
<div class="section" id="white-space-management">
<h3>White Space Management<a class="headerlink" href="#white-space-management" title="Permalink to this headline">¶</a></h3>
<p>One of the issues highlighted by code linters is trailing spaces. Sublime Text provides a setting that allows you to remove them every time you save a file:</p>
<div class="highlight-json notranslate"><div class="highlight"><pre><span></span><span class="p">{</span>
<span class="nt">"trim_trailing_whitespace_on_save"</span><span class="p">:</span> <span class="kc">true</span>
<span class="p">}</span>
</pre></div>
</div>
<p>This is a useful setting, but be careful if you are working with existing code: removing trailing whitespace by default causes a <em>ton</em> of noise in git commits.</p>
<p>But if you use it from the start with your code, it will keep it clean from the beginning.</p>
<p>It is suggested in the above settings.</p>
</div>
<div class="section" id="debugging-support">
<h3>Debugging Support<a class="headerlink" href="#debugging-support" title="Permalink to this headline">¶</a></h3>
<p>You’ll probably want to wait on this until you start using a debugger, but it’s a nifty feature when you get there.</p>
<p>The final requirement for a reasonable IDE experience is to be able to follow a debugging session in the file where the code exists.</p>
<p>This: <a class="reference external" href="https://packagecontrol.io/packages/Python%20Debugger">https://packagecontrol.io/packages/Python%20Debugger</a></p>
<p>Looks promising as a debugger plugin for sublime.</p>
</div>
</div>
</div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
© Copyright 2020, University of Washington, Natasha Aleksandrova, Christopher Barker, Brian Dorsey, Cris Ewing, Christy Heaton, Jon Jacky, Maria McKinley, Andy Miles, Rick Riehle, Joseph Schilz, Joseph Sheedy, Hosung Song. Creative Commons Attribution-ShareAlike 4.0 license
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>