summaryrefslogtreecommitdiff
path: root/slides/devtools/presentation.rst
blob: 0f6f7cc26c350ef3a32a5f50164cfcfb1a127ba7 (plain)
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
=============================================
Virtualenv, Packaging and Useful Tools
=============================================

.. class:: center

    March 30, 2015

    Department of Aerospace Engineering,
    IIT Bombay

    :Author: Prabhu Ramachandran



Agenda
=========

- Introduction to virtual env and its use

- Python packaging
    - What are Packages?
    - Distributing Packages
    - PyPI

- Hosting documentation

- Continuous integration

- Test coverage

Preamble: what's a package?
=============================

A collection of Python modules organized into a hierarchy::

   $ tree jedi
    jedi/
    ├── __init__.py
    ├── api.py
    ├── builtin.py
    ...
    ├── debug.py
    ├── refactoring.py
    └── settings.py



Virtualenvs
=============

A self-contained virtual Python environment which **you** control!

- Requires a "system" Python distribution


Motivation
===========

- Need to install Python packages
- No root access
- Don’t want to mess up system
- Create “isolated” environment

Virtualenv
============

- www.virtualenv.org
- pypi.python.org/pypi/virtualenv
- Either install virtualenv
- Or use the `virtualenv.py`_

.. code:: shell

    $ easy_install virtualenv

Or download tarball and::

    $ python setup.py install [--prefix=/usr/local]

.. _`virtualenv.py`: http://github.com/pypa/virtualenv/tree/master/virtualenv.py


Environments
=============

.. code:: shell

    $ python virtualenv.py --help

    $ python virtualenv.py ENV

    $ virtualenv --system-site-packages ENV

- ``ENV`` is a directory name of your choice
- Self-contained universe
- Can inherit system packages
- Look in ``ENV/bin`` (or ``ENV\Scripts``)
- Look in ``ENV/lib`` (or ``ENV\Lib``)

Activation
============

.. code:: shell

    # Activation (Linux/Mac OSX)
    $ source ENV/bin/activate

    $ ENV\Scripts\activate.bat

    # Deactivate
    (ENV)$ deactivate

Usage
=======

.. code:: shell

    (ENV)$ deactivate
    $ python virtualenv.py ANOTHER
    (ANOTHER)$ source ANOTHER/bin/activate
    (ANOTHER)$ pip install PKG
    # installs in ANOTHER

    (ANOTHER)$ deactivate
    $ source ENV/bin/activate

    # To remove ANOTHER
    $ rm -rf ANOTHER

Easy and convenient!

Python Packages
=================

- Organized hierarchy of modules
- Can include data
- Documentation
- Installation and distribution

Installing packages
====================

.. code:: shell

    $ pip install requests

    $ pip list

    $ pip uninstall requests

Making your own
==================

Let us look at a simple package

.. code:: shell

    $ tree my_project
    my_project/
    ├── README.md
    └── sees
        ├── __init__.py
        └── hello.py

Packaging the package
=======================

- We want to "install" this
- Want others to install it
- Want to share it

- Make sure you have ``setuptools`` available

.. code:: shell

    $ python -c "import setuptools"

No import error means you are good!

Writing a ``setup.py``
========================

Create ``setup.py``

.. code:: python

    from setuptools import setup, find_packages

    setup(
        name="sees",
        version="0.1",
        description="Utility code for SEES course",
        author="FOSSEE developers",
        author_email="python@fossee.in",
        packages=find_packages(),
    )

Using it
==========

.. code:: shell

    $ python setup.py --help
    $ python setup.py sdist
    $ python setup.py develop
    $ python setup.py install

More on distutils
======================

- Many more options
- Support to compile extensions
- Including package data
- See `setuptools documentation`_
- See `distutils documentation`_.

.. _setuptools documentation: http://pythonhosted.org//setuptools/
.. _distutils documentation: https://docs.python.org/2/distutils/index.html#distutils-index

Distributing and PyPI
=========================

- Register on http://pypi.python.org

.. code:: shell

    $ python setup.py register

- Create a ``~/.pypirc``

::

    [pypirc]
    servers = pypi
    [server-login]
    username:your_awesome_username
    password:your_awesome_password

Hosting Documentation
======================

- Bitbucket/Github

- Better: http://www.readthedocs.org
    - http://read-the-docs.readthedocs.org/


Continuous integration
========================

- Run tests automatically

    - On each commit
    - For each PR
    - For all branches

- Potentially on multiple platforms

Continuous integration
========================

- Jenkins/Hudson

- Travis-ci.org

- Drone.io

- Shippable.com

- Appveyor


Travis-CI example
===================

- Uses a YAML file for config
- Most others are similar
- Look at some examples


Additional Reading
===================

Very nice document with examples:

https://pythonhosted.org/an_example_pypi_project/index.html