Skip to content

Commit f8b5e70

Browse files
author
Kenneth Reitz
committed
Merge remote-tracking branch 'origin/master'
2 parents 3c4f30f + ff65a10 commit f8b5e70

14 files changed

Lines changed: 238 additions & 35 deletions

File tree

docs/contents.rst.inc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ This part of the guide focuses on setting up your Python environment.
2424

2525
starting/which-python
2626
starting/installation
27-
starting/next
2827

2928

3029
Development Environment
@@ -80,6 +79,7 @@ different scenarios.
8079
scenarios/admin
8180
scenarios/ci
8281
scenarios/speed
82+
scenarios/scientific
8383

8484

8585
Additional Notes
@@ -92,3 +92,4 @@ Contibution notes and legal information are here (for those interested).
9292

9393
notes/contribute
9494
notes/license
95+
notes/styleguide

docs/dev/env.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,17 @@ IPython
223223
BPython
224224
-------
225225

226+
`bpython <http://bpython-interpreter.org/>`_ is an alternative interface to the Python interpreter for Unix-like operating systems. It has the following features:
227+
228+
* In-line syntax highlighting.
229+
* Readline-like autocomplete with suggestions displayed as you type.
230+
* Expected parameter list for any Python function.
231+
* "Rewind" function to pop the last line of code from memory and re-evaluate.
232+
* Send entered code off to a pastebin.
233+
* Save entered code to a file.
234+
* Auto-indentation.
235+
* Python 3 support.
236+
226237
::
227238

228239
$ pip install bpython

docs/dev/virtualenvs.rst

Lines changed: 116 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,128 @@
11
Virtual Environments
22
====================
33

4-
.. todo:: Explain "Virtual Environments"
4+
A Virtual Environment, put simply, is an isolated working copy of Python which
5+
allows you to work on a specific project without worry of affecting other
6+
projects.
7+
8+
For example, you can work on a project which requires Django 1.3 while also
9+
maintaining a project which requires Django 1.0.
510

611
virtualenv
712
----------
813

9-
.. todo:: Write about virtualenv
14+
`virtualenv <http://pypi.python.org/pypi/virtualenv>`_ is a tool to create
15+
isolated Python environments.
16+
17+
Install it via pip:
18+
19+
.. code-block:: console
20+
21+
$ pip install virtualenv
22+
23+
Basic Usage
24+
~~~~~~~~~~~
25+
26+
1. Create a virtual environment:
27+
28+
.. code-block:: console
29+
30+
$ virtualenv venv
31+
32+
This creates a copy of Python in whichever directory you ran the command in,
33+
placing it in a folder named ``venv``.
34+
35+
2. To begin using the virtual environment, it needs to be activated:
36+
37+
.. code-block:: console
38+
39+
$ source venv/bin/activate
40+
41+
You can then begin installing any new modules without affecting the system
42+
default Python or other virtual environments.
43+
44+
3. If you are done working in the virtual environment for the moment, you can
45+
deactivate it:
46+
47+
.. code-block:: console
48+
49+
$ deactivate
50+
51+
This puts you back to the system's default Python interpreter with all its
52+
installed libraries.
53+
54+
To delete a virtual environment, just delete its folder.
55+
56+
After a while, though, you might end up with a lot of virtual environments
57+
littered across your system, and its possible you'll forget their names or
58+
where they were placed.
1059

1160
virtualenvwrapper
1261
-----------------
1362

14-
.. todo:: Write about virtualenvwrapper
63+
`virtualenvwrapper <http://www.doughellmann.com/projects/virtualenvwrapper/>`_
64+
provides a set of commands which makes working with virtual environments much
65+
more pleasant. It also places all your virtual environments in one place.
66+
67+
To install (make sure **virtualenv** is already installed):
68+
69+
.. code-block:: console
70+
71+
$ pip install virtualenvwrapper
72+
$ export WORKON_HOME=~/Envs
73+
$ source /usr/local/bin/virtualenvwrapper.sh
74+
75+
(`Full virtualenvwrapper install instructions <http://www.doughellmann.com/docs/virtualenvwrapper/#introduction>`_.)
76+
77+
Basic Usage
78+
~~~~~~~~~~~
79+
80+
1. Create a virtual environment:
81+
82+
.. code-block:: console
83+
84+
$ mkvirtualenv venv
85+
86+
This creates the ``venv`` folder inside ``~/Envs``.
87+
88+
2. Work on a virtual environment:
89+
90+
.. code-block:: console
91+
92+
$ workon venv
93+
94+
**virtualenvwrapper** provides tab-completion on environment names. It really
95+
helps when you have a lot of environments and have trouble remembering their
96+
names.
97+
``workon`` also deactivates whatever environment you are currently in, so you
98+
can quickly switch between environments.
99+
100+
3. Deactivating is still the same:
101+
102+
.. code-block:: console
103+
104+
$ deactivate
105+
106+
4. To delete:
107+
108+
.. code-block:: console
109+
110+
$ rmvirtualenv venv
111+
112+
Other useful commands
113+
~~~~~~~~~~~~~~~~~~~~~
114+
115+
``lsvirtualenv``
116+
List all of the environments.
117+
118+
``cdvirtualenv``
119+
Navigate into the directory of the currently activated virtual environment,
120+
so you can browse its ``site-packages``, for example.
121+
122+
``cdsitepackages``
123+
Like the above, but directly into ``site-packages`` directory.
124+
125+
``lssitepackages``
126+
Shows contents of ``site-packages`` directory.
15127

128+
`Full list of virtualenvwrapper commands <http://www.doughellmann.com/docs/virtualenvwrapper/command_ref.html#managing-environments>`_.

docs/intro/community.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ The mission of the Python Software Foundation is to promote, protect, and advanc
1919
PEPs
2020
----
2121

22-
PEPs are *Python Enhancement Proposals*. They are define change to Python itself, or the standards around it.
22+
PEPs are *Python Enhancement Proposals*. They describe changes to Python itself, or the standards around it.
2323

2424
There are three different types of PEPs (as defined by `PEP1 <http://www.python.org/dev/peps/pep-0001/>`_):
2525

@@ -70,4 +70,4 @@ A comprehensive list of conferences is maintained `at pycon.org <http://www.pyco
7070
Python User Groups
7171
--------------------------
7272

73-
User Groups are where a bunch of Python developers meet to present or talk about Python topics of interest. A list of local user groups is maintained at the `Python Software Foundation Wiki <http://wiki.python.org/moin/LocalUserGroups>`_.
73+
User Groups are where a bunch of Python developers meet to present or talk about Python topics of interest. A list of local user groups is maintained at the `Python Software Foundation Wiki <http://wiki.python.org/moin/LocalUserGroups>`_.

docs/intro/learning.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ While exploring the various features available in the python language the author
4747
patterns and best practices.
4848

4949
The book also includes several case studies which have the reader explore the topics discussed in the book
50-
in greater detail by applying those topics to real-world examples. Case studies include assingments in GUI
50+
in greater detail by applying those topics to real-world examples. Case studies include assignments in GUI
5151
and Markov Analysis.
5252

5353
`Think Python <http://greenteapress.com/thinkpython/html/index.html>`_

docs/intro/news.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Python-related news.
1919
Python Weekly
2020
~~~~~~~~~~~~~
2121

22-
Python Weekly is a free weekly newsletter featureing curated news, articles,
23-
new releases, jobs etc related to Python.
22+
Python Weekly is a free weekly newsletter featuring curated news, articles,
23+
new releases, jobs, etc. related to Python.
2424

2525
`Python Weekly <http://www.pythonweekly.com/>`_

docs/notes/contribute.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,3 @@ If you'd like to contribute, there's plenty to do. Here's a short todo_ list.
2525

2626
.. _GitHub: http://github.com/kennethreitz/python-guide/
2727
.. _todo: https://github.com/kennethreitz/python-guide/blob/master/TODO.rst
28-
29-
.. include:: ../../AUTHORS.rst

docs/scenarios/ci.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Why?
77

88
Martin Fowler, who first wrote about `Continuous Integration <http://martinfowler.com/articles/continuousIntegration.html>`_ (short: CI) together with Kent Beck, describes the CI as follows:
99

10-
Continuous Integration is a software development practice where members of a team integrate their work frequently, usually each person integrates at least daily - leading to multiple integrations per day. Each integration is verified by an automated build (including test) to detect integration errors as quickly as possible. Many teams find that this approach leads to significantly reduced integration problems and allows a team to develop cohesive software more rapidly. This article is a quick overview of Continuous Integration summarizing the technique and its current usage.
10+
Continuous Integration is a software development practice where members of a team integrate their work frequently, usually each person integrates at least daily - leading to multiple integrations per day. Each integration is verified by an automated build (including test) to detect integration errors as quickly as possible. Many teams find that this approach leads to significantly reduced integration problems and allows a team to develop cohesive software more rapidly.
1111

1212
Jenkins
1313
-------
@@ -29,4 +29,9 @@ Mule?
2929
Tox
3030
---
3131

32-
.. todo:: Write about `Tox <http://codespeak.net/~hpk/tox/>`_
32+
`tox <https://bitbucket.org/hpk42/tox>`_ is an automation tool providing packaging, testing and deployment of Python software right from the console or CI server.
33+
It is a generic virtualenv management and test command line tool which provides the following features:
34+
35+
* Checking that packages install correctly with different Python versions and interpreters
36+
* Running tests in each of the environments, configuring your test tool of choice
37+
* Acting as a frontend to Continuous Integration servers, reducing boilerplate and merging CI and shell-based testing.

docs/scenarios/gui.rst

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,30 @@ PyObjC
2626

2727
WXPython
2828
::::::::
29+
30+
2931
Install (Stable)
30-
----
32+
----------------
3133
*Go to http://www.wxpython.org/download.php#stable and download the appropriate package for your OS.*
3234

3335
Gtk
3436
:::
37+
PyGTK provides Python bindings for the GTK+ toolkit. Like the GTK+ library
38+
itself, it is currently licensed under the GNU LGPL. It is worth noting that
39+
PyGTK only currenty supports the Gtk-2.X API (NOT Gtk-3.0). It is currently
40+
recommended that PyGTK is not used for new projects and existing applications be
41+
ported from PyGTK to PyGObject.
42+
43+
Tk
44+
::
45+
Tkinter is a thin object-oriented layer on top of Tcl/Tk. It has the advantage
46+
of being included with the Python standard library, making it the most
47+
convenient and compatible toolkit to program with.
48+
49+
Both Tk and Tkinter are available on most Unix platforms, as well as on Windows
50+
and Macintosh systems. Starting with the 8.0 release, Tk offers native look and
51+
feel on all platforms.
3552

36-
tk
37-
::
53+
There's a good multi-language Tk tutorial with Python examples at
54+
`TkDocs <http://www.tkdocs.com/tutorial/index.html>`_. There's more information
55+
available on the `Python Wiki <http://wiki.python.org/moin/TkInter>`_.

docs/scenarios/speed.rst

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,32 @@ Speed
33

44
CPython, the most commonly used implementation of Python, is slow for CPU bound tasks. `PyPy`_ is fast.
55

6-
.. todo:: Fill in stub for Speed comparisons
6+
Using a slightly modified version of `David Beazleys`_ CPU bound test code(added loop for multiple tests), you can see the difference between CPython and PyPy's processing.
7+
8+
::
9+
10+
PyPy
11+
$ ./pypy -V
12+
Python 2.7.1 (7773f8fc4223, Nov 18 2011, 18:47:10)
13+
[PyPy 1.7.0 with GCC 4.4.3]
14+
$ ./pypy measure2.py
15+
0.0683999061584
16+
0.0483210086823
17+
0.0388588905334
18+
0.0440690517426
19+
0.0695300102234
20+
21+
::
22+
23+
CPython
24+
$ ./python -V
25+
Python 2.7.1
26+
$ ./python measure2.py
27+
1.06774401665
28+
1.45412397385
29+
1.51485204697
30+
1.54693889618
31+
1.60109114647
732

833
Context
934
:::::::
@@ -12,7 +37,13 @@ Context
1237
The GIL
1338
-------
1439

40+
`The GIL`_ (Global Interpreter Lock) is how Python allows multiple threads to operate at the same time. Python's
41+
memory management isn't entirely thread-safe, so the GIL is requried to prevents multiple threads from running
42+
the same Python code at once.
1543

44+
David Beazley has a great `guide`_ on how the GIL operates. He also covers the `new GIL`_ in Python 3.2. His
45+
results show that maximizing performance in a Python application requires a strong understanding of the GIL,
46+
how it affects your specific application, how many cores you have, and where your application bottlenecks are.
1647

1748
C Extentions
1849
------------
@@ -21,8 +52,8 @@ C Extentions
2152
The GIL
2253
-------
2354

24-
25-
55+
`Special care`_ must be taken when writing C extensions to make sure you register your threads
56+
with the interpreter.
2657

2758
C Extentions
2859
::::::::::::
@@ -57,4 +88,9 @@ Multiprocessing
5788
---------------
5889

5990

60-
.. _`PyPy`: http://pypy.org
91+
.. _`PyPy`: http://pypy.org
92+
.. _`The GIL`: http://wiki.python.org/moin/GlobalInterpreterLock
93+
.. _`guide`: http://www.dabeaz.com/python/UnderstandingGIL.pdf
94+
.. _`New GIL`: http://www.dabeaz.com/python/NewGIL.pdf
95+
.. _`Special care`: http://docs.python.org/c-api/init.html#threads
96+
.. _`David Beazleys`: http://www.dabeaz.com/GIL/gilvis/measure2.py

0 commit comments

Comments
 (0)