Skip to content

Commit

Permalink
fix(pain001): ✅ fixed linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienrousseau committed May 19, 2024
1 parent 50039df commit cb3892a
Show file tree
Hide file tree
Showing 25 changed files with 197 additions and 366 deletions.
5 changes: 5 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[flake8]
ignore = E203, E266, E501, W503, F403, F401
max-line-length = 79
max-complexity = 18
exclude = tests/*
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,13 @@ tests/data/valid_data.csv
tests/data/invalid_data.db
tests/data/valid_data.db
tests/data/unsupported_data_type.txt
tests/data/empty_unique.csv
tests/data/invalid_data_unique.csv
tests/data/invalid_data_unique.db
tests/data/single_column_unique.csv
tests/data/single_row_unique.csv
tests/data/template_unique.xml
tests/data/template_unique.xsd
tests/data/unsupported_data_type_unique.txt
tests/data/valid_data_unique.csv
tests/data/valid_data_unique.db
24 changes: 6 additions & 18 deletions pain001/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@
"""
title = "Pain001"

table = Table(
box=box.ROUNDED, safe_box=True, show_header=False, title=title
)
table = Table(box=box.ROUNDED, safe_box=True, show_header=False, title=title)

table.add_column(justify="center", no_wrap=False, vertical="middle")
table.add_row(description)
Expand All @@ -57,9 +55,7 @@


@click.command(
help=(
"To use Pain001, you must specify the following options:\n\n"
),
help=("To use Pain001, you must specify the following options:\n\n"),
context_settings=dict(help_option_names=["-h", "--help"]),
)
@click.option(
Expand Down Expand Up @@ -119,12 +115,8 @@ def main(

# Check that the XML message type is valid
if xml_message_type not in valid_xml_types:
logger.info(
f"Invalid XML message type: {xml_message_type}."
)
console.print(
f"Invalid XML message type: {xml_message_type}."
)
logger.info(f"Invalid XML message type: {xml_message_type}.")
console.print(f"Invalid XML message type: {xml_message_type}.")
sys.exit(1)

if not os.path.isfile(xml_template_file_path):
Expand Down Expand Up @@ -154,12 +146,8 @@ def main(
sys.exit(1)

if not os.path.isfile(data_file_path):
logger.info(
f"The data file '{data_file_path}' does not exist."
)
console.print(
f"The data file '{data_file_path}' does not exist."
)
logger.info(f"The data file '{data_file_path}' does not exist.")
console.print(f"The data file '{data_file_path}' does not exist.")
sys.exit(1)

process_files(
Expand Down
4 changes: 1 addition & 3 deletions pain001/context/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ def set_log_level(self, log_level):
"CRITICAL": logging.CRITICAL,
}

if isinstance(
log_level, int
): # Check if log_level is an integer
if isinstance(log_level, int): # Check if log_level is an integer
if log_level in valid_log_levels.values():
self.log_level = log_level
else:
Expand Down
4 changes: 1 addition & 3 deletions pain001/core/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,7 @@ def process_files(

# Check if the data file exists
if not os.path.exists(data_file_path):
error_message = (
f"Error: Data file '{data_file_path}' does not exist."
)
error_message = f"Error: Data file '{data_file_path}' does not exist."
logger.error(error_message)
raise FileNotFoundError(error_message)

Expand Down
4 changes: 1 addition & 3 deletions pain001/csv/load_csv_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
import csv
import logging

logging.basicConfig(
level=logging.ERROR, format="%(levelname)s: %(message)s"
)
logging.basicConfig(level=logging.ERROR, format="%(levelname)s: %(message)s")


def load_csv_data(file_path):
Expand Down
7 changes: 2 additions & 5 deletions pain001/csv/validate_csv_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,7 @@ def validate_csv_data(data):
value = value[:-1] + "+00:00"
datetime.datetime.fromisoformat(value)
except ValueError:
datetime.datetime.strptime(
value, "%Y-%m-%d"
)
datetime.datetime.strptime(value, "%Y-%m-%d")
else:
str(value)
except ValueError:
Expand All @@ -125,8 +123,7 @@ def validate_csv_data(data):
)
if invalid_columns:
expected_types = [
required_columns[col].__name__
for col in invalid_columns
required_columns[col].__name__ for col in invalid_columns
]
print(
f"Error: Invalid data type for column(s) {invalid_columns}, "
Expand Down
12 changes: 3 additions & 9 deletions pain001/xml/create_xml_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ def create_xml_v3(root, data):
env = Environment(loader=FileSystemLoader("."), autoescape=True)

# Load the Jinja2 template for the pain.001.001.03 schema
template = env.get_template(
"templates/pain.001.001.03/template.xml"
)
template = env.get_template("templates/pain.001.001.03/template.xml")

# Prepare the data dictionary for rendering through the Jinja2 template
# This dictionary is a reformatted version of the `data` parameter, made to
Expand All @@ -71,9 +69,7 @@ def create_xml_v3(root, data):
"nb_of_txs": data[0]["nb_of_txs"],
"initiator_name": data[0]["initiator_name"],
"initiator_street_name": data[0]["initiator_street_name"],
"initiator_building_number": data[0][
"initiator_building_number"
],
"initiator_building_number": data[0]["initiator_building_number"],
"initiator_postal_code": data[0]["initiator_postal_code"],
"initiator_town_name": data[0]["initiator_town_name"],
"initiator_country_code": data[0]["initiator_country_code"],
Expand All @@ -99,9 +95,7 @@ def create_xml_v3(root, data):
"creditor_agent_BIC": row["creditor_agent_BIC"],
"creditor_name": row["creditor_name"],
"creditor_street_name": row["creditor_street_name"],
"creditor_building_number": row[
"creditor_building_number"
],
"creditor_building_number": row["creditor_building_number"],
"creditor_postal_code": row["creditor_postal_code"],
"creditor_town_name": row["creditor_town_name"],
"creditor_country_code": row["creditor_country_code"],
Expand Down
12 changes: 3 additions & 9 deletions pain001/xml/create_xml_v4.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ def create_xml_v4(root, data):
env = Environment(loader=FileSystemLoader("."), autoescape=True)

# Load the Jinja2 template
template = env.get_template(
"templates/pain.001.001.04/template.xml"
)
template = env.get_template("templates/pain.001.001.04/template.xml")

# Prepare the data for rendering
xml_data_pain001_001_04 = {
Expand All @@ -62,9 +60,7 @@ def create_xml_v4(root, data):
"nb_of_txs": data[0]["nb_of_txs"],
"initiator_name": data[0]["initiator_name"],
"initiator_street": data[0]["initiator_street"],
"initiator_building_number": data[0][
"initiator_building_number"
],
"initiator_building_number": data[0]["initiator_building_number"],
"initiator_postal_code": data[0]["initiator_postal_code"],
"initiator_town": data[0]["initiator_town"],
"initiator_country": data[0]["initiator_country"],
Expand Down Expand Up @@ -105,9 +101,7 @@ def create_xml_v4(root, data):
"creditor_agent_BIC": row["creditor_agent_BIC"],
"creditor_name": row["creditor_name"],
"creditor_street": row["creditor_street"],
"creditor_building_number": row[
"creditor_building_number"
],
"creditor_building_number": row["creditor_building_number"],
"creditor_postal_code": row["creditor_postal_code"],
"creditor_town": row["creditor_town"],
"creditor_account_IBAN": row["creditor_account_IBAN"],
Expand Down
8 changes: 2 additions & 6 deletions pain001/xml/create_xml_v5.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ def create_xml_v5(root, data):
env = Environment(loader=FileSystemLoader("."), autoescape=True)

# Load the Jinja2 template
template = env.get_template(
"templates/pain.001.001.05/template.xml"
)
template = env.get_template("templates/pain.001.001.05/template.xml")

# Prepare the data for rendering
xml_data_pain001_001_05 = {
Expand All @@ -62,9 +60,7 @@ def create_xml_v5(root, data):
"ctrl_sum": data[0]["ctrl_sum"],
"initiator_name": data[0]["initiator_name"],
"initiator_street_name": data[0]["initiator_street_name"],
"initiator_building_number": data[0][
"initiator_building_number"
],
"initiator_building_number": data[0]["initiator_building_number"],
"initiator_postal_code": data[0]["initiator_postal_code"],
"initiator_town": data[0]["initiator_town_name"],
"initiator_country": data[0]["initiator_country"],
Expand Down
8 changes: 2 additions & 6 deletions pain001/xml/create_xml_v6.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ def create_xml_v6(root, data):
env = Environment(loader=FileSystemLoader("."), autoescape=True)

# Load pain.001.001.06 template
template = env.get_template(
"templates/pain.001.001.06/template.xml"
)
template = env.get_template("templates/pain.001.001.06/template.xml")

# Prepare data for rendering
xml_data = {
Expand All @@ -60,9 +58,7 @@ def create_xml_v6(root, data):
"ctrl_sum": data[0]["ctrl_sum"],
"initiator_name": data[0]["initiator_name"],
"initiator_street_name": data[0]["initiator_street_name"],
"initiator_building_number": data[0][
"initiator_building_number"
],
"initiator_building_number": data[0]["initiator_building_number"],
"initiator_postal_code": data[0]["initiator_postal_code"],
"initiator_town": data[0]["initiator_town_name"],
"initiator_country": data[0]["initiator_country"],
Expand Down
8 changes: 2 additions & 6 deletions pain001/xml/create_xml_v7.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ def create_xml_v7(root, data):
env = Environment(loader=FileSystemLoader("."), autoescape=True)

# Load pain.001.001.07 template
template = env.get_template(
"templates/pain.001.001.07/template.xml"
)
template = env.get_template("templates/pain.001.001.07/template.xml")

# Prepare data for rendering
xml_data = {
Expand All @@ -60,9 +58,7 @@ def create_xml_v7(root, data):
"ctrl_sum": data[0]["ctrl_sum"],
"initiator_name": data[0]["initiator_name"],
"initiator_street_name": data[0]["initiator_street_name"],
"initiator_building_number": data[0][
"initiator_building_number"
],
"initiator_building_number": data[0]["initiator_building_number"],
"initiator_postal_code": data[0]["initiator_postal_code"],
"initiator_town": data[0]["initiator_town_name"],
"initiator_country": data[0]["initiator_country"],
Expand Down
8 changes: 2 additions & 6 deletions pain001/xml/create_xml_v8.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ def create_xml_v8(root, data):
env = Environment(loader=FileSystemLoader("."), autoescape=True)

# Load pain.001.001.08 template
template = env.get_template(
"templates/pain.001.001.08/template.xml"
)
template = env.get_template("templates/pain.001.001.08/template.xml")

# Prepare data for rendering
xml_data = {
Expand All @@ -60,9 +58,7 @@ def create_xml_v8(root, data):
"ctrl_sum": data[0]["ctrl_sum"],
"initiator_name": data[0]["initiator_name"],
"initiator_street_name": data[0]["initiator_street_name"],
"initiator_building_number": data[0][
"initiator_building_number"
],
"initiator_building_number": data[0]["initiator_building_number"],
"initiator_postal_code": data[0]["initiator_postal_code"],
"initiator_town": data[0]["initiator_town_name"],
"initiator_country": data[0]["initiator_country"],
Expand Down
12 changes: 3 additions & 9 deletions pain001/xml/create_xml_v9.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ def create_xml_v9(root, data):
env = Environment(loader=FileSystemLoader("."), autoescape=True)

# Load the Jinja2 template
template = env.get_template(
"templates/pain.001.001.09/template.xml"
)
template = env.get_template("templates/pain.001.001.09/template.xml")

# Prepare the data
xml_data_pain001_001_09 = {
Expand All @@ -65,9 +63,7 @@ def create_xml_v9(root, data):
"payment_id": row["payment_id"],
"payment_method": row["payment_method"],
"payment_nb_of_txs": row["nb_of_txs"],
"requested_execution_date": row[
"requested_execution_date"
],
"requested_execution_date": row["requested_execution_date"],
"debtor_name": row["debtor_name"],
"debtor_account_IBAN": row["debtor_account_IBAN"],
"debtor_agent_BIC": row["debtor_agent_BIC"],
Expand All @@ -79,9 +75,7 @@ def create_xml_v9(root, data):
"payment_currency": row["currency"],
"cdtr_agent_BICFI": row["creditor_agent_BIC"],
"creditor_name": row["creditor_name"],
"cdtr_account_IBAN": row[
"creditor_account_IBAN"
],
"cdtr_account_IBAN": row["creditor_account_IBAN"],
"remittance_information": row[
"remittance_information"
],
Expand Down
Loading

0 comments on commit cb3892a

Please sign in to comment.