Commit c9be3663 authored by Bharath Ramsundar's avatar Bharath Ramsundar Committed by GitHub
Browse files

Merge pull request #406 from lilleswing/394-Format-Tests-cr

394: Auto Format Using .yapf
parents 5b56a483 ba5ee134
Loading
Loading
Loading
Loading

.style.yapf

0 → 100644
+3 −0
Original line number Diff line number Diff line
[style]
based_on_style = google
indent_width = 2
+2 −0
Original line number Diff line number Diff line
@@ -24,9 +24,11 @@ install:
- conda install -c conda-forge protobuf=3.1.0
- conda install -c omnia mdtraj
- pip install tensorflow==0.12.1
- pip install yapf==0.16.0
- python setup.py install
script:
- nosetests -v deepchem --nologcapture
- bash devtools/travis-ci/test_format_code.sh
after_success:
- echo $TRAVIS_SECURE_ENV_VARS
- source devtools/travis-ci/after_sucess.sh
+5 −4
Original line number Diff line number Diff line
@@ -383,11 +383,12 @@ We actively encourage community contributions to DeepChem. The first place to st
Once you've got a sense of how the package works, we encourage the use of Github issues to discuss more complex changes,  raise requests for new features or propose changes to the global architecture of DeepChem. Once consensus is reached on the issue, please submit a PR with proposed modifications. All contributed code to DeepChem will be reviewed by a member of the DeepChem team, so please make sure your code style and documentation style match our guidelines!

### Code Style Guidelines
DeepChem broadly follows the [Google Python Style Guide](https://google.github.io/styleguide/pyguide.html). In terms of practical changes, the biggest effect is that all code uses 2-space indents instead of 4-space indents. We encourage new contributors to make use of [pylint](https://www.pylint.org/) with the following command
```
pylint --disable=invalid-name --indent-string "  " --extension-pkg-whitelist=numpy [file.py]
DeepChem uses [yapf](https://github.com/google/yapf) to autoformat code.  We created a git pre-commit hook to make this process easier.

``` bash
cp devtools/travis-ci/pre-commit .git/hooks
pip install yapf==0.16.0
```
Aim for a score of at least 8/10 on contributed files.

### Documentation Style Guidelines
DeepChem uses [NumPy style documentation](https://github.com/numpy/numpy/blob/master/doc/HOWTO_DOCUMENT.rst.txt). Please follow these conventions when documenting code, since we use [Sphinx+Napoleon](http://www.sphinx-doc.org/en/stable/ext/napoleon.html) to automatically generate docs on [deepchem.io](deepchem.io).
+10 −0
Original line number Diff line number Diff line
#!/bin/sh
CHANGED_FILES=`git diff --cached --name-only | grep .py`
if [ -z $CHANGED_FILES ]
then
    echo "No Python Files Changed"
else
    echo $CHANGED_FILES
    yapf -i $CHANGED_FILES
    git diff --name-only --cached | xargs -l git add
fi
+30 −0
Original line number Diff line number Diff line
#!/bin/bash -e

CHANGED_FILES=`git diff --name-only $TRAVIS_COMMIT_RANGE | grep .py$`

exit_success () {
    echo "Passed Formatting Test"
    exit 0
}

if [ -z $CHANGED_FILES ]
then
    echo "No Python Files Changed"
    exit_success
fi

yapf -d $CHANGED_FILES > diff.txt

if [ -s diff.txt ]
then
    cat diff.txt
    echo ""
    echo "Failing Formatting Test"
    echo "Please run yapf over the files changed"
    echo "pip install yapf"
    echo "yapf -i $CHANGED_FILES"
    exit 1
else
    exit_success
fi
exit 1