Skip to content
This repository has been archived by the owner on Feb 16, 2023. It is now read-only.

Commit

Permalink
Pre-commit, tests, contributors guideline (#220)
Browse files Browse the repository at this point in the history
* Pre-commit, tests, contributors guideline

* PySyft -> Grid

* Add Makefile
  • Loading branch information
hereismari committed May 22, 2019
1 parent 2ec4058 commit 5b2e4f9
Show file tree
Hide file tree
Showing 7 changed files with 207 additions and 5 deletions.
8 changes: 6 additions & 2 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
[flake8]
select = E901,E999,F821,F822,F823
max-line-length = 100
exclude = .git,.eggs,__pycache__,build,dist
max-complexity=11
exclude = .git,.eggs,__pycache__,build,dist,venv
max-complexity = 11
show-source = true
statistics = true
count = true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.cache
.coverage
*__pycache__*
.eggs/
build/
Expand Down
21 changes: 21 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v1.3.0
hooks:
- id: trailing-whitespace
- id: check-docstring-first
- id: check-json
- id: check-added-large-files
- id: check-yaml
- id: debug-statements
- id: name-tests-test
- id: requirements-txt-fixer
- id: flake8
- repo: https://github.com/ambv/black
rev: 19.3b0
hooks:
- id: black
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.1.0
hooks:
- id: python-use-type-annotations
36 changes: 36 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
group: travis_latest
language: python
cache: pip
python:
- 3.6
matrix:
allow_failures:
- python: nightly
- python: pypy
- python: pypy3
install:
- sudo apt-get update
- hash -r
- pip3 install -r requirements.txt >build.log
- pip3 install flake8
- pip3 install flake8-docstrings
- pip3 install flake8-comprehensions
- pip3 install pep8-naming
- python setup.py install >> build.log
before_script:
# stop the build if there are Python syntax errors or undefined
# names
- flake8 --config=.flake8 .
- black --check --verbose .
# exit-zero treats all errors as warnings.
# diverting from the standard 79 character line length in
# accordance with this:
# https://www.python.org/dev/peps/pep-0008/#a-foolish-consistency-is-the-hobgoblin-of-little-minds
- flake8 . --count --exit-zero --statistics --select=E,F,W,C90
script:
- coverage run --omit=*/virtualenv/*,setup.py,.eggs/*,*__init__.py setup.py test
# - if grep -q "Traceback (most recent call last):" nb_to_md.txt; then false; else true; fi
notifications:
on_success: change
# `always` will be the setting below once code changes slow down
on_failure: change
105 changes: 102 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,104 @@
### Running tests
# Contributors Guidelines to Grid

## Getting Started

### Slack

A great first place to join the Community is the Slack channel <http://slack.openmined.org>.

### Issues

On <https://github.com/OpenMined/Grid/issues> you can find all open Issues. You can find a detailed explanation on how to work with issues below under [Issue Allocation](#Issue-Allocation).

## Setup

### Forking a Repository

To contribute to Grid you will need to fork the OpenMind/Grid repository.
Then you can work risk-free on your fork.

You will just need to fork once. After that you can call `git fetch upstream` and `git pull 'branch-name'` before you do your local changes to get the remote changes and be up-to-date

### Setting up Pre-Commit Hook

Grid uses the python package `pre-commit` to make sure the correct formatting (black & flake) is applied.

You can install it via `pip install pre-commit`

Then you just need to call `pre-commit install`

This can all also be done by running `make install_hooks`

### Syncing a Forked Repository

To sync your fork with the OpenMined/Grid repository please see this [Guide](https://help.github.com/articles/syncing-a-fork/) on how to sync your fork.

## Contributing

### Beginner Issues

If you are new to the project and want to get into the code, we recommend picking an issue with the label "good first issue". These issues should ony require general programming knowledge and little to none insights into the project.

### Issue Allocation

Each issue someone is currently working on should have an assignee. If you want to contribute to an issue someone else is already working on please make sure to get in contact with that person via slack or github and organize yourself.

If you want to work on an open issue, please post a comment telling that you will work on that issue, we will assign you as the assignee then.

**Caution**: We try our best to keep the assignee up-to-date but as we are all humans with our own schedule delays are possible, so make sure to check the comments once before you start working on an issue even when no one is assigned to it.

### Set up

#### Dependencies

You'll need to have the following dependencies installed:

Heroku Toolbelt: https://toolbelt.heroku.com/
Pip: https://www.makeuseof.com/tag/install-pip-for-python/
Git: https://gist.github.com/derhuerst/1b15ff4652a867391f03
PySyft: https://github.com/OpenMined/PySyft

You can install most of the dependencies by running `pip install -r requirements.txt`.

#### Building Grid

You can build grid by running: `python setup.py install`.

### Writing Test Cases

Always make sure to create the necessary tests and keep test coverage at 100%. You can always ask for help in slack or via github if you don't feel confidant about your tests.

```bash
redis-server & python app/app.py & pytest test/
```
coverage run --omit=*/venv/*,setup.py,.eggs/* setup.py test
```

### Documentation and Codestyle

To ensure code quality and make sure other people can understand your changes, you have to document your code. For documentation we are using the Google Python Style Rules which can be found [here](https://github.com/google/styleguide/blob/gh-pages/pyguide.md). A well wrote example can we viewed [here](https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html).

You documentation should not describe the obvious, but explain what's the intention behind the code and how you tried to realize your intention.

You should also document non self-explanatory code fragments e.g. complicated for-loops. Again please do not just describe what each line is doing but also explain the idea behind the code fragment and why you decided to use that exact solution.

#### Imports

For better merge compatibility each import is within a separate line. Multiple imports from one package are written in one line each.

### Keep it DRY (Don't repeat yourself)

As with any software project it's important to keep the amount of code to a minimum, so keep code duplication to a minimum!

### Creating a Pull Request

At any point in time you can create a pull request, so others can see your changes and give you feedback.
Please create all pull requests to the `dev` branch.
If your PR is still work in progress and not ready to be merged please add a `[WIP]` at the start of the title.
Example:`[WIP] Websocket worker for Grid`

### Check CI and Wait for Reviews

After each commit TravisCI will check your new code against the formatting guidelines (should not cause any problems when you setup your pre-commit hook) and execute the tests to check if the test coverage is high enough.

We will only merge PRs that pass the TravisCI checks.

If your check fails don't worry you will still be able to make changes and make your code pass the checks.
33 changes: 33 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
venv: venv/bin/activate

venv/bin/activate: requirements.txt
test -e venv/bin/activate || virtualenv venv
. venv/bin/activate; pip install -Ur requirements.txt; python setup.py install
touch venv/bin/activate

install_hooks: venv
venv/bin/pre-commit install

notebook: venv
(. venv/bin/activate; \
python setup.py install; \
python -m ipykernel install --user --name=grid; \
jupyter notebook;\
)

lab: venv
(. venv/bin/activate; \
python setup.py install; \
python -m ipykernel install --user --name=grid; \
jupyter lab;\
)

.PHONY: test
test: venv
(. venv/bin/activate; \
python setup.py install; \
venv/bin/coverage run setup.py test;\
)

clean:
rm -rf venv
8 changes: 8 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
black
requests
pre-commit
pytest
websocket_client
websockets>=7.0
Flask
flask_socketio

0 comments on commit 5b2e4f9

Please sign in to comment.