SlideShare a Scribd company logo
VVV
                         Validation and linting tool

                               Mikko Ohtamaa
                        http://twitter.com/moo9000
                         Python Helsinki meet-up




Tuesday, May 15, 2012
• Validation: HTML validator, CSS validator
                    • Linting: flag suspicious code: catch typing
                        errors, formatting errors



         https://en.wikipedia.org/wiki/Lint_programming_tool

Tuesday, May 15, 2012
foobar = get_magic()

                        try:

                               foobar.doSomething()

                        except:

                               fobar.doSomethingElse()




Tuesday, May 15, 2012
[~/code/vvv/demo]% vvv .

                        Running vvv against .

                        /Users/moo/code/vvv/demo/demo.py
                        validation output:

                        ************* Module demo

                        E0602: 15,4: Undefined variable 'fobar'



Tuesday, May 15, 2012
Why you need VVV

                    • Humans make human errors and are lazy
                    • Good practices must be enforced
                        automatically, continuously
                    • “Disadvantages: Initial setup time required”


Tuesday, May 15, 2012
VVV
                    • Per project configuration files for coding
                        conventions and linting rules
                    • Easy set-up: Automatically install required
                        software
                    • Integration with version control
                    • Support multiple languages (Python,
                        Javascript, CSS, restructured text... more to
                        come)

Tuesday, May 15, 2012
Benefits

                    • No bad code slips thru the commits
                    • Enforce coding conventions across project
                        members easily (esp. in open-ended OSS
                        projects)
                    • Permanent increase in software code
                        quality



Tuesday, May 15, 2012
Automatic enforcement
                        [~/code/vvv/demo]% git status
                        # On branch master
                        # Changes to be committed:
                        #   (use "git reset HEAD <file>..." to unstage)
                        #
                        #! new file:    demo.py
                        #! new file:    moomodule.py
                        #

                        [~/code/vvv/demo]% git commit -m "New cool stuff I typed in eyes
                        folder in 3 seconds"
                        /Users/moo/code/vvv/demo/demo.py
                        /Users/moo/code/vvv/demo/demo.py validation output:
                        ************* Module demo
                        E1101: 8,0: Instance of 'str' has no 'cutHumanInHalf' member

                        To fix validation errors:
                        -----------------------------
                        Python source code did not pass Pylint validator. Please fix
                        issues or disable warnings in .py file itself or validation-
                        options.yaml file.

                        Let's fix these issues, ok? ^_^
                        /Users/moo/code/vvv/demo/moomodule.py
                        VVV validatoin and linting failed




Tuesday, May 15, 2012
Mark-up errors
                        .foo {
                            backgrnd: yellow;
                        }




                        Running vvv against .
                        /Users/moo/code/vvv/demo/demo.py validation output:
                        {vextwarning=false, output=text, lang=en, warning=2,
                        medium=all, profile=css3}
                        W3C CSS Validator results for file:/Users/moo/code/vvv/
                        demo/foobar.css
                        Sorry! We found the following errors (1)
                        URI : file:/Users/moo/code/vvv/demo/foobar.css
                        Line : 2 .foo
                               Property backgrnd doesn&#39;t exist :
                               yellow



Tuesday, May 15, 2012
Coding conventions
                        C0103: 2,4:MagicalObject.doSomething: Invalid name
                        "doSomething" (should match [a-z_][a-z0-9_]{2,30}$)




                                   (PEP-8 for Pythoneers)




Tuesday, May 15, 2012
Generic text validation
                    • Line length
                    • Catch bad tabs and indentation
                    • Catch bad character sets (ISO-8859-1,
                        anyone?)
                    • Catch spooky stuff like ALT+spacebar No
                        Break Space character


Tuesday, May 15, 2012
Usage



Tuesday, May 15, 2012
Install VVV on your
                              computer
                        # Python 3 + virtualenv

                        cd ~
                        virtualenv-3.2 vvv-venv
                        . ~/vvv-venv/bin/activate
                        pip install vvv



Tuesday, May 15, 2012
Add VVV configuration
                      in project root

                    • validation-options.yaml to tell which
                        validators to run with which options
                    • validation-files.yaml for file
                        whitelisting / blacklisting




Tuesday, May 15, 2012
validation-options.yaml
                        # Enforce max line length
                        linelength:
                          length: 250

                        # Python additional configuration

                        pylint:

                          host-python-env: true

                          python3k: true

                          configuration: |

                            [MESSAGES CONTROL]
                            # Disable:
                            # - Missing docstring
                            # :C0112: *Empty docstring*
                            # :R0903: *Too few public methods (%s/%s)*
                            # :R0904: *Too many public methods (%s/%s)*
                            disable = C0111, C0112, R0903, R0904


Tuesday, May 15, 2012
validation-files.yaml
                        # Don't match hidden dotted files/folders
                        # Don't match generated folders
                        # Don't match test data (which is bad
                        intentionally)
                        all: |
                          *
                          !RE:.*/..*|^..*
                          !**/build/**
                          !dist/**
                          !venv
                          !**/__pycache__
                          !*.egg-info
                          !tests/validators
                          !tests/test-installation-environment



Tuesday, May 15, 2012
Run VVV
                        source ~/vvv-venv/bin/activate
                        vvv .



                                        ...or...


                        ~/vvv-venv/bin/vvv .




Tuesday, May 15, 2012
No painful manual
                            installations
                    • VVV will automatically download and install
                        a pile of software in ~/.vvv when run for the
                        first time
                    • VVV gives instructions how to install
                        dependencies which cannot be
                        automatically installed: java, node
                    • Installed on-demand: jshint, CSS validator,
                        pylint, etc.

Tuesday, May 15, 2012
Fighting the laziness



Tuesday, May 15, 2012
Pre-commit hook
                               integration
                        # Run pre-commit hook installation
                        vvv-install-git-pre-commit-hook .



                            Breaking the law (Judas Priest, 1980)
                        git commit --no-verify -m "Those validator hooks
                        prevent me committing crappy code, damn it!"



                                  https://www.youtube.com/watch?v=L397TWLwrUU

Tuesday, May 15, 2012
Continuous integration
                       (.travis.yml)
                        # Snake me baby!
                        language: python

                        python:
                          - "3.2"

                        # - We use logilab.astng trunk until this bug fix is
                        # released http://comments.gmane.org/gmane.comp.python.logilab/1193
                        install:
                          - "pip install hg+http://hg.logilab.org/logilab/astng/"
                          - pip install . --use-mirrors


                        # command to run validation against the code base
                        script: vvv .




Tuesday, May 15, 2012
VVV is here today

                    • Available on PyPi: http://pypi.python.org/
                        pypi/vvv
                    • Available on Github: https://github.com/
                        miohtama/vvv




Tuesday, May 15, 2012
Future
                    • Text-editor background linting when typing
                        (Sublime Edit 2)
                    • Expanded version control integration with
                        SVN, Bazaar and Mercurial
                    • Expanded language support: Java, PHP,
                        CoffeeScript
                    • Expanded user base: you report the bugs
Tuesday, May 15, 2012
Q&A

                    • Mikko Ohtamaa
                    • http://twitter.com/moo9000
                    • http://linkedin.com/in/ohtis
                    • http://opensourcehacker.com

Tuesday, May 15, 2012

More Related Content

PDF
Go testunderthehood
PDF
Comment j'ai mis ma suite de tests au régime en 5 minutes par jour
PPT
Greenbox Service Overview
KEY
Solving problems one Plone package at a time
PPT
Sottogruppo 2 Interlingua
PPT
Curso de didáctica de la lengua española
PPT
Progetti Quality Label 1D-3D
PPT
Parejas
Go testunderthehood
Comment j'ai mis ma suite de tests au régime en 5 minutes par jour
Greenbox Service Overview
Solving problems one Plone package at a time
Sottogruppo 2 Interlingua
Curso de didáctica de la lengua española
Progetti Quality Label 1D-3D
Parejas

Viewers also liked (11)

PDF
Plone IDE - the future of Plone development
PDF
Tomai materiali na
KEY
Saving Plone from Plone agony
PPT
Quando l'Europa fa la differenza
PDF
Writing the docs
PDF
Operations security - SyPy Dec 2014 (Sydney Python users)
KEY
Beautiful Maintainable ModularJavascript Codebase with RequireJS - HelsinkiJ...
PDF
Plone, battle-scarred community with battle tanks
PDF
Javascript - How to avoid the bad parts
PDF
Operations security (OPSEC)
PDF
Websauna - introduction to the best Python web framework
Plone IDE - the future of Plone development
Tomai materiali na
Saving Plone from Plone agony
Quando l'Europa fa la differenza
Writing the docs
Operations security - SyPy Dec 2014 (Sydney Python users)
Beautiful Maintainable ModularJavascript Codebase with RequireJS - HelsinkiJ...
Plone, battle-scarred community with battle tanks
Javascript - How to avoid the bad parts
Operations security (OPSEC)
Websauna - introduction to the best Python web framework
Ad

Similar to VVV validation and linting tool (20)

PDF
Code with style
PDF
Python introduction
PDF
Code with Style - PyOhio
PDF
Ruxmon.2013-08.-.CodeBro!
PDF
Python testing like a pro by Keith Yang
PDF
Don't do this
PDF
Effective code reviews
PDF
Effective code reviews
PPTX
How does one learn to program?
PPTX
PPTX
Spotify at PyCon Finland 2011
PDF
Static Code Analysis and Cppcheck
PDF
What schools should be teaching IT students
PDF
Poisoning Rubinius: The _why and How
PDF
Coding for Designers. A primer. By Fabian Fabian
PDF
Software maintenance PyConPL 2016
PDF
Python - code quality and production monitoring
PDF
PyCon 2011: IronPython Command Line
PPT
Standard exceptions
PDF
Parsing and Type checking all 2^10000 configurations of the Linux kernel
Code with style
Python introduction
Code with Style - PyOhio
Ruxmon.2013-08.-.CodeBro!
Python testing like a pro by Keith Yang
Don't do this
Effective code reviews
Effective code reviews
How does one learn to program?
Spotify at PyCon Finland 2011
Static Code Analysis and Cppcheck
What schools should be teaching IT students
Poisoning Rubinius: The _why and How
Coding for Designers. A primer. By Fabian Fabian
Software maintenance PyConPL 2016
Python - code quality and production monitoring
PyCon 2011: IronPython Command Line
Standard exceptions
Parsing and Type checking all 2^10000 configurations of the Linux kernel
Ad

More from Mikko Ohtamaa (9)

PDF
Operations Security - SF Bitcoin Hackday March 2015
PDF
World Plone Day 2013
PDF
Test lol
PDF
The Easy Way - Plone Conference 2011
KEY
Mobile Landscape 2011
PDF
Mobiilimarkkinoinnin mahdollisuudet nyt
PDF
The World Outside Plone
PPTX
mFabrik Case Studies
PPTX
Building HTML based mobile phone applications
Operations Security - SF Bitcoin Hackday March 2015
World Plone Day 2013
Test lol
The Easy Way - Plone Conference 2011
Mobile Landscape 2011
Mobiilimarkkinoinnin mahdollisuudet nyt
The World Outside Plone
mFabrik Case Studies
Building HTML based mobile phone applications

Recently uploaded (20)

PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
KodekX | Application Modernization Development
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
sap open course for s4hana steps from ECC to s4
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Electronic commerce courselecture one. Pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPT
Teaching material agriculture food technology
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Machine learning based COVID-19 study performance prediction
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
KodekX | Application Modernization Development
Review of recent advances in non-invasive hemoglobin estimation
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Network Security Unit 5.pdf for BCA BBA.
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
sap open course for s4hana steps from ECC to s4
20250228 LYD VKU AI Blended-Learning.pptx
Digital-Transformation-Roadmap-for-Companies.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Electronic commerce courselecture one. Pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Agricultural_Statistics_at_a_Glance_2022_0.pdf
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
Teaching material agriculture food technology
NewMind AI Weekly Chronicles - August'25 Week I
Machine learning based COVID-19 study performance prediction
Mobile App Security Testing_ A Comprehensive Guide.pdf

VVV validation and linting tool

  • 1. VVV Validation and linting tool Mikko Ohtamaa http://twitter.com/moo9000 Python Helsinki meet-up Tuesday, May 15, 2012
  • 2. • Validation: HTML validator, CSS validator • Linting: flag suspicious code: catch typing errors, formatting errors https://en.wikipedia.org/wiki/Lint_programming_tool Tuesday, May 15, 2012
  • 3. foobar = get_magic() try: foobar.doSomething() except: fobar.doSomethingElse() Tuesday, May 15, 2012
  • 4. [~/code/vvv/demo]% vvv . Running vvv against . /Users/moo/code/vvv/demo/demo.py validation output: ************* Module demo E0602: 15,4: Undefined variable 'fobar' Tuesday, May 15, 2012
  • 5. Why you need VVV • Humans make human errors and are lazy • Good practices must be enforced automatically, continuously • “Disadvantages: Initial setup time required” Tuesday, May 15, 2012
  • 6. VVV • Per project configuration files for coding conventions and linting rules • Easy set-up: Automatically install required software • Integration with version control • Support multiple languages (Python, Javascript, CSS, restructured text... more to come) Tuesday, May 15, 2012
  • 7. Benefits • No bad code slips thru the commits • Enforce coding conventions across project members easily (esp. in open-ended OSS projects) • Permanent increase in software code quality Tuesday, May 15, 2012
  • 8. Automatic enforcement [~/code/vvv/demo]% git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # #! new file: demo.py #! new file: moomodule.py # [~/code/vvv/demo]% git commit -m "New cool stuff I typed in eyes folder in 3 seconds" /Users/moo/code/vvv/demo/demo.py /Users/moo/code/vvv/demo/demo.py validation output: ************* Module demo E1101: 8,0: Instance of 'str' has no 'cutHumanInHalf' member To fix validation errors: ----------------------------- Python source code did not pass Pylint validator. Please fix issues or disable warnings in .py file itself or validation- options.yaml file. Let's fix these issues, ok? ^_^ /Users/moo/code/vvv/demo/moomodule.py VVV validatoin and linting failed Tuesday, May 15, 2012
  • 9. Mark-up errors .foo { backgrnd: yellow; } Running vvv against . /Users/moo/code/vvv/demo/demo.py validation output: {vextwarning=false, output=text, lang=en, warning=2, medium=all, profile=css3} W3C CSS Validator results for file:/Users/moo/code/vvv/ demo/foobar.css Sorry! We found the following errors (1) URI : file:/Users/moo/code/vvv/demo/foobar.css Line : 2 .foo Property backgrnd doesn&#39;t exist : yellow Tuesday, May 15, 2012
  • 10. Coding conventions C0103: 2,4:MagicalObject.doSomething: Invalid name "doSomething" (should match [a-z_][a-z0-9_]{2,30}$) (PEP-8 for Pythoneers) Tuesday, May 15, 2012
  • 11. Generic text validation • Line length • Catch bad tabs and indentation • Catch bad character sets (ISO-8859-1, anyone?) • Catch spooky stuff like ALT+spacebar No Break Space character Tuesday, May 15, 2012
  • 13. Install VVV on your computer # Python 3 + virtualenv cd ~ virtualenv-3.2 vvv-venv . ~/vvv-venv/bin/activate pip install vvv Tuesday, May 15, 2012
  • 14. Add VVV configuration in project root • validation-options.yaml to tell which validators to run with which options • validation-files.yaml for file whitelisting / blacklisting Tuesday, May 15, 2012
  • 15. validation-options.yaml # Enforce max line length linelength: length: 250 # Python additional configuration pylint: host-python-env: true python3k: true configuration: | [MESSAGES CONTROL] # Disable: # - Missing docstring # :C0112: *Empty docstring* # :R0903: *Too few public methods (%s/%s)* # :R0904: *Too many public methods (%s/%s)* disable = C0111, C0112, R0903, R0904 Tuesday, May 15, 2012
  • 16. validation-files.yaml # Don't match hidden dotted files/folders # Don't match generated folders # Don't match test data (which is bad intentionally) all: | * !RE:.*/..*|^..* !**/build/** !dist/** !venv !**/__pycache__ !*.egg-info !tests/validators !tests/test-installation-environment Tuesday, May 15, 2012
  • 17. Run VVV source ~/vvv-venv/bin/activate vvv . ...or... ~/vvv-venv/bin/vvv . Tuesday, May 15, 2012
  • 18. No painful manual installations • VVV will automatically download and install a pile of software in ~/.vvv when run for the first time • VVV gives instructions how to install dependencies which cannot be automatically installed: java, node • Installed on-demand: jshint, CSS validator, pylint, etc. Tuesday, May 15, 2012
  • 20. Pre-commit hook integration # Run pre-commit hook installation vvv-install-git-pre-commit-hook . Breaking the law (Judas Priest, 1980) git commit --no-verify -m "Those validator hooks prevent me committing crappy code, damn it!" https://www.youtube.com/watch?v=L397TWLwrUU Tuesday, May 15, 2012
  • 21. Continuous integration (.travis.yml) # Snake me baby! language: python python: - "3.2" # - We use logilab.astng trunk until this bug fix is # released http://comments.gmane.org/gmane.comp.python.logilab/1193 install: - "pip install hg+http://hg.logilab.org/logilab/astng/" - pip install . --use-mirrors # command to run validation against the code base script: vvv . Tuesday, May 15, 2012
  • 22. VVV is here today • Available on PyPi: http://pypi.python.org/ pypi/vvv • Available on Github: https://github.com/ miohtama/vvv Tuesday, May 15, 2012
  • 23. Future • Text-editor background linting when typing (Sublime Edit 2) • Expanded version control integration with SVN, Bazaar and Mercurial • Expanded language support: Java, PHP, CoffeeScript • Expanded user base: you report the bugs Tuesday, May 15, 2012
  • 24. Q&A • Mikko Ohtamaa • http://twitter.com/moo9000 • http://linkedin.com/in/ohtis • http://opensourcehacker.com Tuesday, May 15, 2012