From 1e4b4a5460b0409f16e892e94f8d62414cfd9e9a Mon Sep 17 00:00:00 2001 From: Zearin Date: Fri, 28 Mar 2014 13:26:24 -0400 Subject: [PATCH] =?UTF-8?q?docs/**:=20Specify=20language=20for=20code-bloc?= =?UTF-8?q?ks=20(syntax=20highlighting!=20=20mmm=E2=80=A6)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/scenarios/admin.rst | 2 +- docs/scenarios/db.rst | 4 ++-- docs/scenarios/imaging.rst | 2 +- docs/scenarios/scrape.rst | 2 +- docs/scenarios/speed.rst | 29 +++++++++++++++++------------ docs/shipping/freezing.rst | 6 +++++- docs/starting/install/osx.rst | 4 +++- docs/starting/install/win.rst | 6 +++++- docs/writing/documentation.rst | 8 ++++++-- docs/writing/style.rst | 15 ++++++++++----- docs/writing/tests.rst | 13 +++++++------ 11 files changed, 58 insertions(+), 33 deletions(-) diff --git a/docs/scenarios/admin.rst b/docs/scenarios/admin.rst index 5fca65f..26dc5e6 100644 --- a/docs/scenarios/admin.rst +++ b/docs/scenarios/admin.rst @@ -21,7 +21,7 @@ latter will ssh into each server, cd to our project directory, activate the virtual environment, pull the newest codebase, and restart the application server. -:: +.. code-block:: python from fabric.api import cd, env, prefix, run, task diff --git a/docs/scenarios/db.rst b/docs/scenarios/db.rst index 787f0ef..252d9d7 100644 --- a/docs/scenarios/db.rst +++ b/docs/scenarios/db.rst @@ -20,9 +20,9 @@ SQLAlchemy Unlike many database libraries it not only provides an ORM layer but also a generalized API for writing database-agnostic code without SQL. -:: +.. code-block:: console - pip install sqlalchemy + $ pip install sqlalchemy Django ORM ---------- diff --git a/docs/scenarios/imaging.rst b/docs/scenarios/imaging.rst index fa71882..4103c36 100644 --- a/docs/scenarios/imaging.rst +++ b/docs/scenarios/imaging.rst @@ -23,6 +23,6 @@ the instructions for your platform `here Carson Busses $29.95 diff --git a/docs/scenarios/speed.rst b/docs/scenarios/speed.rst index 0219cf3..bee6769 100644 --- a/docs/scenarios/speed.rst +++ b/docs/scenarios/speed.rst @@ -8,9 +8,9 @@ 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. -:: +.. code-block:: console - PyPy + # PyPy $ ./pypy -V Python 2.7.1 (7773f8fc4223, Nov 18 2011, 18:47:10) [PyPy 1.7.0 with GCC 4.4.3] @@ -21,9 +21,9 @@ and PyPy's processing. 0.0440690517426 0.0695300102234 -:: +.. code-block:: console - CPython + # CPython $ ./python -V Python 2.7.1 $ ./python measure2.py @@ -72,9 +72,10 @@ Cython with which you are able to write C and C++ modules for Python. Cython also allows you to call functions from compiled C libraries. Using Cython allows you to take advantage of Python's strong typing of variables and operations. -Here is an example of strong typing with Cython: -.. code-block:: python +Here's an example of strong typing with Cython: + +.. code-block:: cython def primes(int kmax): """Calculation of prime numbers with additional @@ -128,7 +129,7 @@ Notice that in the Cython version you declare integers and integer arrays for to be compiled into C types while also creating a Python list: -.. code-block:: python +.. code-block:: cython def primes(int kmax): """Calculation of prime numbers with additional @@ -190,18 +191,22 @@ The `pyximport` module allows you to import `pyx` files (e.g., `primesCy.pyx`) w The `pyximport.install()` command allows the Python interpreter to start the Cython compiler directly to generate C-code, which is automatically compiled to a `*.so` C-library. Cython is able to import this library for you in your Python-code. 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. +On a standard notebook (dual core AMD E-450 1.6 GHz), the measured values are: -On a standard notebook (dualcore AMD E-450 1,6 GHz) the measured values are: +.. code-block:: console + + Cython time: 0.0054 seconds + + Python time: 0.0566 seconds -Cython time: 0.0054 seconds -Python time: 0.0566 seconds And here the output of an embedded `ARM beaglebone `_ machine: +.. code-block:: console -Cython time: 0.0196 seconds + Cython time: 0.0196 seconds -Python time: 0.3302 seconds + Python time: 0.3302 seconds Pyrex ----- diff --git a/docs/shipping/freezing.rst b/docs/shipping/freezing.rst index 2722c12..888127e 100644 --- a/docs/shipping/freezing.rst +++ b/docs/shipping/freezing.rst @@ -59,6 +59,8 @@ Prerequisite is to install :ref:`Python on Windows `. 2. Write setup.py (`List of configuration options `_):: +.. code-block:: python + from distutils.core import setup import py2exe @@ -70,7 +72,9 @@ Prerequisite is to install :ref:`Python on Windows `. 4. (Optionally) `one-file mode `_ -5. Generate `.exe` into `dist` directory:: +5. Generate ``.exe`` into ``dist`` directory: + +.. code-block:: console $ python setup.py py2exe diff --git a/docs/starting/install/osx.rst b/docs/starting/install/osx.rst index ac05a0d..1633337 100644 --- a/docs/starting/install/osx.rst +++ b/docs/starting/install/osx.rst @@ -53,7 +53,9 @@ line at the bottom of your ``~/.bashrc`` file export PATH=/usr/local/bin:/usr/local/sbin:$PATH -Now, we can install Python 2.7: :: +Now, we can install Python 2.7: + +.. code-block:: console $ brew install python diff --git a/docs/starting/install/win.rst b/docs/starting/install/win.rst index b71b882..f21e2d5 100644 --- a/docs/starting/install/win.rst +++ b/docs/starting/install/win.rst @@ -25,9 +25,13 @@ tedious, so add the directories for your default Python version to the PATH. Assuming that your Python installation is in ``C:\Python27\``, add this to your PATH:: +.. code-block:: console + C:\Python27\;C:\Python27\Scripts\ -You can do this easily by running the following in ``powershell``:: +You can do this easily by running the following in ``powershell``: + +.. code-block:: console [Environment]::SetEnvironmentVariable("Path", "$env:Path;C:\Python27\;C:\Python27\Scripts\", "User") diff --git a/docs/writing/documentation.rst b/docs/writing/documentation.rst index 3f4d0b9..29de3e4 100644 --- a/docs/writing/documentation.rst +++ b/docs/writing/documentation.rst @@ -100,7 +100,9 @@ code easier to understand. In Python, comments begin with a hash .. _docstring-ref: -In Python, *docstrings* describe modules, classes, and functions: :: +In Python, *docstrings* describe modules, classes, and functions: + +.. code-block:: python def square_and_rooter(x): """Returns the square root of self times self.""" @@ -130,7 +132,9 @@ Docstrings versus Block comments These aren't interchangeable. For a function or class, the leading comment block is a programmer's note. The docstring describes the -operation of the function or class: :: +*operation* of the function or class: + +.. code-block:: python # This function slows down program execution for some reason. def square_and_rooter(x): diff --git a/docs/writing/style.rst b/docs/writing/style.rst index cba3586..165117f 100644 --- a/docs/writing/style.rst +++ b/docs/writing/style.rst @@ -336,7 +336,9 @@ Instead, use a list comprehension: four_lists = [[] for __ in xrange(4)] -A common idiom for creating strings is to use :py:meth:`str.join` on an empty string.:: +A common idiom for creating strings is to use :py:meth:`str.join` on an empty string. + +.. code-block:: python letters = ['s', 'p', 'a', 'm'] word = ''.join(letters) @@ -345,7 +347,9 @@ This will set the value of the variable *word* to 'spam'. This idiom can be appl Sometimes we need to search through a collection of things. Let's look at two options: lists and dictionaries. -Take the following code for example:: +Take the following code for example: + +.. code-block:: python d = {'s': [], 'p': [], 'a': [], 'm': []} l = ['s', 'p', 'a', 'm'] @@ -365,7 +369,7 @@ Zen of Python Also known as :pep:`20`, the guiding principles for Python's design. -:: +.. code-block:: pycon >>> import this The Zen of Python, by Tim Peters @@ -406,14 +410,15 @@ exists a command-line program, `pep8 `_, that can check your code for conformance. Install it by running the following command in your Terminal: -:: + +.. code-block:: console $ pip install pep8 Then run it on a file or series of files to get a report of any violations. -:: +.. code-block:: console $ pep8 optparse.py optparse.py:69:11: E401 multiple imports on one line diff --git a/docs/writing/tests.rst b/docs/writing/tests.rst index cb863c0..b854bf0 100644 --- a/docs/writing/tests.rst +++ b/docs/writing/tests.rst @@ -81,7 +81,7 @@ series of tools. Creating testcases is accomplished by subclassing a TestCase base class -:: +.. code-block:: python import unittest @@ -148,7 +148,7 @@ py.test is a no-boilerplate alternative to Python's standard unittest module. Despite being a fully-featured and extensible test tool, it boasts a simple syntax. Creating a test suite is as easy as writing a module with a couple of -functions +functions: .. code-block:: python @@ -251,9 +251,10 @@ the need to change any other code. mock ---- -mock is a library for testing in Python. Starting with Python 3.3, it is -available in the `standard library