Skip to content

Commit 2083f0d

Browse files
gfyoungjreback
authored andcommitted
DOC: Add documentation about cpplint (#14890)
1 parent 992dfbc commit 2083f0d

File tree

1 file changed

+78
-15
lines changed

1 file changed

+78
-15
lines changed

doc/source/contributing.rst

+78-15
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,12 @@ want to clone your fork to your machine::
113113
This creates the directory `pandas-yourname` and connects your repository to
114114
the upstream (main project) *pandas* repository.
115115

116-
The testing suite will run automatically on Travis-CI once your pull request is
117-
submitted. However, if you wish to run the test suite on a branch prior to
118-
submitting the pull request, then Travis-CI needs to be hooked up to your
119-
GitHub repository. Instructions for doing so are `here
120-
<http://about.travis-ci.org/docs/user/getting-started/>`__.
116+
The testing suite will run automatically on Travis-CI and Appveyor once your
117+
pull request is submitted. However, if you wish to run the test suite on a
118+
branch prior to submitting the pull request, then Travis-CI and/or AppVeyor
119+
need to be hooked up to your GitHub repository. Instructions for doing so
120+
are `here <http://about.travis-ci.org/docs/user/getting-started/>`__ for
121+
Travis-CI and `here <https://www.appveyor.com/docs/>`__ for AppVeyor.
121122

122123
Creating a branch
123124
-----------------
@@ -142,7 +143,7 @@ To update this branch, you need to retrieve the changes from the master branch::
142143
git fetch upstream
143144
git rebase upstream/master
144145

145-
This will replay your commits on top of the lastest pandas git master. If this
146+
This will replay your commits on top of the latest pandas git master. If this
146147
leads to merge conflicts, you must resolve these before submitting your pull
147148
request. If you have uncommitted changes, you will need to ``stash`` them prior
148149
to updating. This will effectively store your changes and they can be reapplied
@@ -396,7 +397,7 @@ evocations, sphinx will try to only build the pages that have been modified.
396397
If you want to do a full clean build, do::
397398

398399
python make.py clean
399-
python make.py build
400+
python make.py html
400401

401402
Starting with *pandas* 0.13.1 you can tell ``make.py`` to compile only a single section
402403
of the docs, greatly reducing the turn-around time for checking your changes.
@@ -442,18 +443,80 @@ Contributing to the code base
442443
Code standards
443444
--------------
444445

446+
Writing good code is not just about what you write. It is also about *how* you
447+
write it. During testing on Travis-CI, several tools will be run to check your
448+
code for stylistic errors. Generating any warnings will cause the test to fail.
449+
Thus, good style is a requirement for submitting code to *pandas*.
450+
451+
In addition, because a lot of people use our library, it is important that we
452+
do not make sudden changes to the code that could have the potential to break
453+
a lot of user code as a result, that is, we need it to be as *backwards compatible*
454+
as possible to avoid mass breakages.
455+
456+
Additional standards are outlined on the `code style wiki
457+
page <https://github.com/pandas-dev/pandas/wiki/Code-Style-and-Conventions>`_.
458+
459+
C (cpplint)
460+
~~~~~~~~~~~
461+
462+
*pandas* uses the `Google <https://google.github.io/styleguide/cppguide.html>`_
463+
standard. Google provides an open source style checker called ``cpplint``, but we
464+
use a fork of it that can be found `here <https://github.com/cpplint/cpplint>`_.
465+
Here are *some* of the more common ``cpplint`` issues:
466+
467+
- we restrict line-length to 80 characters to promote readability
468+
- every header file must include a header guard to avoid name collisions if re-included
469+
470+
Travis-CI will run the `cpplint <https://pypi.python.org/pypi/cpplint>`_ tool
471+
and report any stylistic errors in your code. Therefore, it is helpful before
472+
submitting code to run the check yourself::
473+
474+
cpplint --extensions=c,h --headers=h --filter=-readability/casting,-runtime/int,-build/include_subdir modified-c-file
475+
476+
You can also run this command on an entire directory if necessary::
477+
478+
cpplint --extensions=c,h --headers=h --filter=-readability/casting,-runtime/int,-build/include_subdir --recursive modified-c-directory
479+
480+
To make your commits compliant with this standard, you can install the
481+
`ClangFormat <http://clang.llvm.org/docs/ClangFormat.html>`_ tool, which can be
482+
downloaded `here <http://llvm.org/builds/>`_. To configure, in your home directory,
483+
run the following command::
484+
485+
clang-format style=google -dump-config > .clang-format
486+
487+
Then modify the file to ensure that any indentation width parameters are at least four.
488+
Once configured, you can run the tool as follows::
489+
490+
clang-format modified-c-file
491+
492+
This will output what your file will look like if the changes are made, and to apply
493+
them, just run the following command::
494+
495+
clang-format -i modified-c-file
496+
497+
To run the tool on an entire directory, you can run the following analogous commands::
498+
499+
clang-format modified-c-directory/*.c modified-c-directory/*.h
500+
clang-format -i modified-c-directory/*.c modified-c-directory/*.h
501+
502+
Do note that this tool is best-effort, meaning that it will try to correct as
503+
many errors as possible, but it may not correct *all* of them. Thus, it is
504+
recommended that you run ``cpplint`` to double check and make any other style
505+
fixes manually.
506+
507+
Python (PEP8)
508+
~~~~~~~~~~~~~
509+
445510
*pandas* uses the `PEP8 <http://www.python.org/dev/peps/pep-0008/>`_ standard.
446511
There are several tools to ensure you abide by this standard. Here are *some* of
447512
the more common ``PEP8`` issues:
448513

449-
- we restrict line-length to 80 characters to promote readability
514+
- we restrict line-length to 79 characters to promote readability
450515
- passing arguments should have spaces after commas, e.g. ``foo(arg1, arg2, kw1='bar')``
451516

452-
The Travis-CI will run `flake8 <http://pypi.python.org/pypi/flake8>`_ tool and report
453-
any stylistic errors in your code. Generating any warnings will cause the build to fail;
454-
thus these are part of the requirements for submitting code to *pandas*.
455-
456-
It is helpful before submitting code to run this yourself on the diff::
517+
Travis-CI will run the `flake8 <http://pypi.python.org/pypi/flake8>`_ tool
518+
and report any stylistic errors in your code. Therefore, it is helpful before
519+
submitting code to run the check yourself on the diff::
457520

458521
git diff master | flake8 --diff
459522

@@ -466,8 +529,8 @@ and make these changes with::
466529

467530
pep8radius master --diff --in-place
468531

469-
Additional standards are outlined on the `code style wiki
470-
page <https://github.com/pandas-dev/pandas/wiki/Code-Style-and-Conventions>`_.
532+
Backwards Compatibility
533+
~~~~~~~~~~~~~~~~~~~~~~~
471534

472535
Please try to maintain backward compatibility. *pandas* has lots of users with lots of
473536
existing code, so don't break it if at all possible. If you think breakage is required,

0 commit comments

Comments
 (0)