Skip to content

Commit

Permalink
[apache#3205] improvement(client-python): Apply naming convention to …
Browse files Browse the repository at this point in the history
…client-python (apache#3369)

### What changes were proposed in this pull request?

- Define naming style of each class, module, function and variable
- See `pylintrc` for detail settings

### Why are the changes needed?

Fix: apache#3205 

### Does this PR introduce _any_ user-facing change?

No

### How was this patch tested?

No

---------

Co-authored-by: TimWang <[email protected]>
  • Loading branch information
noidname01 and TimWang authored May 13, 2024
1 parent f207466 commit 0a3caed
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ def drop_metalake(self, ident: NameIdentifier) -> bool:
resp = self._rest_client.delete(
self.API_METALAKES_IDENTIFIER_PATH + ident.name()
)
dropResponse = DropResponse.from_json(resp.body, infer_missing=True)
drop_response = DropResponse.from_json(resp.body, infer_missing=True)

return dropResponse.dropped()
return drop_response.dropped()
except Exception:
logger.warning("Failed to drop metalake %s", ident)
return False
6 changes: 3 additions & 3 deletions clients/client-python/gravitino/client/gravitino_metalake.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ def list_catalogs(self, namespace: Namespace) -> List[NameIdentifier]:
Namespace.check_catalog(namespace)
url = f"api/metalakes/{namespace.level(0)}/catalogs"
response = self.rest_client.get(url)
entityList = EntityListResponse.from_json(response.body, infer_missing=True)
entityList.validate()
return entityList.identifiers()
entity_list = EntityListResponse.from_json(response.body, infer_missing=True)
entity_list.validate()
return entity_list.identifiers()

def list_catalogs_info(self, namespace: Namespace) -> List[Catalog]:
"""List all the catalogs with their information under this metalake with specified namespace.
Expand Down
4 changes: 2 additions & 2 deletions clients/client-python/gravitino/dto/version_dto.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class VersionDTO:
version: str = ""
"""The version of the software."""

compileDate: str = ""
compile_date: str = ""
"""The date the software was compiled."""

gitCommit: str = ""
git_commit: str = ""
"""The git commit of the software."""
8 changes: 5 additions & 3 deletions clients/client-python/gravitino/name_identifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
This software is licensed under the Apache License version 2.
"""

from typing import ClassVar

from dataclasses import dataclass, field

from dataclasses_json import DataClassJsonMixin, config
Expand All @@ -21,11 +23,11 @@ class NameIdentifier(DataClassJsonMixin):
schema.
"""

_DOT: ClassVar[str] = "."

_name: str = field(metadata=config(field_name="name"))
_namespace: Namespace = field(metadata=config(field_name="namespace"))

DOT: str = "."

@classmethod
def builder(cls, namespace: Namespace, name: str):
return NameIdentifier(_namespace=namespace, _name=name)
Expand Down Expand Up @@ -241,7 +243,7 @@ def parse(identifier: str) -> "NameIdentifier":
"Cannot parse a null or empty identifier",
)

parts = identifier.split(NameIdentifier.DOT)
parts = identifier.split(NameIdentifier._DOT)
return NameIdentifier.of(*parts)

def has_namespace(self):
Expand Down
4 changes: 2 additions & 2 deletions clients/client-python/gravitino/namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
This software is licensed under the Apache License version 2.
"""

from typing import List
from typing import List, ClassVar


class Namespace:
Expand All @@ -12,7 +12,7 @@ class Namespace:
"metalake1.catalog1.schema1" are all valid namespaces.
"""

_DOT: str = "."
_DOT: ClassVar[str] = "."

_levels: List[str] = []

Expand Down
4 changes: 2 additions & 2 deletions clients/client-python/gravitino/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
from typing import Mapping, Sequence, Union

# https://github.com/python/typing/issues/182#issuecomment-1320974824
JSON_ro = Union[
Mapping[str, "JSON_ro"], Sequence["JSON_ro"], str, int, float, bool, None
JSONType = Union[
Mapping[str, "JSONType"], Sequence["JSONType"], str, int, float, bool, None
]
4 changes: 2 additions & 2 deletions clients/client-python/gravitino/utils/http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from urllib.error import HTTPError
import json as _json

from gravitino.typing import JSON_ro
from gravitino.typing import JSONType
from gravitino.utils.exceptions import handle_error
from gravitino.constants import TIMEOUT

Expand Down Expand Up @@ -165,7 +165,7 @@ def close(self):

def unpack(path: str):
def decorator(func):
def wrapper(*args, **kwargs) -> JSON_ro:
def wrapper(*args, **kwargs) -> JSONType:
resp = func(*args, **kwargs)
rv = resp.json()
for p in path.split("."):
Expand Down
23 changes: 21 additions & 2 deletions clients/client-python/pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ disable=missing-class-docstring,
protected-access, #TODO-fix
too-many-arguments, #TODO-fix
inconsistent-return-statements, #TODO-fix
invalid-name, #TODO-config

[LOGGING]

Expand Down Expand Up @@ -63,4 +62,24 @@ ignore-long-lines=^\s*(# )?<?https?://\S+>?$
indent-after-paren=4

# String used as indentation unit.
indent-string=' '
indent-string=' '

[BASIC]

# Naming Style for Const
const-naming-style=UPPER_CASE

# Naming Style for Class
class-naming-style=PascalCase
class-const-naming-style=UPPER_CASE
class-attribute-naming-style=any
attr-naming-style=snake_case

# Naming Style for Function and Method
function-naming-style=snake_case
method-naming-style=snake_case
argument-naming-style=snake_case
variable-naming-style=snake_case

# Naming Style for Module
module-naming-style=snake_case
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ def setUpClass(cls):
logger.error("ERROR: Can't find online Gravitino server!")
return

GravitinoHome = os.environ.get("GRAVITINO_HOME")
if GravitinoHome is None:
gravitino_home = os.environ.get("GRAVITINO_HOME")
if gravitino_home is None:
logger.error(
"Gravitino Python client integration test must configure `GRAVITINO_HOME`"
)
sys.exit(0)

cls.gravitino_startup_script = os.path.join(GravitinoHome, "bin/gravitino.sh")
cls.gravitino_startup_script = os.path.join(gravitino_home, "bin/gravitino.sh")
if not os.path.exists(cls.gravitino_startup_script):
logger.error(
"Can't find Gravitino startup script: %s, "
Expand Down

0 comments on commit 0a3caed

Please sign in to comment.