Browse Source

[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
3.2.0-release
Jiajie Zhong 2 years ago committed by GitHub
parent
commit
d3f087e29b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 25
      .pre-commit-config.yaml
  2. 17
      docs/docs/en/contribute/development-environment-setup.md
  3. 15
      docs/docs/zh/contribute/development-environment-setup.md
  4. 24
      style/pre-commit

25
dolphinscheduler-python/pydolphinscheduler/.pre-commit-config.yaml → .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

17
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

15
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镜像构建

24
style/pre-commit

@ -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…
Cancel
Save