/
under-the-hood-of-saws-a-supercharged-aws-cli.html
296 lines (250 loc) · 13.9 KB
/
under-the-hood-of-saws-a-supercharged-aws-cli.html
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
<!DOCTYPE html>
<html lang="en" prefix="og: http://ogp.me/ns# fb: https://www.facebook.com/2008/fbml">
<head>
<title>Donne Martin</title>
<!-- Using the latest rendering mode for IE -->
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<meta name="author" content="Donne Martin" />
<!-- Open Graph tags -->
<meta property="og:site_name" content="Donne Martin" />
<meta property="og:type" content="website"/>
<meta property="og:title" content="Donne Martin"/>
<meta property="og:url" content="."/>
<meta property="og:description" content="Donne Martin"/>
<!-- Bootstrap -->
<link rel="stylesheet" href="./theme/css/bootstrap.min.css" type="text/css"/>
<link href="./theme/css/pygments/monokai.css" rel="stylesheet">
<!-- Custom CSS -->
<link href="./theme/css/agency.css" rel="stylesheet">
<link href="./theme/css/custom.css" rel="stylesheet">
<!-- Custom Fonts -->
<link href="./theme/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<link href="https://fonts.googleapis.com/css?family=Montserrat:400,700" rel="stylesheet" type="text/css">
<link href='https://fonts.googleapis.com/css?family=Kaushan+Script' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Droid+Serif:400,700,400italic,700italic' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Roboto+Slab:400,100,300,700' rel='stylesheet' type='text/css'>
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond../theme/js/1.4.2/respond.min.js"></script>
<![endif]-->
</head><body id="page-top" class="index">
<!-- Banner -->
<!-- End Banner -->
<div class="container">
<div class="row">
<div class="col-lg-12">
<nav class="navbar navbar-default navbar-fixed-top" style="background-color: #000">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header page-scroll">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand page-scroll" href=".">Donne Martin</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li class="hidden">
<a href="#page-top"></a>
</li>
<li>
<a class="page-scroll" href="./#likes">Likes</a>
</li>
<li>
<a class="page-scroll" href="./#portfolio">GitHub</a>
</li>
<li>
<a class="page-scroll" href="./#about">About</a>
</li>
<li>
<a class="page-scroll" href="./#contact">Contact</a>
</li>
<li>
<a class="page-scroll" href="./archives">Blog</a>
</li>
<li>
<a class="page-scroll" href="http://donnemartin.com/viz/">Viz</a>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav> <section id="content" class="section-top-padding">
<article class="article-top-padding">
<h1>
<a href="./under-the-hood-of-saws-a-supercharged-aws-cli.html"
rel="bookmark"
title="Permalink to Under the Hood of SAWS, A Supercharged AWS CLI">
Under the Hood of SAWS, A Supercharged AWS CLI
</a>
</h1>
<i><time datetime="2015-09-23T00:00:00-04:00"> Wed 23 September 2015</time></i>
<div class="entry-content">
<div class="panel">
<br/>
</div>
<div class="container">
<br/>
<img class="img-responsive" src="https://camo.githubusercontent.com/2af72023269b0b320adf4ec55576435f5c8b79c4/687474703a2f2f692e696d6775722e636f6d2f767a43357a6d412e676966">
</div>
<hr class="featurette-divider">
<h2>What's SAWS?</h2>
<p><a href="https://github.com/donnemartin/saws">SAWS: GitHub Repo</a></p>
<h2>So what's under the hood?</h2>
<h3>AWS CLI</h3>
<p>Python-powered official <a href="https://github.com/aws/aws-cli">AWS CLI</a>. Does the heavy lifting communicating with AWS and feeds completions to <code>SAWS</code>. The AWS CLI uses <a href="https://github.com/boto/boto">boto</a>, the official Python SDK for AWS.</p>
<p>Check out <a href="https://github.com/donnemartin/saws/blob/master/saws/completer.py">completer.py</a> for more details on how <code>awscli</code> is used.</p>
<h3>Python-Prompt Toolkit</h3>
<p><a href="https://github.com/jonathanslenders/python-prompt-toolkit">Python-prompt-toolkit</a> simplifies the creation of interactive command lines.</p>
<p>Used throughout the <code>SAWS</code> source code.</p>
<h3>Pygments</h3>
<p><a href="http://pygments.org/">Pygments</a> is a syntax highlighter for <code>SAWS</code> commands and output.</p>
<p>Check out <a href="https://github.com/donnemartin/saws/blob/master/saws/lexer.py">lexer.py</a> for more details on how <code>pygments</code> is used.</p>
<h3>Unit Tests</h3>
<p><code>SAWS</code> uses:</p>
<ul>
<li><a href="https://docs.python.org/2/library/unittest.html">unittest</a><ul>
<li>Check out the <a href="https://github.com/donnemartin/saws/tree/master/tests">tests</a> folder</li>
</ul>
</li>
<li><a href="https://pexpect.readthedocs.org/en/stable/">pexpect</a><ul>
<li>Used in <a href="https://github.com/donnemartin/saws/blob/master/tests/test_cli.py">test_cli.py</a> to run, interact, and stop the CLI</li>
<li>Not supported on Windows</li>
</ul>
</li>
<li><a href="https://pypi.python.org/pypi/mock">Mock</a><ul>
<li>Could be intimidating at first, here's a helpful <a href="http://www.toptal.com/python/an-introduction-to-mocking-in-python">tutorial</a></li>
</ul>
</li>
</ul>
<p>If you want to play around the development environment, run the following:</p>
<div class="highlight"><pre><span class="nv">$ </span>git clone https://github.com/donnemartin/saws.git
<span class="nv">$ </span>pip install -e .
<span class="nv">$ </span>pip install -r requirements-dev.txt
<span class="nv">$ </span>saws
</pre></div>
<p>Run unit tests in your active Python environment:</p>
<div class="highlight"><pre><span class="nv">$ </span>python tests/run_tests.py
</pre></div>
<p>I'm also a fan of:</p>
<ul>
<li><a href="http://pytest.org/latest/">pytest</a></li>
<li><a href="https://nose.readthedocs.org/en/latest/">nose</a></li>
</ul>
<p>While working on <code>SAWS</code> I came across 'behavior driven development' with <a href="http://pythonhosted.org/behave/">behave</a>--interesting!</p>
<h3>Tox</h3>
<p><a href="https://tox.readthedocs.org/en/latest/">Tox</a> is used to automate and standardize testing in Python 2.6, 2.7, 3.3, 3.4, and pypy.</p>
<p>I've found Tox + <a href="https://travis-ci.org/donnemartin/saws">Travis CI</a> to be a great combination. To hook up tox to Travis CI, add the following to your <a href="https://github.com/donnemartin/saws/blob/master/.travis.yml">.travis.yml</a>:</p>
<div class="highlight"><pre>install:
- travis_retry pip install tox
after_success:
- codecov
</pre></div>
<p>To run locally:</p>
<div class="highlight"><pre><span class="nv">$ </span>tox
</pre></div>
<p>The <a href="https://github.com/donnemartin/saws/blob/master/tox.ini">tox.ini</a> file specifies:</p>
<ul>
<li>Python environments</li>
<li>Travis CI arguments</li>
<li>Dependencies</li>
<li>Test commands</li>
</ul>
<h3>Coverage Tests</h3>
<p><a href="https://codecov.io/github/donnemartin/saws/saws"><img alt="Codecov" src="https://img.shields.io/codecov/c/github/donnemartin/saws.svg" /></a></p>
<p><a href="https://codecov.io/github/donnemartin/saws/saws">Codecov</a> provides code coverage. <code>SAWS</code> uses <a href="https://github.com/codecov/codecov-python">codecov-python</a> to interact with CodeCov.</p>
<p><a href="https://coveralls.io/">Coveralls</a> is also very popular and can be used with <a href="https://github.com/z4r/python-coveralls">python-coveralls</a> and <a href="https://github.com/coagulant/coveralls-python">coveralls-python</a>.</p>
<p>To hook up to Codecov to Travis CI, add the following to your <a href="https://github.com/donnemartin/saws/blob/master/.travis.yml">.travis.yml</a>:</p>
<div class="highlight"><pre>install:
- pip install codecov
after_success:
- codecov
</pre></div>
<p align="center">
<img src="http://codecov.io/github/donnemartin/saws/branch.svg?branch=master" class="img-responsive">
</p>
<h3>TravisCI</h3>
<p><a href="https://travis-ci.org/donnemartin/saws"><img alt="Build Status" src="https://travis-ci.org/donnemartin/saws.svg?branch=master" /></a></p>
<p><a href="https://travis-ci.org/donnemartin/saws">Travis CI</a> provides continuous integration.</p>
<p>The <a href="https://github.com/donnemartin/saws/blob/master/.travis.yml">.travis.yml</a> file specifies:</p>
<ul>
<li>Python versions</li>
<li>OS (I had trouble getting Mac OS X to work)</li>
<li>Install dependencies</li>
<li>Script to run</li>
<li>What to do after running (send the coverage stats to Codecov)</li>
</ul>
<h3>Sphinx</h3>
<p><a href="http://saws.readthedocs.org/en/latest/?badge=latest"><img alt="Documentation Status" src="https://readthedocs.org/projects/saws/badge/?version=latest" /></a></p>
<p><a href="http://sphinx-doc.org/">Sphinx</a> is a great documentation tool. It takes your <a href="https://www.python.org/dev/peps/pep-0257/">docstrings</a> and turns it into documentation that can be hosted on sites such as <a href="http://saws.readthedocs.org/en/latest/?badge=latest">Readthedocs.org</a> and <a href="https://pypi.python.org/pypi/saws/">PyPi</a>.</p>
<p>Here's a handy article to learn more about how to build and upload your Sphinx docs to PyPi:</p>
<p><a href="https://pythonhosted.org/an_example_pypi_project/buildanduploadsphinx.html"></a></p>
<p>Run the following to build the docs:</p>
<div class="highlight"><pre><span class="nv">$ </span>python setup.py build_sphinx
</pre></div>
<h3>PyPI and Setup.py</h3>
<p><a href="http://badge.fury.io/py/saws"><img alt="PyPI version" src="https://badge.fury.io/py/saws.svg" /></a> <a href="https://pypi.python.org/pypi/saws/"><img alt="PyPI" src="https://img.shields.io/pypi/pyversions/saws.svg" /></a></p>
<p><a href="https://github.com/donnemartin/saws/blob/master/setup.py">Setup.py</a> contains information on versioning, package requirements, and other useful info for <a href="https://pypi.python.org/pypi/saws">PyPI</a>.</p>
<p>This allows end-users to install with a one-liner:</p>
<div class="highlight"><pre><span class="nv">$ </span>pip install saws
</pre></div>
<p>A <code>virtualenv</code> install is recommended to avoid potential permissions or package dependency issues.</p>
<p>Check out this <a href="http://peterdowns.com/posts/first-time-with-pypi.html">article</a> to learn more about posting to PyPI.</p>
<h3>Git-Flow</h3>
<p><a href="https://github.com/nvie/gitflow">Git-Flow</a> is a set of Git extensions that provide high-level repository operations for the popular <a href="http://nvie.com/img/git-model@2x.png">git branching model</a>.</p>
<h3>Misc</h3>
<ul>
<li><a href="https://pypi.python.org/pypi/six">Six</a> - Python 2 and 3 compatibility.</li>
<li><a href="https://pypi.python.org/pypi/flake8">Flake8</a> - Linter for code quality.</li>
</ul>
</div>
<hr class="featurette-divider">
<!-- /.entry-content -->
</article>
</section>
</div>
</div>
</div>
<footer>
<div class="container">
<div class="row">
<div class="col-md-12 text-left">
<span class="copyright">Copyright © Donne Martin 2014-Present</span>
</div>
</div>
</div>
</footer>
<script src="./theme/js/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="./theme/js/bootstrap.min.js"></script>
<!-- Enable responsive features in IE8 with Respond.js (https://github.com/scottjehl/Respond) -->
<script src="./theme/js/respond.min.js"></script>
<!-- Plugin JavaScript -->
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.3/jquery.easing.min.js"></script>
<script src="./theme/js/classie.js"></script>
<script src="./theme/js/cbpAnimatedHeader.js"></script>
<!-- Custom Theme JavaScript -->
<script src="./theme/js/agency.js"></script>
<!-- Google Analytics Universal -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-54747412-1', 'auto');
ga('send', 'pageview');
</script>
<!-- End Google Analytics Universal Code -->
</body>
</html>