Skip to content

Commit 9d8a491

Browse files
committed
Merge pull request realpython#393 from Zearin/code-blocks
Code blocks
2 parents bc29d68 + 5f86330 commit 9d8a491

File tree

16 files changed

+120
-81
lines changed

16 files changed

+120
-81
lines changed

Readme.rst

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,18 @@ basis.
1616

1717
Topics include:
1818

19-
- Platform/version specific installations
19+
- Platform- and version-specific installations
2020
- Py2app, Py2exe, bbfreeze, pyInstaller
21-
- Pip / virtualenv
22-
- Documentation. Writing it.
23-
- server configurations / tools for various web frameworks
21+
- Pip
22+
- Virtualenv
2423
- fabric
25-
- exhaustive module recommendations, grouped by topic/purpose
26-
- Testing. Jenkins + tox guides.
27-
- How to interface w/ hg from git easily
28-
- what libraries to use for what
29-
30-
If you are not fond of reading reStructuredText, there is an
24+
- Exhaustive module recommendations, grouped by topic/purpose
25+
- Which libraries to use for what
26+
- Server configurations & tools for various web frameworks
27+
- Documentation: writing it
28+
- Testing: Jenkins & tox guides
29+
- How to easily interface ``hg`` from ``git`` easily
30+
31+
If you aren't fond of reading reStructuredText, there is an
3132
almost up-to-date `HTML version at docs.python-guide.org
3233
<http://docs.python-guide.org>`_.

docs/dev/env.rst

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Vim is a text editor which uses keyboard shortcuts for editing instead of menus
1616
or icons. There exist a couple of plugins and settings for the VIM editor to
1717
aid Python development. If you only develop in Python, a good start is to set
1818
the default settings for indentation and line-wrapping to values compliant with
19-
:pep:`8`. In your home directory, open a file called `.vimrc` and add the
19+
:pep:`8`. In your home directory, open a file called ``.vimrc`` and add the
2020
following lines::
2121

2222
set textwidth=79 " lines longer than 79 columns will be broken
@@ -42,11 +42,11 @@ If your VIM is compiled with `+python` you can also utilize some very handy
4242
plugins to do these checks from within the editor.
4343

4444
For PEP8 checking, install the vim-pep8_ plugin, and for pyflakes you can
45-
install vim-pyflakes_. Now you can map the functions `Pep8()` or `Pyflakes()`
45+
install vim-pyflakes_. Now you can map the functions ``Pep8()`` or ``Pyflakes()``
4646
to any hotkey or action you want in Vim. Both plugins will display errors at
4747
the bottom of the screen, and provide an easy way to jump to the corresponding
4848
line. It's very handy to call these functions whenever you save a file. In
49-
order to do this, add the following lines to your `vimrc`::
49+
order to do this, add the following lines to your ``.vimrc``::
5050

5151
autocmd BufWritePost *.py call Pyflakes()
5252
autocmd BufWritePost *.py call Pep8()
@@ -67,12 +67,12 @@ Python-mode
6767
Python-mode_ is a complex solution in VIM for working with Python code.
6868
It has:
6969

70-
- Asynchronous Python code checking (pylint, pyflakes, pep8, mccabe) in any combination
70+
- Asynchronous Python code checking (``pylint``, ``pyflakes``, ``pep8``, ``mccabe``) in any combination
7171
- Code refactoring and autocompletion with Rope
7272
- Fast Python folding
7373
- Virtualenv support
7474
- Search by Python documentation and run Python code
75-
- Auto PEP8 error fixes
75+
- Auto PEP8_ error fixes
7676

7777
And more.
7878

@@ -105,10 +105,10 @@ already an Emacs user is `Python Programming in Emacs`_ at EmacsWiki.
105105
TextMate
106106
--------
107107

108-
"`TextMate <http://macromates.com/>`_ brings Apple's approach to operating
109-
systems into the world of text editors. By bridging UNIX underpinnings and GUI,
110-
TextMate cherry-picks the best of both worlds to the benefit of expert
111-
scripters and novice users alike."
108+
`TextMate <http://macromates.com/>`_ brings Apple's approach to operating
109+
systems into the world of text editors. By bridging UNIX underpinnings and GUI,
110+
TextMate cherry-picks the best of both worlds to the benefit of expert
111+
scripters and novice users alike.
112112

113113
Sublime Text
114114
------------
@@ -143,7 +143,7 @@ The most popular Eclipse plugin for Python development is Aptana's
143143
Komodo IDE
144144
----------
145145
`Komodo IDE <http://www.activestate.com/komodo-ide>`_ is developed by
146-
ActiveState and is a commercial IDE for Windows, Mac and Linux.
146+
ActiveState and is a commercial IDE for Windows, Mac, and Linux.
147147

148148

149149
Spyder
@@ -189,18 +189,22 @@ virtualenv
189189
Virtualenv is a tool to keep the dependencies required by different projects
190190
in separate places, by creating virtual Python environments for them.
191191
It solves the "Project X depends on version 1.x but, Project Y needs 4.x"
192-
dilemma and keeps your global site-packages directory clean and manageable.
192+
dilemma, and keeps your global site-packages directory clean and manageable.
193193

194194
`virtualenv <http://www.virtualenv.org/en/latest/index.html>`_ creates
195195
a folder which contains all the necessary executables to contain the
196196
packages that a Python project would need. An example workflow is given.
197197

198-
Install virtualenv::
198+
Install virtualenv:
199+
200+
.. code-block:: console
199201
200202
$ pip install virtualenv
201203
202204
203-
Create a virtual environment for a project::
205+
Create a virtual environment for a project:
206+
207+
.. code-block:: console
204208
205209
$ cd my_project
206210
$ virtualenv venv
@@ -211,22 +215,28 @@ library which you can use to install other packages. The name of the
211215
virtual environment (in this case, it was ``venv``) can be anything;
212216
omitting the name will place the files in the current directory instead.
213217

214-
To start using the virtual environment, run::
218+
To start using the virtual environment, run:
219+
220+
.. code-block:: console
215221
216222
$ source venv/bin/activate
217223
218224
219225
The name of the current virtual environment will now appear on the left
220226
of the prompt (e.g. ``(venv)Your-Computer:your_project UserName$``) to
221227
let you know that it's active. From now on, any package that you install
222-
using ``pip`` will be placed in the venv folder, isolated from the global
223-
Python installation. Install packages as usual::
228+
using ``pip`` will be placed in the ``venv`` folder, isolated from the global
229+
Python installation.
230+
231+
Install packages as usual:
232+
233+
.. code-block:: console
224234
225235
$ pip install requests
226236
227-
To stop using an environment simply type ``deactivate``. To remove the
237+
To stop using an environment, simply type ``deactivate``. To remove the
228238
environment, just remove the directory it was installed into. (In this
229-
case, it would be ``rm -rf venv``).
239+
case, it would be ``rm -rf venv``.)
230240

231241
Other Notes
232242
^^^^^^^^^^^
@@ -239,7 +249,7 @@ for keeping the package list clean in case it needs to be accessed later.
239249
In order to keep your environment consistent, it's a good idea to "freeze"
240250
the current state of the environment packages. To do this, run
241251

242-
::
252+
.. code-block:: console
243253
244254
$ pip freeze > requirements.txt
245255
@@ -249,7 +259,7 @@ versions. Later, when a different developer (or you, if you need to re-
249259
create the environment) can install the same packages, with the same
250260
versions by running
251261

252-
::
262+
.. code-block:: console
253263
254264
$ pip install -r requirements.txt
255265
@@ -265,14 +275,14 @@ virtualenvwrapper
265275
`Virtualenvwrapper <http://pypi.python.org/pypi/virtualenvwrapper>`_ makes
266276
virtualenv a pleasure to use by wrapping the command line API with a nicer CLI.
267277

268-
::
278+
.. code-block:: console
269279
270280
$ pip install virtualenvwrapper
271281
272282
273-
Put this into your `~/.bash_profile` (Linux/Mac) file:
283+
Put this into your ``~/.bash_profile`` (Linux/Mac) file:
274284

275-
::
285+
.. code-block:: console
276286
277287
$ export VIRTUALENVWRAPPER_VIRTUALENV_ARGS='--no-site-packages'
278288
@@ -312,7 +322,7 @@ most out of using Python interactively. Its main components are:
312322
* Flexible, embeddable interpreters to load into your own projects.
313323
* Tools for high level and interactive parallel computing.
314324

315-
::
325+
.. code-block:: console
316326
317327
$ pip install ipython
318328
@@ -333,7 +343,7 @@ Python interpreter for Unix-like operating systems. It has the following feature
333343
* Auto-indentation.
334344
* Python 3 support.
335345

336-
::
346+
.. code-block:: console
337347
338348
$ pip install bpython
339349

docs/index.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ The Hitchhiker's Guide to Python!
88

99
Welcome to The Hitchhiker's Guide to Python.
1010

11-
**This guide is currently under heavy active development.** If you'd like to help, `fork us on GitHub <https://github.com/kennethreitz/python-guide>`_!
11+
**This guide is currently under heavy active development.** If you'd like to help,
12+
`fork us on GitHub <https://github.com/kennethreitz/python-guide>`_!
1213

1314
This *opinionated* guide exists to provide both novice and expert Python
1415
developers a best-practice handbook to the installation, configuration, and

docs/intro/duction.rst

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ Python is a general-purpose, high-level programming language similar
77
to Tcl, Perl, Ruby, Scheme, or Java. Some of its main key features
88
include:
99

10-
* very clear, readable syntax
10+
* **very clear, readable syntax**
1111

1212
Python's philosophy focuses on readability, from code blocks
1313
delineated with significant whitespace to intuitive keywords in
1414
place of inscrutable punctuation
1515

16-
* extensive standard libraries and third party modules for virtually
17-
any task
16+
* **extensive standard libraries and third party modules for virtually
17+
any task**
1818

1919
Python is sometimes described with the words "batteries included"
2020
for its extensive
@@ -30,21 +30,21 @@ include:
3030
the `Django <http://www.djangoproject.com>`_ web framework and the
3131
`NumPy <http://numpy.scipy.org>`_ set of math routines.
3232

33-
* integration with other systems
33+
* **integration with other systems**
3434

3535
Python can integrate with `Java libraries <http://www.jython.org>`_,
3636
enabling it to be used with the rich Java environment that corporate
3737
programmers are used to. It can also be
3838
`extended by C or C++ modules <http://docs.python.org/extending/>`_
3939
when speed is of the essence.
4040

41-
* ubiquity on computers
41+
* **ubiquity on computers**
4242

4343
Python is available on Windows, \*nix, and Mac. It runs wherever the
4444
Java virtual machine runs, and the reference implementation CPython
4545
can help bring Python to wherever there is a working C compiler.
4646

47-
* friendly community
47+
* **friendly community**
4848

4949
Python has a vibrant and large :ref:`community <the-community>`
5050
which maintains wikis, conferences, countless repositories,
@@ -77,10 +77,12 @@ For the Community
7777

7878
All contributions to the Guide are welcome, from Pythonistas of all levels.
7979
If you think there's a gap in what the Guide covers, fork the Guide on
80-
GitHub and submit a pull request. Contributions are welcome from everyone,
81-
whether they're an old hand or a first-time Pythonista, and the authors to
82-
the Guide will gladly help if you have any questions about the
83-
appropriateness, completeness, or accuracy of a contribution.
80+
GitHub and submit a pull request.
81+
82+
Contributions are welcome from everyone, whether they're an old hand or a
83+
first-time Pythonista, and the authors to the Guide will gladly help if you
84+
have any questions about the appropriateness, completeness, or accuracy of
85+
a contribution.
8486

8587
To get started working on The Hitchhiker's Guide, see the :doc:`/notes/contribute` page.
8688

docs/notes/styleguide.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ Strive to keep any contributions relevant to the :ref:`purpose of The Guide
3030
* `Cite <http://sphinx.pocoo.org/rest.html?highlight=citations#citations>`_
3131
references where needed.
3232
* If a subject isn't directly relevant to Python, but useful in conjunction
33-
with Python (ex: Git, Github, Databases), reference by linking to useful
34-
resources and describe why it's useful to Python.
33+
with Python (e.g., Git, GitHub, Databases), reference by linking to useful
34+
resources, and describe why it's useful to Python.
3535
* When in doubt, ask.
3636

3737
Headings

docs/scenarios/admin.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ latter will ssh into each server, cd to our project directory, activate the
2121
virtual environment, pull the newest codebase, and restart the application
2222
server.
2323

24-
::
24+
.. code-block:: python
2525
2626
from fabric.api import cd, env, prefix, run, task
2727

docs/scenarios/db.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ SQLAlchemy
2020
Unlike many database libraries it not only provides an ORM layer but also a
2121
generalized API for writing database-agnostic code without SQL.
2222

23-
::
23+
.. code-block:: console
2424
25-
pip install sqlalchemy
25+
$ pip install sqlalchemy
2626
2727
Django ORM
2828
----------

docs/scenarios/imaging.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ the instructions for your platform `here <https://pypi.python.org/pypi/Pillow/2.
2323

2424
After that, it's straightforward:
2525

26-
.. code-block:: bash
26+
.. code-block:: console
2727
2828
$ pip install Pillow

docs/scenarios/scrape.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ After a quick analysis, we see that in our page the data is contained in
5656
two elements - one is a div with title 'buyer-name' and the other is a
5757
span with class 'item-price':
5858

59-
::
59+
.. code-block:: html
6060

6161
<div title="buyer-name">Carson Busses</div>
6262
<span class="item-price">$29.95</span>

docs/scenarios/speed.rst

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ Using a slightly modified version of `David Beazleys`_ CPU bound test code
88
(added loop for multiple tests), you can see the difference between CPython
99
and PyPy's processing.
1010

11-
::
11+
.. code-block:: console
1212
13-
PyPy
13+
# PyPy
1414
$ ./pypy -V
1515
Python 2.7.1 (7773f8fc4223, Nov 18 2011, 18:47:10)
1616
[PyPy 1.7.0 with GCC 4.4.3]
@@ -21,9 +21,9 @@ and PyPy's processing.
2121
0.0440690517426
2222
0.0695300102234
2323
24-
::
24+
.. code-block:: console
2525
26-
CPython
26+
# CPython
2727
$ ./python -V
2828
Python 2.7.1
2929
$ ./python measure2.py
@@ -72,9 +72,10 @@ Cython
7272
with which you are able to write C and C++ modules for Python. Cython also
7373
allows you to call functions from compiled C libraries. Using Cython allows
7474
you to take advantage of Python's strong typing of variables and operations.
75-
Here is an example of strong typing with Cython:
7675

77-
.. code-block:: python
76+
Here's an example of strong typing with Cython:
77+
78+
.. code-block:: cython
7879
7980
def primes(int kmax):
8081
"""Calculation of prime numbers with additional
@@ -128,7 +129,7 @@ Notice that in the Cython version you declare integers and integer arrays for
128129
to be compiled into C types while also creating a Python list:
129130

130131

131-
.. code-block:: python
132+
.. code-block:: cython
132133
133134
def primes(int kmax):
134135
"""Calculation of prime numbers with additional
@@ -190,18 +191,22 @@ The `pyximport` module allows you to import `pyx` files (e.g., `primesCy.pyx`) w
190191
The `pyximport.install()` command allows the Python interpreter to start the Cython compiler directly to generate C-code,
191192
which is automatically compiled to a `*.so` C-library. Cython is able to import this library for you in your Python-code.
192193
Very easy and very efficient. With the `time.time()` function you are able to compare the time between this 2 different calls to find 500 prime numbers.
194+
On a standard notebook (dual core AMD E-450 1.6 GHz), the measured values are:
195+
196+
.. code-block:: console
197+
198+
Cython time: 0.0054 seconds
193199
194-
On a standard notebook (dualcore AMD E-450 1,6 GHz) the measured values are:
200+
Python time: 0.0566 seconds
195201
196-
Cython time: 0.0054 seconds
197202
198-
Python time: 0.0566 seconds
199203
200204
And here the output of an embedded `ARM beaglebone <http://beagleboard.org/Products/BeagleBone>`_ machine:
205+
.. code-block:: console
201206
202-
Cython time: 0.0196 seconds
207+
Cython time: 0.0196 seconds
203208
204-
Python time: 0.3302 seconds
209+
Python time: 0.3302 seconds
205210
206211
Pyrex
207212
-----

0 commit comments

Comments
 (0)