This is an automated email from the ASF dual-hosted git repository.
zhongjiajie pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git
The following commit(s) were added to refs/heads/dev by this push:
new d3f087e29b [feat][ci] Add pre-commit for easy spotless config (#12192)
d3f087e29b is described below
commit d3f087e29b212ee9295fe155de6e5ec91b8f2be6
Author: Jiajie Zhong <[email protected]>
AuthorDate: Thu Sep 29 10:10:53 2022 +0800
[feat][ci] Add pre-commit for easy spotless config (#12192)
* Use pre-commit to handle spotless check
* Migrate exists python pre-commit-config into dir root one
* Change related document
---
...e-commit-config.yaml => .pre-commit-config.yaml | 25 +++++++++++++++-------
.../en/contribute/development-environment-setup.md | 17 ++++++++++++---
.../zh/contribute/development-environment-setup.md | 15 +++++++++++--
style/pre-commit | 24 ---------------------
4 files changed, 44 insertions(+), 37 deletions(-)
diff --git a/dolphinscheduler-python/pydolphinscheduler/.pre-commit-config.yaml
b/.pre-commit-config.yaml
similarity index 76%
rename from dolphinscheduler-python/pydolphinscheduler/.pre-commit-config.yaml
rename to .pre-commit-config.yaml
index 9e817a50e0..38031544df 100644
--- a/dolphinscheduler-python/pydolphinscheduler/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -23,13 +23,14 @@ 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
@@ -37,20 +38,28 @@ repos:
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
diff --git a/docs/docs/en/contribute/development-environment-setup.md
b/docs/docs/en/contribute/development-environment-setup.md
index d65454a06e..5520f01ee8 100644
--- a/docs/docs/en/contribute/development-environment-setup.md
+++ b/docs/docs/en/contribute/development-environment-setup.md
@@ -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
diff --git a/docs/docs/zh/contribute/development-environment-setup.md
b/docs/docs/zh/contribute/development-environment-setup.md
index 1edbe8efec..5caae63b60 100644
--- a/docs/docs/zh/contribute/development-environment-setup.md
+++ b/docs/docs/zh/contribute/development-environment-setup.md
@@ -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镜像构建
diff --git a/style/pre-commit b/style/pre-commit
deleted file mode 100644
index 89ef99f755..0000000000
--- a/style/pre-commit
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/bin/sh
-#
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-# A hook script to automatically fix code style and formatting errors with
spotless
-if ./mvnw spotless:check; then
- exit 0
-fi
-./mvnw spotless:apply
-exit 1