[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
This commit is contained in:
parent
d1e409e9a2
commit
d3f087e29b
|
|
@ -23,13 +23,14 @@ default_language_version:
|
||||||
# force all python hooks to run python3
|
# force all python hooks to run python3
|
||||||
python: python3
|
python: python3
|
||||||
repos:
|
repos:
|
||||||
|
# Python API Hooks
|
||||||
- repo: https://github.com/pycqa/isort
|
- repo: https://github.com/pycqa/isort
|
||||||
rev: 5.10.1
|
rev: 5.10.1
|
||||||
hooks:
|
hooks:
|
||||||
- id: isort
|
- id: isort
|
||||||
name: isort (python)
|
name: isort (python)
|
||||||
- repo: https://github.com/psf/black
|
- repo: https://github.com/psf/black
|
||||||
rev: 22.1.0
|
rev: 22.3.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: black
|
- id: black
|
||||||
- repo: https://github.com/pycqa/flake8
|
- repo: https://github.com/pycqa/flake8
|
||||||
|
|
@ -37,20 +38,28 @@ repos:
|
||||||
hooks:
|
hooks:
|
||||||
- id: flake8
|
- id: flake8
|
||||||
additional_dependencies: [
|
additional_dependencies: [
|
||||||
'flake8-docstrings>=1.6',
|
'flake8-docstrings>=1.6',
|
||||||
'flake8-black>=0.2',
|
'flake8-black>=0.2',
|
||||||
]
|
]
|
||||||
# pre-commit run in the root, so we have to point out the full path of configuration
|
# pre-commit run in the root, so we have to point out the full path of configuration
|
||||||
args: [
|
args: [
|
||||||
--config,
|
--config,
|
||||||
dolphinscheduler-python/pydolphinscheduler/.flake8
|
dolphinscheduler-python/pydolphinscheduler/.flake8
|
||||||
]
|
]
|
||||||
- repo: https://github.com/pycqa/autoflake
|
- repo: https://github.com/pycqa/autoflake
|
||||||
rev: v1.4
|
rev: v1.4
|
||||||
hooks:
|
hooks:
|
||||||
- id: autoflake
|
- id: autoflake
|
||||||
args: [
|
args: [
|
||||||
--remove-all-unused-imports,
|
--remove-all-unused-imports,
|
||||||
--ignore-init-module-imports,
|
--ignore-init-module-imports,
|
||||||
--in-place
|
--in-place
|
||||||
]
|
]
|
||||||
|
- repo: local
|
||||||
|
hooks:
|
||||||
|
# Spotless Hooks
|
||||||
|
- id: spotless
|
||||||
|
name: spotless lint
|
||||||
|
entry: ./mvnw spotless:apply
|
||||||
|
language: script
|
||||||
|
pass_filenames: false
|
||||||
|
|
@ -38,9 +38,20 @@ the code style and formatting errors for you:
|
||||||
./mvnw spotless:apply
|
./mvnw spotless:apply
|
||||||
```
|
```
|
||||||
|
|
||||||
You could copy the `pre-commit hook` file `/style/pre-commit` to your `.git/hooks/`
|
We also have provided a `pre-commit` config file for easy configuration. To use it, you need to have python installed
|
||||||
directory so that every time you commit your code with `git commit`, `Spotless` will automatically
|
and then install `pre-commit` by running the following command:
|
||||||
fix things for you.
|
|
||||||
|
```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
|
## Docker image build
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,8 +37,19 @@ DolphinScheduler使用`Spotless`检查并修复代码风格和格式问题。
|
||||||
./mvnw spotless:apply
|
./mvnw spotless:apply
|
||||||
```
|
```
|
||||||
|
|
||||||
您可将`/style/pre-commit`目录下的`pre-commit hook`文件拷贝到您的`.git/hooks/`
|
我们也提供了一个`pre-commit`配置文件,方便您配置。要使用它,您需要先安装python,然后通过运行以下命令安装`pre-commit`:
|
||||||
目录下,这样您每次使用`git commit`命令时,`Spotless`将会自动为您修复代码风格和格式问题。
|
|
||||||
|
```shell
|
||||||
|
python -m pip install pre-commit
|
||||||
|
```
|
||||||
|
|
||||||
|
之后,您可以运行以下命令安装`pre-commit`钩子:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
pre-commit install
|
||||||
|
```
|
||||||
|
|
||||||
|
现在,每次您提交代码时,`pre-commit`都会自动运行`Spotless`来检查代码风格和格式。
|
||||||
|
|
||||||
## Docker镜像构建
|
## Docker镜像构建
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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
|
|
||||||
Loading…
Reference in New Issue