Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Code quality in Python - tools and reasons

946 views

Published on

Presentation from talk on EuroPython 2015

Published in: Software
  • Be the first to comment

Code quality in Python - tools and reasons

  1. 1. You can’t automatically check if code is good
  2. 2. Code quality in Python - tools and reasons Radosław Ganczarek
  3. 3. Rice’s theorem
  4. 4. Rice’s theorem (You probably haven’t heard of it) for any non-trivial property of partial functions, no general and effective method can decide whether an algorithm computes a partial function with that property
  5. 5. Rice’s theorem In the common language: you can’t write a algorithm, that will check in finite time if a program has some nontrivial property
  6. 6. You can’t write a dictionary containing all good programs
  7. 7. Examples You can’t automatically check if: ● program never fails ● there is any data set, for which program returns “1” ● program is well written and will be readable for humans ● program’s WTF factor will be low
  8. 8. But you can try hard ...
  9. 9. Don’t worry! It’s not that hard!
  10. 10. We’ve got many tools Checkers Formatters Import sorters Coverage Docstring checkers Dead code checkers ...
  11. 11. What’s this talk about? YES Developer’s view Checking code every day General tools Python 2.7 Jenkins NO Manager’s view Charts and tables Django, flask, web2py etc. Python 3.* Buildbot, Travis etc. Checkers for other languages Import graph visualisation
  12. 12. Let’s get started!
  13. 13. Checkers
  14. 14. pep8
  15. 15. pyflakes
  16. 16. mccabe
  17. 17. radon
  18. 18. flake8
  19. 19. pylint
  20. 20. The lure of Pylama Pro: ● all tools in one module Con: ● Configuration
  21. 21. Other tools pep257 vulture isort
  22. 22. pep257
  23. 23. Vulture
  24. 24. isort
  25. 25. Extensions flake8 (other checks - imports, docstrings etc.) pylint (specific settings - Django, flask etc.) pylama (new checkers) browsing raw code vs AST
  26. 26. Extensions Example: mccabe extension to flake8
  27. 27. Formatters autopep8 yapf isort
  28. 28. Autopep8 ● Doesn’t fix everything ● Leaves ugly line breaks
  29. 29. Yapf - our saviour
  30. 30. Isort
  31. 31. Test coverage coverage module How to run Common problems Comparing with master
  32. 32. Utils diff-cover diff-quality git-lint hgdiffmetrics scspell3k
  33. 33. diff-cover, diff-quality
  34. 34. git-lint, hgdiffmetrics
  35. 35. scspell3k
  36. 36. Automation tox py.test Jenkins Github PR builder plugin
  37. 37. Tox example (from diff-cover app)
  38. 38. OK, got it. But why?
  39. 39. Benefits? ● refactor confidence ● uniform style Pro tip: buzzwords for managers: ● maintainability ● readability ● extendability
  40. 40. Questions?
  41. 41. Mandatory Monty Python screen
  42. 42. About me Radosław Ganczarek Senior Python Developer @ (http://stxnext.com) From Wrocław (Poland) https://pl.linkedin.com/in/dreamwalker

×