Mercurial > pylearn
comparison doc/v2_planning/coding_style.txt @ 1155:b70a1fcb7b4f
coding_style: tools to make life easier and automating certain processes
author | Dumitru Erhan <dumitru.erhan@gmail.com> |
---|---|
date | Fri, 17 Sep 2010 16:09:02 +0300 |
parents | 0904dd74894d |
children | 531e77fb67f2 a0f178bc9052 |
comparison
equal
deleted
inserted
replaced
1154:f923dddf0bf7 | 1155:b70a1fcb7b4f |
---|---|
172 * Some random guy guidelines (nothing special): http://www.voidspace.org.uk/python/articles/python_style_guide.shtml | 172 * Some random guy guidelines (nothing special): http://www.voidspace.org.uk/python/articles/python_style_guide.shtml |
173 | 173 |
174 We will probably want to take PEP-8 as starting point, and read what other | 174 We will probably want to take PEP-8 as starting point, and read what other |
175 people think about it / how other coding guidelines differ from it. | 175 people think about it / how other coding guidelines differ from it. |
176 | 176 |
177 Dumi: we should also try to find tools that automate these | |
178 processes: pylint, pyflakes, pychecker, pythontidy | |
179 | |
180 OD: Things about PEP 8 I don't like (but it may be just me): | 177 OD: Things about PEP 8 I don't like (but it may be just me): |
181 | 178 |
182 * If necessary, you can add an extra pair of parentheses around an | 179 * If necessary, you can add an extra pair of parentheses around an |
183 expression, but sometimes using a backslash looks better. | 180 expression, but sometimes using a backslash looks better. |
184 --> I rarely find that backslash looks better. In most situations you can | 181 --> I rarely find that backslash looks better. In most situations you can |
267 to use warning instead of logging. (DWF) | 264 to use warning instead of logging. (DWF) |
268 | 265 |
269 * Automatized code verification | 266 * Automatized code verification |
270 Use pychecker & friends to make sure everything is fine. | 267 Use pychecker & friends to make sure everything is fine. |
271 Task: Look into the various options available (DE) | 268 Task: Look into the various options available (DE) |
269 Result: See sections 'Tools to help us out' and 'Automating and enforcing coding | |
270 style' | |
272 | 271 |
273 * Tests | 272 * Tests |
274 Force people to write tests. Automatic email reminder of code lines not | 273 Force people to write tests. Automatic email reminder of code lines not |
275 covered by tests (see if we can get this from nosetests). Decorator to mark | 274 covered by tests (see if we can get this from nosetests). Decorator to mark |
276 some classes / methods as not being tested yet, so as to be able to | 275 some classes / methods as not being tested yet, so as to be able to |
397 * Standardize the merge commit text (what is the message from fetch?) | 396 * Standardize the merge commit text (what is the message from fetch?) |
398 | 397 |
399 During committee's meeting, Fred mentioned a bug with Assembla links for | 398 During committee's meeting, Fred mentioned a bug with Assembla links for |
400 multi-line commits. | 399 multi-line commits. |
401 | 400 |
401 Tools to help us out | |
402 --------------------- | |
403 | |
404 Dumi: | |
405 | |
406 * pylint: highly configurable and very popular tool, similar in spirit to lint | |
407 for C. Can specify a config file, customize/disable warnings and errors, hook | |
408 it to vim/emacs and include coding style convensions in the check too. A nice | |
409 feature is that you can include a comment like "# pylint: disable-msg=C0103" | |
410 into a file and disable a message locally. This is nice and dangerous at the | |
411 same time. Another cool feature is incremental checking with caching of | |
412 results, which also allows tracking of progress. | |
413 | |
414 * pyflakes: pylint alternative that is supposedly faster, but is I think more | |
415 limited in the number of things it is good at: "PyFlakes will tell you when | |
416 you have forgotten an import, mistyped a variable name, defined two functions | |
417 with the same name, shadowed a variable from another scope, imported a module | |
418 twice, or two different modules with the same name, and so on.". Most reviews | |
419 found online praise the speed, but note that pylint is clearly superior in | |
420 every other respect. | |
421 | |
422 * pychecker: it actually *imports* each module (not sure if pylint does this). | |
423 It seems that pylint = pychecker + coding style and that pylint is more | |
424 popular. | |
425 | |
426 * pep8: if all you care is about obeying PEP-8: | |
427 http://pypi.python.org/pypi/pep8 (includes the actual PEP-8 snippets with the | |
428 errors found, which is neat). Otherwise, pylint seems like a superset of this. | |
429 | |
430 * http://www.doughellmann.com/articles/pythonmagazine/completely-different/2008-03-linters/index.html | |
431 - article from 2008 comparing pylint, pychecker, and pyflakes. The conclusion | |
432 is to use pylint, more or less. | |
433 | |
434 I say we stick with pylint for now as it provides a great degree of flexibility | |
435 in a single mature package. | |
436 | |
437 * vim + pylint: http://www.vim.org/scripts/script.php?script_id=891 | |
438 * emcas + pylint: http://www.emacswiki.org/emacs/PythonProgrammingInEmacs#toc5 | |
439 | |
440 Automating and enforcing coding style | |
441 ------------------------------------- | |
442 | |
443 Ideally, we would like to have a uniform approach to this, where everyone tests | |
444 against the same tool(s) and uses the same list of disabled warnings etc. | |
445 | |
446 Dumi: there are several ways of approaching this, independently of the tools used: | |
447 | |
448 * Create a precommit hook for mercurial, which runs the tool(s) of choice and | |
449 generates warnings or aborts the commit process. This hook is a simple Python | |
450 module (well, as simple as we want it to be), which we can include into | |
451 everyone's hgrc, in the precommit.pylint variable, for instance. An example | |
452 is http://github.com/jrburke/dvcs_jslint/blob/master/dvcs_jslint.js. The | |
453 advantage of this approach is that the load is distributed and | |
454 errors/warnings are caught client-side, before the commit. | |
455 | |
456 * Another client-side option is to have editor plugins for the various style | |
457 checkers: vim and emacs can access pylint pretty easily for instance. | |
458 | |
459 * Instead of doing this client-side, one can do things server-side. On | |
460 Assembla, this means using their Webhooks | |
461 (http://www.assembla.com/spaces/demostuff/webhook_tool), since HTTP-based | |
462 hooks that we would need to tie with our buildbot server (whichever server we | |
463 choose that to be). | |
464 | |
465 * I (DE) prefer starting with the client-side approach, as it is easier to | |
466 implement, has no single point of failure and is deployable fast. We could | |
467 have a "batch" script that runs our lint tools in conjunction with hg | |
468 annotate and sends hate-mail once a week to offenders who have somehow | |
469 slipped things through the cracks. Also on the server-side we could run | |
470 time-consuming checking (though how such checks would differ from tests is | |
471 unclear). | |
472 | |
473 Note that: | |
474 | |
475 * I haven't found anything ready-made online, so we need to write these | |
476 hooks ourselves. | |
477 * I think we should make it so that it is not possible to commit things if | |
478 pylint reports an actual error. | |
479 | |
402 Type checking | 480 Type checking |
403 ------------- | 481 ------------- |
404 | 482 |
405 (Suggested by Francois Savard) | 483 (Suggested by Francois Savard) |
406 | 484 |