Skip to content

Commit 18ff252

Browse files
noidname01TimWang
and
TimWang
authored
[#3206]improvement(client-python): Add Black for client-python (#3254) (#3325)
### What changes were proposed in this pull request? * Add Black as code formatter, it enforce the coding style with 1. trailing commas and whitespaces 2. unified quotation marks(") 3. new lines 4. max line length 5. indents * Aligned with Pylint Rules * Add Black into Gradle and form a code formatting pipeline (pipInstall -> Black -> Pylint), this pipeline will run implicitly in `build` and `test` gradle tasks. > Note that Black still can't format long entire string exceeding `max line length` without enabling unstable features, please handle long strings with caution and make Pylint to ignore them if they are really necessary. ### Why are the changes needed? Fix: #3206, #3203 ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? No Co-authored-by: TimWang <tim.wang@pranaq.com>
1 parent 84f8d5e commit 18ff252

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+859
-371
lines changed

clients/client-python/build.gradle.kts

+15-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,15 @@ tasks {
3838
args = listOf("install", "-e", ".[dev]")
3939
}
4040

41+
val black by registering(VenvTask::class) {
42+
dependsOn(pipInstall)
43+
venvExec = "black"
44+
args = listOf("./gravitino", "./tests")
45+
}
46+
4147
val pylint by registering(VenvTask::class) {
48+
dependsOn(pipInstall)
49+
mustRunAfter(black)
4250
venvExec = "pylint"
4351
args = listOf("./gravitino", "./tests")
4452
}
@@ -50,7 +58,6 @@ tasks {
5058
gravitinoServer("start")
5159
}
5260

53-
dependsOn(pipInstall, pylint)
5461
venvExec = "python"
5562
args = listOf("-m", "unittest")
5663
workingDir = projectDir.resolve(".")
@@ -67,7 +74,6 @@ tasks {
6774
}
6875

6976
val build by registering(VenvTask::class) {
70-
dependsOn(pipInstall, pylint)
7177
}
7278

7379
val clean by registering(Delete::class) {
@@ -79,4 +85,11 @@ tasks {
7985
deleteCacheDir("__pycache__")
8086
}
8187
}
88+
89+
matching {
90+
it.name.endsWith("envSetup")
91+
}.all {
92+
// add install package and code formatting before any tasks
93+
finalizedBy(pipInstall, black, pylint)
94+
}
8295
}

clients/client-python/gravitino/api/audit.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Copyright 2024 Datastrato Pvt Ltd.
33
This software is licensed under the Apache License version 2.
44
"""
5+
56
from abc import ABC, abstractmethod
67
from datetime import datetime
78

clients/client-python/gravitino/api/auditable.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Copyright 2024 Datastrato Pvt Ltd.
33
This software is licensed under the Apache License version 2.
44
"""
5+
56
from abc import ABC, abstractmethod
67

78
from gravitino.api.audit import Audit

clients/client-python/gravitino/api/catalog.py

+12-6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Copyright 2024 Datastrato Pvt Ltd.
33
This software is licensed under the Apache License version 2.
44
"""
5+
56
from abc import abstractmethod
67
from enum import Enum
78
from typing import Dict, Optional
@@ -14,6 +15,7 @@ class Catalog(Auditable):
1415
"""The interface of a catalog. The catalog is the second level entity in the gravitino system,
1516
containing a set of tables.
1617
"""
18+
1719
class Type(Enum):
1820
"""The type of the catalog."""
1921

@@ -92,9 +94,11 @@ def as_schemas(self) -> SupportsSchemas:
9294
Returns:
9395
The {@link SupportsSchemas} if the catalog supports schema operations.
9496
"""
95-
raise UnsupportedOperationException("Catalog does not support schema operations")
97+
raise UnsupportedOperationException(
98+
"Catalog does not support schema operations"
99+
)
96100

97-
def as_table_catalog(self) -> 'TableCatalog':
101+
def as_table_catalog(self) -> "TableCatalog":
98102
"""
99103
Raises:
100104
UnsupportedOperationException if the catalog does not support table operations.
@@ -104,17 +108,19 @@ def as_table_catalog(self) -> 'TableCatalog':
104108
"""
105109
raise UnsupportedOperationException("Catalog does not support table operations")
106110

107-
def as_fileset_catalog(self) -> 'FilesetCatalog':
111+
def as_fileset_catalog(self) -> "FilesetCatalog":
108112
"""
109113
Raises:
110114
UnsupportedOperationException if the catalog does not support fileset operations.
111115
112116
Returns:
113117
the FilesetCatalog if the catalog supports fileset operations.
114118
"""
115-
raise UnsupportedOperationException("Catalog does not support fileset operations")
119+
raise UnsupportedOperationException(
120+
"Catalog does not support fileset operations"
121+
)
116122

117-
def as_topic_catalog(self) -> 'TopicCatalog':
123+
def as_topic_catalog(self) -> "TopicCatalog":
118124
"""
119125
Returns:
120126
the {@link TopicCatalog} if the catalog supports topic operations.
@@ -126,4 +132,4 @@ def as_topic_catalog(self) -> 'TopicCatalog':
126132

127133

128134
class UnsupportedOperationException(Exception):
129-
pass
135+
pass

clients/client-python/gravitino/api/catalog_change.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Copyright 2024 Datastrato Pvt Ltd.
33
This software is licensed under the Apache License version 2.
44
"""
5+
56
from abc import ABC
67

78

clients/client-python/gravitino/api/fileset.py

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Copyright 2024 Datastrato Pvt Ltd.
33
This software is licensed under the Apache License version 2.
44
"""
5+
56
from abc import abstractmethod
67
from enum import Enum
78
from typing import Optional, Dict
@@ -20,6 +21,7 @@ class Fileset(Auditable):
2021
Fileset defines the basic properties of a fileset object. A catalog implementation
2122
with FilesetCatalog should implement this interface.
2223
"""
24+
2325
class Type(Enum):
2426
"""An enum representing the type of the fileset object."""
2527

clients/client-python/gravitino/api/fileset_change.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Copyright 2024 Datastrato Pvt Ltd.
33
This software is licensed under the Apache License version 2.
44
"""
5+
56
from abc import ABC
67
from dataclasses import field
78

@@ -65,7 +66,7 @@ def remove_property(property):
6566
class RenameFileset:
6667
"""A fileset change to rename the fileset."""
6768

68-
_new_name: str = field(metadata=config(field_name='new_name'))
69+
_new_name: str = field(metadata=config(field_name="new_name"))
6970

7071
def __init__(self, new_name):
7172
self._new_name = new_name
@@ -113,7 +114,7 @@ def __str__(self):
113114
class UpdateFilesetComment:
114115
"""A fileset change to update the fileset comment."""
115116

116-
_new_comment: str = field(metadata=config(field_name='new_comment'))
117+
_new_comment: str = field(metadata=config(field_name="new_comment"))
117118

118119
def __init__(self, new_comment):
119120
self._new_comment = new_comment
@@ -161,8 +162,8 @@ def __str__(self):
161162
class SetProperty:
162163
"""A fileset change to set the property and value for the fileset."""
163164

164-
_property: str = field(metadata=config(field_name='property'))
165-
_value: str = field(metadata=config(field_name='value'))
165+
_property: str = field(metadata=config(field_name="property"))
166+
_value: str = field(metadata=config(field_name="value"))
166167

167168
def __init__(self, property: str, value: str):
168169
self._property = property
@@ -219,7 +220,7 @@ def __str__(self):
219220
class RemoveProperty:
220221
"""A fileset change to remove a property from the fileset."""
221222

222-
_property: str = field(metadata=config(field_name='property'))
223+
_property: str = field(metadata=config(field_name="property"))
223224

224225
def __init__(self, property: str):
225226
self._property = property

clients/client-python/gravitino/api/metalake.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Copyright 2024 Datastrato Pvt Ltd.
33
This software is licensed under the Apache License version 2.
44
"""
5+
56
from abc import abstractmethod
67
from typing import Optional, Dict
78

clients/client-python/gravitino/api/metalake_change.py

+13-8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Copyright 2024 Datastrato Pvt Ltd.
33
This software is licensed under the Apache License version 2.
44
"""
5+
56
from dataclasses import dataclass, field
67

78
from dataclasses_json import config
@@ -14,7 +15,7 @@ class MetalakeChange:
1415
"""
1516

1617
@staticmethod
17-
def rename(new_name: str) -> 'MetalakeChange.RenameMetalake':
18+
def rename(new_name: str) -> "MetalakeChange.RenameMetalake":
1819
"""Creates a new metalake change to rename the metalake.
1920
2021
Args:
@@ -26,7 +27,7 @@ def rename(new_name: str) -> 'MetalakeChange.RenameMetalake':
2627
return MetalakeChange.RenameMetalake(new_name)
2728

2829
@staticmethod
29-
def update_comment(new_comment: str) -> 'MetalakeChange.UpdateMetalakeComment':
30+
def update_comment(new_comment: str) -> "MetalakeChange.UpdateMetalakeComment":
3031
"""Creates a new metalake change to update the metalake comment.
3132
3233
Args:
@@ -38,7 +39,7 @@ def update_comment(new_comment: str) -> 'MetalakeChange.UpdateMetalakeComment':
3839
return MetalakeChange.UpdateMetalakeComment(new_comment)
3940

4041
@staticmethod
41-
def set_property(property: str, value: str) -> 'SetProperty':
42+
def set_property(property: str, value: str) -> "SetProperty":
4243
"""Creates a new metalake change to set a property and value pair for the metalake.
4344
4445
Args:
@@ -51,7 +52,7 @@ def set_property(property: str, value: str) -> 'SetProperty':
5152
return MetalakeChange.SetProperty(property, value)
5253

5354
@staticmethod
54-
def remove_property(property: str) -> 'RemoveProperty':
55+
def remove_property(property: str) -> "RemoveProperty":
5556
"""Creates a new metalake change to remove a property from the metalake.
5657
5758
Args:
@@ -65,7 +66,8 @@ def remove_property(property: str) -> 'RemoveProperty':
6566
@dataclass(frozen=True)
6667
class RenameMetalake:
6768
"""A metalake change to rename the metalake."""
68-
_new_name: str = field(metadata=config(field_name='new_name'))
69+
70+
_new_name: str = field(metadata=config(field_name="new_name"))
6971

7072
def new_name(self) -> str:
7173
return self._new_name
@@ -76,7 +78,8 @@ def __str__(self):
7678
@dataclass(frozen=True)
7779
class UpdateMetalakeComment:
7880
"""A metalake change to update the metalake comment"""
79-
_new_comment: str = field(metadata=config(field_name='new_comment'))
81+
82+
_new_comment: str = field(metadata=config(field_name="new_comment"))
8083

8184
def new_comment(self) -> str:
8285
return self._new_comment
@@ -87,8 +90,9 @@ def __str__(self):
8790
@dataclass(frozen=True)
8891
class SetProperty:
8992
"""A metalake change to set a property and value pair for the metalake"""
90-
_property: str = field(metadata=config(field_name='property'))
91-
_value: str = field(metadata=config(field_name='value'))
93+
94+
_property: str = field(metadata=config(field_name="property"))
95+
_value: str = field(metadata=config(field_name="value"))
9296

9397
def property(self) -> str:
9498
return self._property
@@ -102,6 +106,7 @@ def __str__(self):
102106
@dataclass(frozen=True)
103107
class RemoveProperty:
104108
"""A metalake change to remove a property from the metalake"""
109+
105110
_property: str
106111

107112
def property(self) -> str:

clients/client-python/gravitino/api/schema.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Copyright 2024 Datastrato Pvt Ltd.
33
This software is licensed under the Apache License version 2.
44
"""
5+
56
from abc import abstractmethod
67
from typing import Optional, Dict
78

clients/client-python/gravitino/api/schema_change.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Copyright 2024 Datastrato Pvt Ltd.
33
This software is licensed under the Apache License version 2.
44
"""
5+
56
from abc import ABC
67
from dataclasses import field
78

@@ -39,8 +40,8 @@ def remove_property(property: str):
3940
class SetProperty:
4041
"""SchemaChange class to set the property and value pairs for the schema."""
4142

42-
_property: str = field(metadata=config(field_name='property'))
43-
_value: str = field(metadata=config(field_name='value'))
43+
_property: str = field(metadata=config(field_name="property"))
44+
_value: str = field(metadata=config(field_name="value"))
4445

4546
def __init__(self, property: str, value: str):
4647
self._property = property
@@ -97,7 +98,7 @@ def __str__(self):
9798
class RemoveProperty:
9899
"""SchemaChange class to remove a property from the schema."""
99100

100-
_property: str = field(metadata=config(field_name='property'))
101+
_property: str = field(metadata=config(field_name="property"))
101102

102103
def __init__(self, property: str):
103104
self._property = property

clients/client-python/gravitino/api/supports_schemas.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Copyright 2024 Datastrato Pvt Ltd.
33
This software is licensed under the Apache License version 2.
44
"""
5+
56
from abc import ABC, abstractmethod
67
from typing import List, Dict
78

@@ -13,6 +14,7 @@
1314

1415
class NoSuchSchemaException(Exception):
1516
"""Exception raised if the schema does not exist."""
17+
1618
pass
1719

1820

@@ -60,7 +62,9 @@ def schema_exists(self, ident: NameIdentifier) -> bool:
6062
return False
6163

6264
@abstractmethod
63-
def create_schema(self, ident: NameIdentifier, comment: str, properties: Dict[str, str]) -> Schema:
65+
def create_schema(
66+
self, ident: NameIdentifier, comment: str, properties: Dict[str, str]
67+
) -> Schema:
6468
"""Create a schema in the catalog.
6569
6670
Args:
@@ -110,7 +114,7 @@ def alter_schema(self, ident: NameIdentifier, *changes: SchemaChange) -> Schema:
110114

111115
@abstractmethod
112116
def drop_schema(self, ident: NameIdentifier, cascade: bool) -> bool:
113-
"""Drop a schema from the catalog. If cascade option is true, recursively
117+
"""Drop a schema from the catalog. If cascade option is true, recursively
114118
drop all objects within the schema.
115119
116120
Args:

0 commit comments

Comments
 (0)