Skip to content
This repository has been archived by the owner on Mar 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #39 from d33bs/main
Browse files Browse the repository at this point in the history
Address logging string formatting and consistency
  • Loading branch information
d33bs authored Feb 21, 2022
2 parents 60b2ea6 + df2d459 commit 3b4fe0e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# This call to setup() does all the work
setuptools.setup(
name="cupyopt",
version="0.15.13.1",
version="0.15.13.2",
description="CU Python Opinionated Prefect Tasks",
long_description=README,
long_description_content_type="text/x-rst",
Expand Down
21 changes: 12 additions & 9 deletions src/cupyopt/objectstore_tasks.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
""" object store functions """

import logging
import os
from typing import Any
from typing_extensions import Literal
Expand Down Expand Up @@ -33,7 +32,7 @@ def run(
self, config_box: Box, http_client: urllib3.poolmanager.PoolManager = None
) -> Minio:

logging.info(
self.logger.info(
"Creating object store client for endpoint %s.", config_box.endpoint
)
client = Minio(
Expand Down Expand Up @@ -62,9 +61,11 @@ def run(self, client: Minio, bucket_name: str):
# make bucket if not exists
if not client.bucket_exists(bucket_name):
client.make_bucket(bucket_name)
logging.info("Created bucket %s", bucket_name)
self.logger.info("Created bucket %s", bucket_name)
else:
logging.info("Bucket %s already exists, taking no actions.", bucket_name)
self.logger.info(
"Bucket %s already exists, taking no actions.", bucket_name
)


class ObjstrPut(Task):
Expand Down Expand Up @@ -117,7 +118,7 @@ def run(
part_size=part_size,
)

logging.info("Put data under %s as %s", bucket_name, object_name)
self.logger.info("Put data under %s as %s", bucket_name, object_name)


class ObjstrGet(Task):
Expand Down Expand Up @@ -149,7 +150,7 @@ def run(self, client: Minio, bucket_name: str, object_name: str) -> Any:
object_name=object_name,
)

logging.info(
self.logger.info(
"Retrieved object %s under %s",
object_name,
bucket_name,
Expand Down Expand Up @@ -191,7 +192,7 @@ def run(
object_name=object_name,
)

logging.info(
self.logger.info(
"Retrieved object %s under %s",
object_name,
bucket_name,
Expand Down Expand Up @@ -244,7 +245,9 @@ def run(
file_path=file_path,
)

logging.info("Put file %s under %s as %s", file_path, bucket_name, object_name)
self.logger.info(
"Put file %s under %s as %s", file_path, bucket_name, object_name
)


class ObjstrFGet(Task):
Expand Down Expand Up @@ -277,7 +280,7 @@ def run(
file_path=file_path,
)

logging.info(
self.logger.info(
"Retrieved object %s under %s as file %s",
object_name,
bucket_name,
Expand Down
18 changes: 9 additions & 9 deletions src/cupyopt/sftp_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def run(
tempfolderpath = data.parameters["cache"]

localtmpfile = os.path.join(tempfolderpath, workfile)
self.logger.debug("Working on {}", os.path.join(tempfolderpath, workfile))
self.logger.debug("Working on %s", os.path.join(tempfolderpath, workfile))

if config_box.get("private_key_path"):
private_key = config_box["private_key_path"]
Expand Down Expand Up @@ -136,7 +136,7 @@ def run(
finally:
sftp.close()

self.logger.info("SFTPGet {}", localtmpfile)
self.logger.info("SFTPGet %s", localtmpfile)

return localtmpfile

Expand Down Expand Up @@ -202,7 +202,7 @@ def run(
finally:
sftp.close()

self.logger.info("SFTPPut {}", workfile)
self.logger.info("SFTPPut %s", workfile)


class SFTPRemove(Task):
Expand All @@ -222,7 +222,7 @@ def run(
):
with prefect.context(**format_kwargs) as data:

self.logger.debug("Attempting to remove ", workfile)
self.logger.debug("Attempting to remove %s", workfile)

if data.get("parameters"):
if data.parameters.get("cnopts"):
Expand Down Expand Up @@ -264,7 +264,7 @@ def run(
sftp.close()

# Read the file into a dataframe
self.logger.info("SFTPRemove {}", workfile)
self.logger.info("SFTPRemove %s", workfile)


class SFTPRename(Task):
Expand Down Expand Up @@ -330,7 +330,7 @@ def run(
filename = os.path.basename(remotesourcepath)

self.logger.debug(
"Moving {} from {} to {}", filename, remotesourcepath, remotetargetpath
"Moving %s from %s to %s", filename, remotesourcepath, remotetargetpath
)

# Move the file from source to target on the SFTP
Expand All @@ -341,7 +341,7 @@ def run(
# Working in notebooks you might have already
# moved the file in another block
self.logger.warning(
"The file {} isn't in the remote folder.",
"The file %s isn't in the remote folder.",
os.path.join(remotesourcepath, filename),
)
else:
Expand Down Expand Up @@ -429,7 +429,7 @@ def run(

files_df = pd.DataFrame(files_data, columns=["File Name", "MTime"])

self.logger.info("Found {} files to process.", len(files_df.index))
self.logger.info("Found %s files to process.", len(files_df.index))
return files_df


Expand Down Expand Up @@ -467,5 +467,5 @@ def run(self, files_df: pd.DataFrame, regex_search: str) -> str:

# Fetch the oldest file from the frame and bring it to a local temp file.
workfile = files_df.iloc[0]["File Name"]
self.logger.info("Found oldest file, {}", workfile)
self.logger.info("Found oldest file, %s", workfile)
return workfile

0 comments on commit 3b4fe0e

Please sign in to comment.