Skip to content

Commit 7c5c7ec

Browse files
authored
[ci][python] Add isort to sort out import (#6871)
* Add isort config file to fix conflict with black * Add some doc about isort
1 parent 54933b3 commit 7c5c7ec

17 files changed

Lines changed: 63 additions & 32 deletions

File tree

.github/workflows/py-ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ jobs:
5050
python-version: 3.7
5151
- name: Install Development Dependences
5252
run: pip install -r requirements_dev.txt
53+
- name: Run Isort Checking
54+
run: isort --check .
5355
- name: Run Black Checking
5456
run: black --check .
5557
- name: Run Flake8 Checking
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
[settings]
19+
profile=black

dolphinscheduler-python/pydolphinscheduler/README.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
[![GitHub Build][ga-py-test]][ga]
2323
[![Code style: black][black-shield]][black-gh]
24+
[![Imports: isort][isort-shield]][isort-gh]
2425

2526
pydolphinscheduler is python API for Apache DolphinScheduler, which allow you definition
2627
your workflow by python code, aka workflow-as-codes.
@@ -104,16 +105,20 @@ and would be implemented in the further.
104105

105106
### Code Style
106107

107-
We use [Black][black] for code formatter and [Flake8][flake8] for pep8 checker. If you use [pycharm][pycharm]
108-
or [IntelliJ IDEA][idea], maybe you could follow [Black-integration][black-editor] to configure them in your environment.
108+
We use [isort][isort] to automatically keep Python imports alphabetically, and use [Black][black] for code
109+
formatter and [Flake8][flake8] for pep8 checker. If you use [pycharm][pycharm]or [IntelliJ IDEA][idea],
110+
maybe you could follow [Black-integration][black-editor] to configure them in your environment.
109111

110-
Our Python API CI would automatically run unittest when you submit pull request in GitHub, you could also run
111-
static check locally.
112+
Our Python API CI would automatically run code style checker and unittest when you submit pull request in
113+
GitHub, you could also run static check locally.
112114

113115
```shell
114-
# We recommend you run Black before Flake8, because Black could auto fix some code style issue
116+
# We recommend you run isort and Black before Flake8, because Black could auto fix some code style issue
115117
# but Flake8 just hint when code style not match pep8
116118

119+
# Run Isort
120+
isort .
121+
117122
# Run Black
118123
black .
119124

@@ -158,8 +163,11 @@ this command output.
158163
[flake8]: https://flake8.pycqa.org/en/latest/index.html
159164
[black-editor]: https://black.readthedocs.io/en/stable/integrations/editors.html#pycharm-intellij-idea
160165
[coverage]: https://coverage.readthedocs.io/en/stable/
166+
[isort]: https://pycqa.github.io/isort/index.html
161167
<!-- badge -->
162168
[ga-py-test]: https://github.com/apache/dolphinscheduler/actions/workflows/py-ci.yml/badge.svg?branch=dev
163169
[ga]: https://github.com/apache/dolphinscheduler/actions
164170
[black-shield]: https://img.shields.io/badge/code%20style-black-000000.svg
165171
[black-gh]: https://github.com/psf/black
172+
[isort-shield]: https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336
173+
[isort-gh]: https://pycqa.github.io/isort/

dolphinscheduler-python/pydolphinscheduler/examples/tutorial.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
from pydolphinscheduler.core.process_definition import ProcessDefinition
3434
from pydolphinscheduler.tasks.shell import Shell
3535

36-
3736
with ProcessDefinition(
3837
name="tutorial",
3938
schedule="0 0 0 * * ? *",

dolphinscheduler-python/pydolphinscheduler/requirements_dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ coverage
2424
flake8
2525
flake8-docstrings
2626
flake8-black
27+
isort

dolphinscheduler-python/pydolphinscheduler/src/pydolphinscheduler/core/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
"""DolphinScheduler Base object."""
1919

20-
from typing import Optional, Dict
20+
from typing import Dict, Optional
2121

2222
# from pydolphinscheduler.side.user import User
2323
from pydolphinscheduler.utils.string import attr2camel

dolphinscheduler-python/pydolphinscheduler/src/pydolphinscheduler/core/process_definition.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@
1919

2020
import json
2121
from datetime import datetime
22-
from typing import Optional, List, Dict, Set, Any
22+
from typing import Any, Dict, List, Optional, Set
2323

2424
from pydolphinscheduler.constants import (
25-
ProcessDefinitionReleaseState,
2625
ProcessDefinitionDefault,
26+
ProcessDefinitionReleaseState,
2727
)
2828
from pydolphinscheduler.core.base import Base
2929
from pydolphinscheduler.java_gateway import launch_gateway
30-
from pydolphinscheduler.side import Tenant, Project, User
31-
from pydolphinscheduler.utils.date import conv_from_str, conv_to_schedule, MAX_DATETIME
30+
from pydolphinscheduler.side import Project, Tenant, User
31+
from pydolphinscheduler.utils.date import MAX_DATETIME, conv_from_str, conv_to_schedule
3232

3333

3434
class ProcessDefinitionContext:

dolphinscheduler-python/pydolphinscheduler/src/pydolphinscheduler/core/task.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,21 @@
1717

1818
"""DolphinScheduler ObjectJsonBase, TaskParams and Task object."""
1919

20-
from typing import Optional, List, Dict, Set, Union, Sequence, Tuple
20+
from typing import Dict, List, Optional, Sequence, Set, Tuple, Union
2121

2222
from pydolphinscheduler.constants import (
23-
TaskPriority,
2423
ProcessDefinitionDefault,
2524
TaskFlag,
25+
TaskPriority,
2626
TaskTimeoutFlag,
2727
)
2828
from pydolphinscheduler.core.base import Base
29-
from pydolphinscheduler.core.process_definition import ProcessDefinition
30-
from pydolphinscheduler.core.process_definition import ProcessDefinitionContext
29+
from pydolphinscheduler.core.process_definition import (
30+
ProcessDefinition,
31+
ProcessDefinitionContext,
32+
)
3133
from pydolphinscheduler.java_gateway import launch_gateway
32-
from pydolphinscheduler.utils.string import snake2camel, class_name2camel
34+
from pydolphinscheduler.utils.string import class_name2camel, snake2camel
3335

3436

3537
class ObjectJsonBase:

dolphinscheduler-python/pydolphinscheduler/src/pydolphinscheduler/java_gateway.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from typing import Any, Optional
2121

2222
from py4j.java_collections import JavaMap
23-
from py4j.java_gateway import JavaGateway, GatewayParameters
23+
from py4j.java_gateway import GatewayParameters, JavaGateway
2424

2525
from pydolphinscheduler.constants import JavaGatewayDefault
2626

dolphinscheduler-python/pydolphinscheduler/src/pydolphinscheduler/side/project.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

2020
from typing import Optional
2121

22-
from pydolphinscheduler.core.base_side import BaseSide
2322
from pydolphinscheduler.constants import ProcessDefinitionDefault
23+
from pydolphinscheduler.core.base_side import BaseSide
2424
from pydolphinscheduler.java_gateway import launch_gateway
2525

2626

0 commit comments

Comments
 (0)