Skip to content
This repository has been archived by the owner on Aug 13, 2020. It is now read-only.

Code quality

Pablo Rodríguez Robles edited this page Nov 8, 2016 · 7 revisions

Code Issues

Installing the necessary tools:

$ conda install pep8 pylint

  • pep8 tool which checks automatically whether the code follows the PEP 8
  • Pylint more elaborated verifications as non-pythonic structures or feasible refactorizations.

Ideally we would like that the code fulfils the PEP 8 as faithful as possible.

Checking that the code follows pep8:

$ cd PyFME
$ pep8 src/
src/pyfme/__init__.py:2:1: W391 blank line at end of file
src/pyfme/environment/isa.py:34:80: E501 line too long (82 > 79 characters)

In order to use Pylint (NOTE: It is not working on Python 3.5):

$ pylint pyfme
No config file found, using default configuration
************* Module pyfme.environment.isa
C: 28, 0: Invalid constant name "R_a" (invalid-name)
C: 29, 0: Invalid constant name "g0" (invalid-name)
C: 32, 0: Invalid constant name "h0" (invalid-name)
C: 33, 0: Invalid constant name "T0_layers" (invalid-name)
C: 34, 0: Invalid constant name "p0_layers" (invalid-name)
C: 35, 0: Invalid constant name "alpha_layers" (invalid-name)
C: 38, 0: Invalid argument name "h" (invalid-name)
C: 76, 8: Invalid variable name "T0" (invalid-name)
C: 77, 8: Invalid variable name "p0" (invalid-name)
C: 80, 8: Invalid variable name "T" (invalid-name)
C: 81, 8: Invalid variable name "p" (invalid-name)
C: 84, 8: Invalid variable name "T0" (invalid-name)
C: 85, 8: Invalid variable name "p0" (invalid-name)
C: 89, 8: Invalid variable name "T" (invalid-name)
C: 90, 8: Invalid variable name "p" (invalid-name)
C: 93, 8: Invalid variable name "T0" (invalid-name)
C: 94, 8: Invalid variable name "p0" (invalid-name)
C: 98, 8: Invalid variable name "T" (invalid-name)
C: 99, 8: Invalid variable name "p" (invalid-name)
C:102, 8: Invalid variable name "T0" (invalid-name)
C:103, 8: Invalid variable name "p0" (invalid-name)
C:107, 8: Invalid variable name "T" (invalid-name)
C:108, 8: Invalid variable name "p" (invalid-name)
C:111, 8: Invalid variable name "T0" (invalid-name)
C:112, 8: Invalid variable name "p0" (invalid-name)
C:116, 8: Invalid variable name "T" (invalid-name)
C:117, 8: Invalid variable name "p" (invalid-name)
C:120, 8: Invalid variable name "T0" (invalid-name)
C:121, 8: Invalid variable name "p0" (invalid-name)
C:125, 8: Invalid variable name "T" (invalid-name)
C:126, 8: Invalid variable name "p" (invalid-name)
C:129, 8: Invalid variable name "T0" (invalid-name)
C:130, 8: Invalid variable name "p0" (invalid-name)
C:134, 8: Invalid variable name "T" (invalid-name)
C:135, 8: Invalid variable name "p" (invalid-name)
R: 38, 0: Too many statements (54/50) (too-many-statements)
************* Module pyfme.utils.coordinates
C: 20, 0: Unnecessary parens after u'not' keyword (superfluous-parens)
C: 22, 0: Unnecessary parens after u'not' keyword (superfluous-parens)
C: 24, 0: Unnecessary parens after u'not' keyword (superfluous-parens)
C: 78, 0: Wrong hanging indentation.
                    [cos(theta) * cos(psi),
        |           ^ (bad-continuation)
C: 81, 0: Wrong hanging indentation.
                    [cos(theta) * sin(psi),
        |           ^ (bad-continuation)
C: 84, 0: Wrong hanging indentation.
                    [- sin(theta),
        |           ^ (bad-continuation)
C: 87, 0: Wrong hanging indentation.
                    ])
    |   |           ^ (bad-continuation)
C:144, 0: Wrong hanging indentation.
                    [cos(theta) * cos(psi),
        |           ^ (bad-continuation)
C:147, 0: Wrong hanging indentation.
                    [sin(phi) * sin(theta) * cos(psi) - cos(phi) * sin(psi),
        |           ^ (bad-continuation)
C:150, 0: Wrong hanging indentation.
                    [cos(phi) * sin(theta) * cos(psi) + sin(phi) * sin(psi),
        |           ^ (bad-continuation)
C:153, 0: Wrong hanging indentation.
                    ])
    |   |           ^ (bad-continuation)
C:170, 0: Unnecessary parens after u'not' keyword (superfluous-parens)
C:172, 0: Unnecessary parens after u'not' keyword (superfluous-parens)
C:174, 0: Unnecessary parens after u'not' keyword (superfluous-parens)
C:219, 0: Wrong hanging indentation.
                    [cos(gamma) * cos(chi),
        |           ^ (bad-continuation)
C:222, 0: Wrong hanging indentation.
                    [cos(gamma) * sin(chi),
        |           ^ (bad-continuation)
C:225, 0: Wrong hanging indentation.
                    [-sin(gamma),
        |           ^ (bad-continuation)
C:228, 0: Wrong hanging indentation.
                    ])
    |   |           ^ (bad-continuation)
C:276, 0: Wrong hanging indentation.
                    [cos(gamma) * cos(chi),
        |           ^ (bad-continuation)
C:279, 0: Wrong hanging indentation.
                    [sin(mu) * sin(gamma) * sin(chi) - cos(mu) * sin(chi),
        |           ^ (bad-continuation)
C:282, 0: Wrong hanging indentation.
                    [cos(mu) * sin(gamma) * cos(chi) + sin(mu) * sin(chi),
        |           ^ (bad-continuation)
C:285, 0: Wrong hanging indentation.
                    ])
    |   |           ^ (bad-continuation)
C:301, 0: Unnecessary parens after u'not' keyword (superfluous-parens)
C:303, 0: Unnecessary parens after u'not' keyword (superfluous-parens)
C:348, 0: Wrong hanging indentation.
                    [cos(alpha) * cos(beta),
        |           ^ (bad-continuation)
C:351, 0: Wrong hanging indentation.
                    [- cos(alpha) * sin(beta),
        |           ^ (bad-continuation)
C:354, 0: Wrong hanging indentation.
                    [-sin(alpha),
        |           ^ (bad-continuation)
C:357, 0: Wrong hanging indentation.
                    ])
    |   |           ^ (bad-continuation)
C:405, 0: Wrong hanging indentation.
                    [cos(alpha) * cos(beta),
        |           ^ (bad-continuation)
C:408, 0: Wrong hanging indentation.
                    [sin(beta),
        |           ^ (bad-continuation)
C:411, 0: Wrong hanging indentation.
                    [sin(alpha) * cos(beta),
        |           ^ (bad-continuation)
C:414, 0: Wrong hanging indentation.
                    ])
    |   |           ^ (bad-continuation)
F:  6, 0: Unable to import 'numpy' (import-error)
F:  7, 0: Unable to import 'numpy' (import-error)
W: 10,42: Unused argument 'psi' (unused-argument)
C: 77, 4: Invalid variable name "Lhb" (invalid-name)
C:143, 4: Invalid variable name "Lbh" (invalid-name)
C:160, 0: Invalid argument name "mu" (invalid-name)
C:178, 0: Invalid argument name "mu" (invalid-name)
C:218, 4: Invalid variable name "Lhw" (invalid-name)
C:235, 0: Invalid argument name "mu" (invalid-name)
C:275, 4: Invalid variable name "Lwh" (invalid-name)
C:347, 4: Invalid variable name "Lwb" (invalid-name)
C:404, 4: Invalid variable name "Lbw" (invalid-name)


Report
======
121 statements analysed.

Statistics by type
------------------

+---------+-------+-----------+-----------+------------+---------+
|type     |number |old number |difference |%documented |%badname |
+=========+=======+===========+===========+============+=========+
|module   |5      |NC         |NC         |100.00      |0.00     |
+---------+-------+-----------+-----------+------------+---------+
|class    |0      |NC         |NC         |0           |0        |
+---------+-------+-----------+-----------+------------+---------+
|method   |0      |NC         |NC         |0           |0        |
+---------+-------+-----------+-----------+------------+---------+
|function |10     |NC         |NC         |100.00      |0.00     |
+---------+-------+-----------+-----------+------------+---------+



Raw metrics
-----------

+----------+-------+------+---------+-----------+
|type      |number |%     |previous |difference |
+==========+=======+======+=========+===========+
|code      |181    |34.22 |NC       |NC         |
+----------+-------+------+---------+-----------+
|docstring |297    |56.14 |NC       |NC         |
+----------+-------+------+---------+-----------+
|comment   |10     |1.89  |NC       |NC         |
+----------+-------+------+---------+-----------+
|empty     |41     |7.75  |NC       |NC         |
+----------+-------+------+---------+-----------+



Duplication
-----------

+-------------------------+------+---------+-----------+
|                         |now   |previous |difference |
+=========================+======+=========+===========+
|nb duplicated lines      |0     |NC       |NC         |
+-------------------------+------+---------+-----------+
|percent duplicated lines |0.000 |NC       |NC         |
+-------------------------+------+---------+-----------+



Messages by category
--------------------

+-----------+-------+---------+-----------+
|type       |number |previous |difference |
+===========+=======+=========+===========+
|convention |76     |NC       |NC         |
+-----------+-------+---------+-----------+
|refactor   |1      |NC       |NC         |
+-----------+-------+---------+-----------+
|warning    |1      |NC       |NC         |
+-----------+-------+---------+-----------+
|error      |0      |NC       |NC         |
+-----------+-------+---------+-----------+



% errors / warnings by module
-----------------------------

+------------------------+------+--------+---------+-----------+
|module                  |error |warning |refactor |convention |
+========================+======+========+=========+===========+
|pyfme.utils.coordinates |0.00  |100.00  |0.00     |53.95      |
+------------------------+------+--------+---------+-----------+
|pyfme.environment.isa   |0.00  |0.00    |100.00   |46.05      |
+------------------------+------+--------+---------+-----------+



Messages
--------

+--------------------+------------+
|message id          |occurrences |
+====================+============+
|invalid-name        |44          |
+--------------------+------------+
|bad-continuation    |24          |
+--------------------+------------+
|superfluous-parens  |8           |
+--------------------+------------+
|import-error        |2           |
+--------------------+------------+
|unused-argument     |1           |
+--------------------+------------+
|too-many-statements |1           |
+--------------------+------------+



Global evaluation
-----------------
Your code has been rated at 3.55/10

Spyder Settings

  1. Go to Tools > Preferences.
  2. Select Editor.
  3. In the tab Code Introspection/Analysis choose:
    • Code analysis (pyflakes).
    • Style analysis (pep8).
    • Tasks (TODO, FIXME...)
  4. In the tab Advanced settings:
    • Automatically remove trailing spaces when saving files.

It may be necessary to install pyflakes and pep8: $ conda install pep8 pyflakes

There are several settings which might help you to feel comfortable using Spyder. Play around and customise it!