Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaced print statements with logger calls #122

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions process_report/invoices/billable_invoice.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
from dataclasses import dataclass
import logging

import pandas
import pyarrow

from process_report.invoices import invoice

logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)


@dataclass
class BillableInvoice(invoice.Invoice):
Expand Down
13 changes: 9 additions & 4 deletions process_report/process_report.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import argparse
import sys
import datetime
import logging

import pandas
import pyarrow
Expand Down Expand Up @@ -58,6 +59,10 @@
ALIAS_S3_FILEPATH = "PIs/alias.csv"


logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)


def load_alias(alias_file):
alias_dict = dict()

Expand All @@ -67,7 +72,7 @@ def load_alias(alias_file):
pi_alias_info = line.strip().split(",")
alias_dict[pi_alias_info[0]] = pi_alias_info[1:]
except FileNotFoundError:
print("Validating PI aliases failed. Alias file does not exist")
logging.error("Validating PI aliases failed. Alias file does not exist")
sys.exit(1)

return alias_dict
Expand Down Expand Up @@ -199,11 +204,11 @@ def main():
with open(args.projects_file) as file:
projects = [line.rstrip() for line in file]

print("Invoice date: " + str(invoice_month))
logger.info("Invoice date: " + str(invoice_month))

timed_projects_list = timed_projects(args.timed_projects_file, invoice_month)
print("The following timed-projects will not be billed for this period: ")
print(timed_projects_list)
logger.info("The following timed-projects will not be billed for this period: ")
logger.info(timed_projects_list)

projects = list(set(projects + timed_projects_list))

Expand Down
9 changes: 7 additions & 2 deletions process_report/processors/add_institution_processor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from dataclasses import dataclass
import logging

import pandas

Expand All @@ -7,6 +8,10 @@
from process_report import util


logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)


@dataclass
class AddInstitutionProcessor(processor.Processor):
@staticmethod
Expand All @@ -27,7 +32,7 @@ def _get_institution_from_pi(institute_map, pi_uname):
institution_domain = institution_domain[institution_domain.find(".") + 1 :]

if institution_name == "":
print(f"Warning: PI name {pi_uname} does not match any institution!")
logger.warning(f"PI name {pi_uname} does not match any institution!")

return institution_name

Expand All @@ -49,7 +54,7 @@ def _add_institution(self):
for i, row in self.data.iterrows():
pi_name = row[invoice.PI_FIELD]
if pandas.isna(pi_name):
print(f"Project {row[invoice.PROJECT_FIELD]} has no PI")
logger.info(f"Project {row[invoice.PROJECT_FIELD]} has no PI")
else:
self.data.at[
i, invoice.INSTITUTION_FIELD
Expand Down
13 changes: 10 additions & 3 deletions process_report/processors/new_pi_credit_processor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys
import logging

from dataclasses import dataclass
import pandas
Expand All @@ -9,6 +10,10 @@
from process_report.processors import discount_processor


logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)


@dataclass
class NewPICreditProcessor(discount_processor.DiscountProcessor):
"""
Expand Down Expand Up @@ -114,7 +119,9 @@ def get_initial_credit_amount(
new_pi_credit_amount = get_initial_credit_amount(
old_pi_df, self.invoice_month, self.INITIAL_CREDIT_AMOUNT
)
print(f"New PI Credit set at {new_pi_credit_amount} for {self.invoice_month}")
logger.info(
f"New PI Credit set at {new_pi_credit_amount} for {self.invoice_month}"
)

credit_eligible_projects = self._get_credit_eligible_projects(data)
current_pi_set = set(credit_eligible_projects[invoice.PI_FIELD])
Expand Down Expand Up @@ -168,8 +175,8 @@ def get_initial_credit_amount(
if (pi_old_pi_entry[credit_used_field] != 0) and (
credits_used != pi_old_pi_entry[credit_used_field]
):
print(
f"Warning: PI file overwritten. PI {pi} previously used ${pi_old_pi_entry[credit_used_field]} of New PI credits, now uses ${credits_used}"
logger.warning(
f"PI file overwritten. PI {pi} previously used ${pi_old_pi_entry[credit_used_field]} of New PI credits, now uses ${credits_used}"
)
old_pi_df.loc[
old_pi_df[invoice.PI_PI_FIELD] == pi, credit_used_field
Expand Down
4 changes: 3 additions & 1 deletion process_report/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ def get_invoice_bucket():
aws_secret_access_key=os.environ["S3_APP_KEY"],
)
except KeyError:
print("Error: Please set the environment variables S3_KEY_ID and S3_APP_KEY")
logger.error(
"Error: Please set the environment variables S3_KEY_ID and S3_APP_KEY"
)
return s3_resource.Bucket(os.environ.get("S3_BUCKET_NAME", "nerc-invoicing"))


Expand Down
Loading