Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Doc] Add coding style guide and how to contribute guide #2542

Merged
merged 8 commits into from
Apr 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 77 additions & 4 deletions docs/development/code_style_guide.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,90 @@
# Code Style Guide

TBF

(this document describes the code style we choosed to follow for GraphScope.)
This document provides the coding style guidelines for GraphScope's codebase, which includes C++, Python, Rust, Java, and shell scripts.
Adhering to consistent coding standards across the codebase promotes maintainability, readability, and code quality.

## C++ Style

We follow the [Google C++ Style Guide](https://google.github.io/styleguide/cppguide.html) for coding standards in C++.

## Python Style

We follow the [black](https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html) code style for Python coding standards.

## Rust Style

We follow the [rust-lang code style](https://github.com/rust-lang/style-team/blob/master/guide/guide.md),
with the GraphScope custom [configuration](https://github.com/alibaba/GraphScope/blob/main/interactive_engine/executor/rustfmt.toml) for coding standards in Rust.

## Java Style

we follow the [Google Java Style Guide](https://google.github.io/styleguide/javaguide.html) for coding standards in Java.

## Script Style

## Style Linter and Checker
We follow the [Google Shell Style Guide](https://google.github.io/styleguide/shellguide.html) for coding standards in shell script.

## Style Linter and Checker

GraphScope uses different linters and checkers for each language to enforce code style rules:

- C++: [clang-format-8](https://releases.llvm.org/8.0.0/tools/clang/docs/ClangFormat.html) and [cpplint](https://github.com/cpplint/cpplint)
- Python: [Flake8](https://flake8.pycqa.org/en/latest/)
- Rust: [rust-fmt](https://github.com/rust-lang/rustfmt)
- Java: [google-java-format](https://github.com/google/google-java-format)

Each linter can be included in the build process to ensure that the code adheres to the style guide.
Below are the commands to check the code style in each language:

For C++, format and lint the code by the MakeFile command:

```bash
# format
$ make graphscope_clformat
# lint
$ make graphscope_cpplint
```

For Python:

- Install dependencies first:

```bash
$ pip3 install -r coordinator/requirements-dev.txt
```

- Check the style:

```bash
$ pushd python
$ python3 -m isort --check --diff .
$ python3 -m black --check --diff .
$ python3 -m flake8 .
$ popd
$ pushd coordinator
$ python3 -m isort --check --diff .
$ python3 -m black --check --diff .
$ python3 -m flake8 .
```

For Rust, we provide a shell script to do the format check:

```bash
$ cd interactive_engine/executor
$ ./check_format.sh
```

For Java:

- Download the google-java-format tool:

```bash
$ wget https://github.com/google/google-java-format/releases/download/v1.13.0/google-java-format-1.13.0-all-deps.jar
```

- Check the style:

```bash
$ files_to_format=$(git ls-files *.java)
$ java -jar google-java-format-1.13.0-all-deps.jar --aosp --skip-javadoc-formatting -i $files_to_format
```
167 changes: 165 additions & 2 deletions docs/development/how_to_contribute.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,167 @@
# How to Contribute

TBF
(This document is intended to help you get started contributing to GraphScope project.)
**Thanks for your interest in the GraphScope project.**

GraphScope is an open-source project focused on large-scale graph computation with a friendly community of developers eager to help new contributors.
We welcome contributions of all types, from code improvements to documentation.

## Code of Conduct

Before contributing to or engaging with our community, please read our [Code of Conduct](https://github.com/alibaba/GraphScope/blob/main/CODE_OF_CONDUCT.md).

## Community

A good first step to getting involved in the GraphScope project is to participate in our discussions and join us in our different communication channels.
Here are several ways to connect with us:

### GitHub Discussion

We use [GitHub Discussion](https://github.com/alibaba/GraphScope/discussions) to ask and answer questions. Feel free to ask any questions you may have about GraphScope or issues you've encountered with your own code.

### Slack

Join in the [Slack channel](http://slack.graphscope.io) for discussion.

## Reporting Bugs

If you find a bug in GraphScope, first test against the [latest version of GraphScope](https://github.com/alibaba/GraphScope/tree/main)
to ensure your issue hasn't already been fixed. If not, search our [issues list](https://github.com/alibaba/GraphScope/issues)
on GitHub to see if a similar issue has already been opened.

If you confirm that the bug hasn't already been reported [file a bug issue](https://github.com/alibaba/GraphScope/issues/new?assignees=&labels=&template=bug_report.md&title=%5BBUG%5D+)
before writing any code. When submitting an issue, please include a clear and concise description of the problem,
relevant code or error messages, and steps to reproduce the issue.

## Requesting Features

If you find yourself wishing for a feature that doesn't exist in GraphScope, please open [a feature request issue](https://github.com/alibaba/GraphScope/issues/new?assignees=&labels=&template=feature_request.md&title=)
on GitHub to describe the feature, why it's needed, and how it should work. Other users may share similar needs,
and many of GraphScope's features were added because users saw a need.

## Improving Documentation

A great way to contribute to the project is by improving documentation. If you find any incomplete or inaccurate documentation,
please share your knowledge with the community.

Documentation improvements are also a great way to gain some experience with our submission and review process, discussed below, without requiring a lot of local development environment setup.
In fact, many documentation-only changes can be made directly in the [GraphScope document pages](https://graphscope.io/docs/) by clicking the “Edit On Github” button. This will handle making a fork and a pull request for you.

TBF: add a link to how to helping with documentation
TBF: add a link to how to build the documentation


## Contributing Code and Documentation Changes

If you would like to contribute a new feature or a bug fix to GraphScope, please first discuss your idea on a GitHub issue.
If there isn't an issue for it, create one. There may be someone already working on it, or it may have particular complexities
that you should be aware of before starting to code. There are often several ways to fix a problem, so it's important to find
the right approach before spending time on a PR that can't be merged.

### Install pre-commit

GraphScope use `pre-commit`_ to ensure no secrets are accidentally committed
into the Git repository. Before contributing, install `pre-commit` by typing:

```bash
$ pip3 install pre-commit
```

Configure the necessary pre-commit hooks with:

```bash
$ pre-commit install --install-hooks
```

### Minor Fixes

For minor changes that affect documentation, you don't need to open a GitHub issue. Instead,
add the prefix "[MINOR]" to the title of your PR if it meets the following guidelines:

* Grammar, usage and spelling fixes that affect no more than 2 files
* Documentation updates affecting no more than 2 files and not more
than 500 words.

### Fork and Create a Branch

Fork the main GraphScope code and clone it to your local machine. See
[GitHub help page](https://help.github.com/articles/fork-a-repo) for help.

Create a branch with a descriptive name.

A good branch name would be (where issue #42 is the ticket you're working on):

```bash
$ git checkout -b 42-add-chinese-translations
```

### Get the Test Suite Running

See [our how-to guide on testing](./how_to_test.md) for help.

### Implement Your Fix or Feature

At this point, you're ready to make the changes. Feel free to ask for help because everyone is a beginner at first!

### Get the Code Format and Style Right

Your patch should follow the same conventions and pass the same code quality checks as the rest of the project.
Follow [our code style guide](./code_style_guide.md) to attain the proper code format and style.

### Submitting Your Changes

See [our guide on how to submit a pull request](./how_to_submit_pr.md).

### Discussing and Keeping Your Pull Request Updated

You will probably receive feedback or requests for changes to your pull request.
This is big part of the submission process and is necessary to evaluate your changes correctly,
so don't be discouraged!

If a maintainer asks you to "rebase" your pull request, it means that a lot of code has changed and
you need to update your branch so it's easier to merge. To learn more about rebasing in Git, refer to the recommended workflow:

```bash
$ git checkout 42-add-chinese-translations
$ git pull --rebase upstream main
$ git push --force-with-lease 42-add-chinese-translations
```

Feel free to comment in the pull request to ping reviewers if you're awaiting a response.
If you encounter unfamiliar words or acronyms, refer to this [glossary](https://chromium.googlesource.com/chromiumos/docs/+/HEAD/glossary.md).

### Merging a PR (maintainers only)

A pull request can only be merged into main by a maintainer if:

* It is passing CI.
* At least two maintainers have approved it. If a maintainer opened the PR, only one extra approval is needed.
* There are no requested changes.
* It is up to date with current main.

### Shipping a Release (maintainers only)

TODO(dongze): TBF


## How to Review Pull Requests

We welcome contributions from the community and encourage everyone to review pull requests. When reviewing a pull request, please consider the following:

- Does the code follow our [Code of Conduct][1]?
- Does the code solve the problem described in the issue or feature request?
- Are there any potential side effects or edge cases that need to be considered?
- Are there any tests included to ensure the code works as expected?

If you have any questions or concerns about a pull request, please comment on the pull request or reach out to the contributor directly.

## Continuous integration testing

All pull requests that contain changes to code must be run through
continuous integration (CI) testing at [Github Actions](https://github.com/alibaba/GarphScope/actions)

The pull request change will trigger a CI testing run. Ideally, the code change
will pass ("be green") on all platform configurations supported by GraphScope.
This means that all tests pass and there are no linting errors. In reality,
however, it is not uncommon for the CI infrastructure itself to fail on specific
platforms ("be red"). It is vital to visually inspect the results of all failed ("red") tests
to determine whether the failure was caused by the changes in the pull request.