| 1 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 2 |
Cheesecake: How tasty is your code? |
|---|
| 3 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 4 |
|
|---|
| 5 |
.. contents:: **Table of Contents** |
|---|
| 6 |
|
|---|
| 7 |
Summary |
|---|
| 8 |
------- |
|---|
| 9 |
|
|---|
| 10 |
The idea of the Cheesecake project is to rank Python packages based on various |
|---|
| 11 |
empirical "kwalitee" factors, such as: |
|---|
| 12 |
|
|---|
| 13 |
* whether the package can be downloaded from PyPI given its name |
|---|
| 14 |
* whether the package can be unpacked |
|---|
| 15 |
* whether the package can be installed into an alternate directory |
|---|
| 16 |
* existence of certain files such as README, INSTALL, LICENSE, setup.py etc. |
|---|
| 17 |
* percentage of modules/functions/classes/methods with docstrings |
|---|
| 18 |
* ... and many others |
|---|
| 19 |
|
|---|
| 20 |
Currently, the Cheesecake index is computed for invidual packages obtained |
|---|
| 21 |
through a variety of methods (detailed below). One of the goals of the |
|---|
| 22 |
Cheesecake project is to automatically compute the Cheesecake index for |
|---|
| 23 |
all packages uploaded to the PyPI Cheese Shop (possibly at upload time) and |
|---|
| 24 |
to maintain a collection of Web pages with statistics related to the |
|---|
| 25 |
various indexes of the packages. |
|---|
| 26 |
|
|---|
| 27 |
Cheesecake currently computes 3 types of indexes: |
|---|
| 28 |
|
|---|
| 29 |
* installability index |
|---|
| 30 |
* documentation index |
|---|
| 31 |
* code kwalitee index |
|---|
| 32 |
|
|---|
| 33 |
The algorithms for computing each index type are detailed below. |
|---|
| 34 |
|
|---|
| 35 |
Why Cheesecake? |
|---|
| 36 |
--------------- |
|---|
| 37 |
|
|---|
| 38 |
The concept of "kwalitee" originated in the Perl community. Here's a relevant |
|---|
| 39 |
quote: |
|---|
| 40 |
|
|---|
| 41 |
*It looks like quality, it sounds like quality, but it's not quite quality.* |
|---|
| 42 |
|
|---|
| 43 |
Kwalitee is an empiric measure of how good a specific body of code is. It |
|---|
| 44 |
defines quality indicators and measures the code along them. It is currently |
|---|
| 45 |
used by the `CPANTS Testing Service <http://cpants.dev.zsi.at/index.html>`_ |
|---|
| 46 |
to evaluate the 'goodness' of CPAN packages. |
|---|
| 47 |
|
|---|
| 48 |
Since the Python package repository (aka `PyPI <http://www.python.org/pypi>`_) |
|---|
| 49 |
is hosted at the Cheese Shop, |
|---|
| 50 |
it stands to reason that the quality indicator of a PyPI package should be |
|---|
| 51 |
called the Cheesecake index! |
|---|
| 52 |
|
|---|
| 53 |
Requirements |
|---|
| 54 |
------------ |
|---|
| 55 |
|
|---|
| 56 |
* `pylint <http://www.logilab.org/projects/pylint>`_ is required for |
|---|
| 57 |
part of the code kwalitee index computation |
|---|
| 58 |
* `setuptools <http://peak.telecommunity.com/DevCenter/setuptools>`_ is |
|---|
| 59 |
required for testing installation |
|---|
| 60 |
|
|---|
| 61 |
Usage examples |
|---|
| 62 |
-------------- |
|---|
| 63 |
|
|---|
| 64 |
To compute the Cheesecake index for a given project, run the cheesecake.py |
|---|
| 65 |
module from the command line and indicate either: |
|---|
| 66 |
|
|---|
| 67 |
* the package short name (e.g. twill) or |
|---|
| 68 |
* the package URL (e.g. http://darcs.idyll.org/~t/projects/twill-0.7.4.tar.gz) or |
|---|
| 69 |
* the package path on the file system (e.g. /tmp/twill-latest.tar.gz) |
|---|
| 70 |
|
|---|
| 71 |
In all cases, the cheesecake module will attempt to download the package |
|---|
| 72 |
if necessary, then to unpack it in a sandbox directory (/tmp/cheesecake_sandbox |
|---|
| 73 |
by default). If either of these operations fails, the Cheesecake index for |
|---|
| 74 |
the package will be 0. If the package can be successfully unpacked, the |
|---|
| 75 |
cheesecake module will compute the values for a variety of indexes detailed |
|---|
| 76 |
in the algorithm given at the end of this file. |
|---|
| 77 |
|
|---|
| 78 |
If the package can be successfully downloaded and unpacked, a log file is |
|---|
| 79 |
created in the system /tmp directory and named <package>.log (e.g. the log file |
|---|
| 80 |
for twill-0.7.4.tar.gz is /tmp/twill-0.7.4.tar.gz.log). |
|---|
| 81 |
The log file is automatically deleted after the Cheesecake index is |
|---|
| 82 |
computed, except for situations when error has occured. |
|---|
| 83 |
|
|---|
| 84 |
Command-line examples: |
|---|
| 85 |
|
|---|
| 86 |
1. Compute the Cheesecake index for the Durus package by using setuptools |
|---|
| 87 |
utilities to download the package from PyPI:: |
|---|
| 88 |
|
|---|
| 89 |
python cheesecake.py --name=Durus |
|---|
| 90 |
|
|---|
| 91 |
2. Compute the Cheesecake index for the Durus package by indicating its URL:: |
|---|
| 92 |
|
|---|
| 93 |
python cheesecake.py --url=http://www.mems-exchange.org/software/durus/Durus-3.1.tar.gz |
|---|
| 94 |
|
|---|
| 95 |
3. Compute the Cheesecake index for the twill package by indicating its path |
|---|
| 96 |
on the local file system:: |
|---|
| 97 |
|
|---|
| 98 |
python cheesecake.py --path=/tmp/twill-latest.tar.gz |
|---|
| 99 |
|
|---|
| 100 |
4. To increase the verbosity of the output, use the -v or --verbose option. |
|---|
| 101 |
For more options, run cheesecake.py with -h or --help. |
|---|
| 102 |
|
|---|
| 103 |
Obtaining the source code |
|---|
| 104 |
------------------------- |
|---|
| 105 |
|
|---|
| 106 |
You can get the source code via svn:: |
|---|
| 107 |
|
|---|
| 108 |
svn co http://svn.pycheesecake.org/trunk cheesecake |
|---|
| 109 |
|
|---|
| 110 |
*Note*: make sure you indicate the target directory when you do the svn checkout, |
|---|
| 111 |
otherwise the cheesecake package files will be checked out directly in your |
|---|
| 112 |
current directory. |
|---|
| 113 |
|
|---|
| 114 |
The source code is also available with [http://pycheesecake.org/browser browsing] |
|---|
| 115 |
on project's Trac wiki. |
|---|
| 116 |
|
|---|
| 117 |
You may want to modify your subversion client configuration to automatically |
|---|
| 118 |
expand tags, like $Id$, $Author$ etc. To do so add following two lines to your |
|---|
| 119 |
``/.subversion/config``:: |
|---|
| 120 |
|
|---|
| 121 |
enable-auto-props = yes |
|---|
| 122 |
|
|---|
| 123 |
in [miscellany] section, and:: |
|---|
| 124 |
|
|---|
| 125 |
*.py = svn:eol-style=native;svn:keywords=Author Date Id Revision |
|---|
| 126 |
|
|---|
| 127 |
in [auto-props] section. |
|---|
| 128 |
|
|---|
| 129 |
Buildbot |
|---|
| 130 |
-------- |
|---|
| 131 |
|
|---|
| 132 |
A buildbot is happily running svn updates and unit tests. Check it out |
|---|
| 133 |
`here <http://agilistas.org:8888/>`_. |
|---|
| 134 |
|
|---|
| 135 |
Mailing list |
|---|
| 136 |
------------ |
|---|
| 137 |
|
|---|
| 138 |
Developer mailing list: http://lists.sourceforge.net/lists/listinfo/cheesecake-devel |
|---|
| 139 |
|
|---|
| 140 |
License |
|---|
| 141 |
------- |
|---|
| 142 |
|
|---|
| 143 |
Cheesecake is licensed under the Python Software Foundation license, |
|---|
| 144 |
the same license that governs Python itself. The text of the license is |
|---|
| 145 |
available in the ``LICENSE`` file in the source code distribution and |
|---|
| 146 |
can also be downloaded from |
|---|
| 147 |
http://www.opensource.org/licenses/PythonSoftFoundation.php. |
|---|
| 148 |
|
|---|
| 149 |
Authors contact info |
|---|
| 150 |
-------------------- |
|---|
| 151 |
|
|---|
| 152 |
Grig Gheorghiu |
|---|
| 153 |
|
|---|
| 154 |
:Email: <grig at gheorghiu dot net> |
|---|
| 155 |
:Web site: http://agiletesting.blogspot.com |
|---|
| 156 |
|
|---|
| 157 |
Michal Kwiatkowski |
|---|
| 158 |
|
|---|
| 159 |
:Email: <ruby at joker.linuxstuff.pl> |
|---|
| 160 |
:Web site: http://joker.linuxstuff.pl |
|---|
| 161 |
|
|---|
| 162 |
Note: clipart for the cheesecake slice logo used with permission from |
|---|
| 163 |
Kazumi Hatasa, Director, the Japanese School at Middlebury College, |
|---|
| 164 |
Purdue University. |
|---|
| 165 |
|
|---|
| 166 |
Algorithm for computing the Cheesecake index |
|---|
| 167 |
-------------------------------------------- |
|---|
| 168 |
|
|---|
| 169 |
Overall Cheesecke score is a sum of values of 3 main indexes |
|---|
| 170 |
(installability, documentation and code kwalitee). Values of these |
|---|
| 171 |
indexes rely on values of their subindexes and so on. Whole index tree |
|---|
| 172 |
and corresponding values for each leaf is presented below: |
|---|
| 173 |
|
|---|
| 174 |
* Installability |
|---|
| 175 |
|
|---|
| 176 |
* package is listed on and can be downloaded from PyPI: 50 |
|---|
| 177 |
* package can be downloaded from given URL: 25 |
|---|
| 178 |
* package can be unpacked without problems: 25 |
|---|
| 179 |
* unpacked package directory is the same as package name: 15 |
|---|
| 180 |
* package has setup.py: 25 |
|---|
| 181 |
* package can be installed to given directory via "setup.py install": 50 |
|---|
| 182 |
* package contain generated files, like .pyc: -20 |
|---|
| 183 |
|
|---|
| 184 |
* Documentation |
|---|
| 185 |
|
|---|
| 186 |
* package contain files listed below |
|---|
| 187 |
|
|---|
| 188 |
* README: 30 |
|---|
| 189 |
* LICENCE/COPYING: 30 [#oneof]_ |
|---|
| 190 |
* ANNOUNCE/CHANGELOG: 20 [#oneof]_ |
|---|
| 191 |
* INSTALL: 20 |
|---|
| 192 |
* AUTHORS: 10 |
|---|
| 193 |
* FAQ: 10 |
|---|
| 194 |
* NEWS: 10 |
|---|
| 195 |
* THANKS: 10 |
|---|
| 196 |
* TODO: 10 |
|---|
| 197 |
|
|---|
| 198 |
* package contain directories listed below |
|---|
| 199 |
|
|---|
| 200 |
* doc/docs: 30 [#oneof]_ |
|---|
| 201 |
* test/tests: 30 [#oneof]_ |
|---|
| 202 |
* demo/example/examples: 10 [#oneof]_ |
|---|
| 203 |
|
|---|
| 204 |
* code is documented by docstrings: 100 [#docstrings]_ |
|---|
| 205 |
* docstrings have proper formatting (like epytext or reST): 30 [#formatted]_ |
|---|
| 206 |
|
|---|
| 207 |
* Code Kwalitee |
|---|
| 208 |
|
|---|
| 209 |
* package has high pylint score: 50 |
|---|
| 210 |
* package uses at least one of known unit test frameworks: 30 |
|---|
| 211 |
|
|---|
| 212 |
Final score depends on how well package scores for all indexes |
|---|
| 213 |
listed above. Score is presented in absolute range (number of points) |
|---|
| 214 |
and relative (percent of gathered points compared to maximum). |
|---|
| 215 |
|
|---|
| 216 |
.. [#oneof] It is enough for a package to contain only one of listed files. |
|---|
| 217 |
.. [#docstrings] Number of points is proportional to percent of documentable objects |
|---|
| 218 |
(module, class or function) that have docstrings. For example, if |
|---|
| 219 |
you have 50 documentable objects and 32 of them have docstrings |
|---|
| 220 |
your code will get 64 points ('cause 64% of objects are documented). |
|---|
| 221 |
.. [#formatted] Number of points depends on number of docstrings that are found |
|---|
| 222 |
to contain one of known markup. Currently ReST, epytext and javadoc are |
|---|
| 223 |
recognized. We give 10 points for 25% of formatted docstrings, 20 points |
|---|
| 224 |
for 50% and 30 points for 75%. |
|---|
| 225 |
|
|---|
| 226 |
Sample output |
|---|
| 227 |
------------- |
|---|
| 228 |
|
|---|
| 229 |
:: |
|---|
| 230 |
|
|---|
| 231 |
$ python cheesecake_index -n Durus |
|---|
| 232 |
py_pi_download ......................... 50 (downloaded package Durus-3.4.1.tar.gz following 1 link from http://www.mems-exchange.org/software/durus/Durus-3.4.1.tar.gz) |
|---|
| 233 |
unpack ................................. 25 (package unpacked successfully) |
|---|
| 234 |
unpack_dir ............................. 15 (unpack directory is Durus-3.4.1 as expected) |
|---|
| 235 |
setup.py ............................... 25 (setup.py found) |
|---|
| 236 |
install ................................ 50 (package installed in /tmp/cheesecakebJ2JTZ/tmp_install_Durus-3.4.1) |
|---|
| 237 |
generated_files ........................ 0 (0 .pyc and 0 .pyo files found) |
|---|
| 238 |
--------------------------------------------- |
|---|
| 239 |
INSTALLABILITY INDEX (ABSOLUTE) ........ 165 |
|---|
| 240 |
INSTALLABILITY INDEX (RELATIVE) ........ 100 (165 out of a maximum of 165 points is 100%) |
|---|
| 241 |
|
|---|
| 242 |
required_files ......................... 150 (4 files and 2 required directories found) |
|---|
| 243 |
docstrings ............................. 33 (found 121/369=32.79% objects with docstrings) |
|---|
| 244 |
formatted_docstrings ................... 0 (found 6/369=1.63% objects with formatted docstrings) |
|---|
| 245 |
--------------------------------------------- |
|---|
| 246 |
DOCUMENTATION INDEX (ABSOLUTE) ......... 183 |
|---|
| 247 |
DOCUMENTATION INDEX (RELATIVE) ......... 53 (183 out of a maximum of 350 points is 53%) |
|---|
| 248 |
|
|---|
| 249 |
pylint ................................. 33 (pylint score was 6.59 out of 10) |
|---|
| 250 |
use_test_framework ..................... 30 (use one or more of known test frameworks) |
|---|
| 251 |
--------------------------------------------- |
|---|
| 252 |
CODE KWALITEE INDEX (ABSOLUTE) ......... 63 |
|---|
| 253 |
CODE KWALITEE INDEX (RELATIVE) ......... 79 (63 out of a maximum of 80 points is 79%) |
|---|
| 254 |
|
|---|
| 255 |
|
|---|
| 256 |
============================================= |
|---|
| 257 |
OVERALL CHEESECAKE INDEX (ABSOLUTE) .... 411 |
|---|
| 258 |
OVERALL CHEESECAKE INDEX (RELATIVE) .... 69 (411 out of a maximum of 595 points is 69%) |
|---|
| 259 |
|
|---|
| 260 |
Future plans |
|---|
| 261 |
------------ |
|---|
| 262 |
Cheesecake is under very active development. The immediate goal is to add the unit test |
|---|
| 263 |
index measurement, followed by other metrics inspired from the |
|---|
| 264 |
`kwalitee indicators <http://cpants.dev.zsi.at/kwalitee.html>`_. |
|---|
| 265 |
Please edit the `IndexMeasurementIdeas <http://pycheesecake.org/wiki/IndexMeasurementIdeas>`_ |
|---|
| 266 |
Wiki page to add things that you would like to see covered |
|---|
| 267 |
by the Cheesecake metrics. |
|---|
| 268 |
|
|---|
| 269 |
.. footer:: Last modified 2006-08-02 by `Michal Kwiatkowski <http://joker.linuxstuff.pl>`_. |
|---|