Skip to content

Commit

Permalink
Apply formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
chezou committed Aug 31, 2024
1 parent 89d51f2 commit e68c34c
Show file tree
Hide file tree
Showing 20 changed files with 164 additions and 217 deletions.
5 changes: 2 additions & 3 deletions tdclient/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def __init__(
retry_post_requests=False,
max_cumul_retry_delay=600,
http_proxy=None,
**kwargs
**kwargs,
):
headers = {} if headers is None else headers
if apikey is not None:
Expand Down Expand Up @@ -493,7 +493,6 @@ def build_request(self, path=None, headers=None, endpoint=None):
return (url, _headers)

def send_request(self, method, url, fields=None, body=None, headers=None, **kwargs):

if body is None:
return self.http.request(
method, url, fields=fields, headers=headers, **kwargs
Expand Down Expand Up @@ -597,7 +596,7 @@ def _read_csv_file(
encoding="utf-8",
dtypes=None,
converters=None,
**kwargs
**kwargs,
):
if columns is None:
reader = csv_dict_record_reader(file_like, encoding, dialect)
Expand Down
2 changes: 1 addition & 1 deletion tdclient/bulk_import_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def bulk_import_upload_file(self, name, part_name, format, file, **kwargs):
The default behaviour is ``"guess"``, which makes a best-effort to decide
the column datatype. See `file import parameters`_ for more details.
.. _`file import parameters`:
https://tdclient.readthedocs.io/en/latest/file_import_parameters.html
"""
Expand Down
53 changes: 21 additions & 32 deletions tdclient/bulk_import_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@


class BulkImport(Model):
"""Bulk-import session on Treasure Data Service
"""
"""Bulk-import session on Treasure Data Service"""

STATUS_UPLOADING = "uploading"
STATUS_PERFORMING = "performing"
Expand Down Expand Up @@ -38,79 +37,66 @@ def update(self):

@property
def name(self):
"""A name of the bulk import session
"""
"""A name of the bulk import session"""
return self._name

@property
def database(self):
"""A database name in a string which the bulk import session is working on
"""
"""A database name in a string which the bulk import session is working on"""
return self._database

@property
def table(self):
"""A table name in a string which the bulk import session is working on
"""
"""A table name in a string which the bulk import session is working on"""
return self._table

@property
def status(self):
"""The status of the bulk import session in a string
"""
"""The status of the bulk import session in a string"""
return self._status

@property
def job_id(self):
"""Job ID
"""
"""Job ID"""
return self._job_id

@property
def valid_records(self):
"""The number of valid records.
"""
"""The number of valid records."""
return self._valid_records

@property
def error_records(self):
"""The number of error records.
"""
"""The number of error records."""
return self._error_records

@property
def valid_parts(self):
"""The number of valid parts.
"""
"""The number of valid parts."""
return self._valid_parts

@property
def error_parts(self):
"""The number of error parts.
"""
"""The number of error parts."""
return self._error_parts

@property
def upload_frozen(self):
"""The number of upload frozen.
"""
"""The number of upload frozen."""
return self._upload_frozen

def delete(self):
"""Delete bulk import
"""
"""Delete bulk import"""
return self._client.delete_bulk_import(self.name)

def freeze(self):
"""Freeze bulk import
"""
"""Freeze bulk import"""
response = self._client.freeze_bulk_import(self.name)
self.update()
return response

def unfreeze(self):
"""Unfreeze bulk import
"""
"""Unfreeze bulk import"""
response = self._client.unfreeze_bulk_import(self.name)
self.update()
return response
Expand All @@ -136,8 +122,7 @@ def perform(self, wait=False, wait_interval=5, wait_callback=None):
return job

def commit(self, wait=False, wait_interval=5, timeout=None):
"""Commit bulk import
"""
"""Commit bulk import"""
response = self._client.commit_bulk_import(self.name)
if wait:
started_at = time.time()
Expand Down Expand Up @@ -201,12 +186,16 @@ def upload_file(self, part_name, fmt, file_like, **kwargs):
The default behaviour is ``"guess"``, which makes a best-effort to decide
the column datatype. See `file import parameters`_ for more details.
.. _`file import parameters`:
https://tdclient.readthedocs.io/en/latest/file_import_parameters.html
"""
response = self._client.bulk_import_upload_file(
self.name, part_name, fmt, file_like, **kwargs,
self.name,
part_name,
fmt,
file_like,
**kwargs,
)
self.update()
return response
Expand Down
12 changes: 5 additions & 7 deletions tdclient/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@


class Client:
"""API Client for Treasure Data Service
"""
"""API Client for Treasure Data Service"""

def __init__(self, *args, **kwargs):
self._api = api.API(*args, **kwargs)
Expand Down Expand Up @@ -79,7 +78,7 @@ def database(self, db_name):
:class:`tdclient.models.Database`
"""
databases = self.api.list_databases()
for (name, kwargs) in databases.items():
for name, kwargs in databases.items():
if name == db_name:
return models.Database(self, name, **kwargs)
raise api.NotFoundError("Database '%s' does not exist" % (db_name))
Expand Down Expand Up @@ -229,7 +228,7 @@ def query(
priority=None,
retry_limit=None,
type="hive",
**kwargs
**kwargs,
):
"""Run a query on specified database table.
Expand Down Expand Up @@ -258,7 +257,7 @@ def query(
result_url=result_url,
priority=priority,
retry_limit=retry_limit,
**kwargs
**kwargs,
)
return models.Job(self, job_id, type, q)

Expand Down Expand Up @@ -927,8 +926,7 @@ def remove_apikey(self, name, apikey):
return self.api.remove_apikey(name, apikey)

def close(self):
"""Close opened API connections.
"""
"""Close opened API connections."""
return self._api.close()


Expand Down
2 changes: 1 addition & 1 deletion tdclient/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def __init__(
retry_limit=None,
wait_interval=None,
wait_callback=None,
**kwargs
**kwargs,
):
cursor_kwargs = dict()
if type is not None:
Expand Down
5 changes: 2 additions & 3 deletions tdclient/database_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@


class Database(Model):
"""Database on Treasure Data Service
"""
"""Database on Treasure Data Service"""

PERMISSIONS = ["administrator", "full_access", "import_only", "query_only"]
PERMISSION_LIST_TABLES = ["administrator", "full_access"]
Expand Down Expand Up @@ -50,7 +49,7 @@ def name(self):
str: a name of the database
"""
return self._db_name

@property
def id(self):
"""
Expand Down
16 changes: 10 additions & 6 deletions tdclient/job_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def show_job(self, job_id):
return job

def job_status(self, job_id):
""""Show job status
""" "Show job status
Args:
job_id (str): job ID
Expand Down Expand Up @@ -208,7 +208,7 @@ def job_result_format(self, job_id, format, header=False):
job_id (int): Job ID
format (str): Output format of the job result information.
"json" or "msgpack"
header (boolean): Includes Header or not.
header (boolean): Includes Header or not.
False or True
Returns:
Expand All @@ -224,7 +224,7 @@ def job_result_format_each(self, job_id, format, header=False):
Args:
job_id (int): job ID
format (str): Output format of the job result information.
format (str): Output format of the job result information.
"json" or "msgpack"
header (bool): Include Header info or not
"True" or "False"
Expand All @@ -241,8 +241,12 @@ def job_result_format_each(self, job_id, format, header=False):
format = "json"

with self.get(
create_url("/v3/job/result/{job_id}?format={format}&header={header}",
job_id=job_id, format=format, header=header)
create_url(
"/v3/job/result/{job_id}?format={format}&header={header}",
job_id=job_id,
format=format,
header=header,
)
) as res:
code = res.status
if code != 200:
Expand Down Expand Up @@ -282,7 +286,7 @@ def query(
result_url=None,
priority=None,
retry_limit=None,
**kwargs
**kwargs,
):
"""Create a job for given query.
Expand Down
Loading

0 comments on commit e68c34c

Please sign in to comment.