Skip to content

Commit

Permalink
[feat][ci] Add pre-commit for easy spotless config (apache#12192)
Browse files Browse the repository at this point in the history
* Use pre-commit to handle spotless check
* Migrate exists python pre-commit-config into dir root one
* Change related document
  • Loading branch information
zhongjiajie authored Sep 29, 2022
1 parent d1e409e commit d3f087e
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,34 +23,43 @@ default_language_version:
# force all python hooks to run python3
python: python3
repos:
# Python API Hooks
- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
name: isort (python)
- repo: https://github.com/psf/black
rev: 22.1.0
rev: 22.3.0
hooks:
- id: black
- repo: https://github.com/pycqa/flake8
rev: 4.0.1
hooks:
- id: flake8
additional_dependencies: [
'flake8-docstrings>=1.6',
'flake8-black>=0.2',
'flake8-docstrings>=1.6',
'flake8-black>=0.2',
]
# pre-commit run in the root, so we have to point out the full path of configuration
args: [
--config,
dolphinscheduler-python/pydolphinscheduler/.flake8
--config,
dolphinscheduler-python/pydolphinscheduler/.flake8
]
- repo: https://github.com/pycqa/autoflake
rev: v1.4
hooks:
- id: autoflake
args: [
--remove-all-unused-imports,
--ignore-init-module-imports,
--in-place
--remove-all-unused-imports,
--ignore-init-module-imports,
--in-place
]
- repo: local
hooks:
# Spotless Hooks
- id: spotless
name: spotless lint
entry: ./mvnw spotless:apply
language: script
pass_filenames: false
17 changes: 14 additions & 3 deletions docs/docs/en/contribute/development-environment-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,20 @@ the code style and formatting errors for you:
./mvnw spotless:apply
```

You could copy the `pre-commit hook` file `/style/pre-commit` to your `.git/hooks/`
directory so that every time you commit your code with `git commit`, `Spotless` will automatically
fix things for you.
We also have provided a `pre-commit` config file for easy configuration. To use it, you need to have python installed
and then install `pre-commit` by running the following command:

```shell
python -m pip install pre-commit
```

After that, you can run the following command to install the `pre-commit` hook:

```shell
pre-commit install
```

Now, every time you commit your code, `pre-commit` will automatically run `Spotless` to check the code style and formatting.

## Docker image build

Expand Down
15 changes: 13 additions & 2 deletions docs/docs/zh/contribute/development-environment-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,19 @@ DolphinScheduler使用`Spotless`检查并修复代码风格和格式问题。
./mvnw spotless:apply
```

您可将`/style/pre-commit`目录下的`pre-commit hook`文件拷贝到您的`.git/hooks/`
目录下,这样您每次使用`git commit`命令时,`Spotless`将会自动为您修复代码风格和格式问题。
我们也提供了一个`pre-commit`配置文件,方便您配置。要使用它,您需要先安装python,然后通过运行以下命令安装`pre-commit`

```shell
python -m pip install pre-commit
```

之后,您可以运行以下命令安装`pre-commit`钩子:

```shell
pre-commit install
```

现在,每次您提交代码时,`pre-commit`都会自动运行`Spotless`来检查代码风格和格式。

## Docker镜像构建

Expand Down
24 changes: 0 additions & 24 deletions style/pre-commit

This file was deleted.

0 comments on commit d3f087e

Please sign in to comment.