We will perform static analysis of a part of the NumPy codebase. In order to do this, we will check out the code using Git. We will then run
static analysis on part of the code using pyflakes
.
To check out the NumPy code, we will need Git. Installing Git is outside the scope of this book. The Git command to retrieve the code is as follows:
git clone git://github.com/numpy/numpy.git numpy
Alternatively, we can download a zip archive from https://github.com/numpy/numpy .
The previous step should have created a numpy
directory with all the NumPy code. Go to this directory, and within it run the following command:
$ pyflakes *.py pavement.py:71: redefinition of unused 'md5' from line 69 pavement.py:88: redefinition of unused 'GIT_REVISION' from line 86 pavement.py:314: 'virtualenv' imported but unused pavement.py:315: local variable 'e' is assigned to but never used pavement.py:380: local variable 'sdir' is assigned to but never used pavement.py:381: local variable 'bdir' is assigned to but never used pavement.py:536: local variable 'st' is assigned to but never used setup.py:21: 're' imported but unused setup.py:27: redefinition of unused 'builtins' from line 25 setup.py:124: redefinition of unused 'GIT_REVISION' from line 118 setupegg.py:17: 'setup' imported but unused setupscons.py:61: 'numpy' imported but unused setupscons.py:64: 'numscons' imported but unused setupsconsegg.py:6: 'setup' imported but unused
This will run analysis on the code style, and check for PEP-8 violations in all the Python scripts within the current directory. You can also analyze a single file if you prefer.