Skip to content

Commit

Permalink
fixes for pylint8 and flake8
Browse files Browse the repository at this point in the history
  • Loading branch information
James Wood authored and James Wood committed Oct 14, 2024
1 parent 93962c9 commit 5e7e3c6
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
10 changes: 4 additions & 6 deletions podaac/hitide_backfill_tool/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import copy
import json
from datetime import datetime, timezone
import requests
import traceback
import requests

from podaac.hitide_backfill_tool.cmr.search import GranuleSearch
from podaac.hitide_backfill_tool.cmr.cmr_granule import CmrGranule
Expand Down Expand Up @@ -124,8 +124,7 @@ class Backfiller:
# Disable broad-except since many types of error indicate the absense
# of data when attempting access (e.g. TypeError, IndexError, KeyError, ...)
# pylint: disable=broad-except

# pylint: disable=too-many-instance-attributes,too-many-arguments
# pylint: disable=too-many-instance-attributes,too-many-arguments,too-many-positional-arguments

def __init__(self, search, message_writer, message_senders, granule_options, logger,
message_limit, cli_execution_id, s3, collection, granule_list_file):
Expand Down Expand Up @@ -190,10 +189,9 @@ def __init__(self, search, message_writer, message_senders, granule_options, log
def read_granule_list_file(self):
"""read the self.granule_list_file and store the granule list in self.granule_list"""

with open(self.granule_list_file, 'r') as file:
with open(self.granule_list_file, 'r', encoding='utf-8') as file:
self.granule_list = [line.strip() for line in file]


def process_granules(self):
"""Loop through granules (in parallel) from granule-search and call the process_one_granule() method."""

Expand All @@ -202,7 +200,7 @@ def process_granules(self):
granules = self.search.get_granules_from_list(self.granule_list)

with ThreadPoolExecutor() as executor:
executor.map(self.process_one_granule, granules)
executor.map(self.process_one_granule, granules)
print("done.")
else:
while self.search.get_next_page():
Expand Down
2 changes: 1 addition & 1 deletion podaac/hitide_backfill_tool/cmr/cmr_granule.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class CmrGranule:
# of data when attempting access (e.g. TypeError, IndexError, KeyError, ...)
# pylint: disable=broad-except

# pylint: disable=too-many-instance-attributes
# pylint: disable=too-many-instance-attributes,too-many-positional-arguments
# pylint: disable-next=too-many-arguments
def __init__(self,
umm_granule,
Expand Down
14 changes: 8 additions & 6 deletions podaac/hitide_backfill_tool/cmr/search.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Search for CMR granules"""

# pylint: disable=line-too-long

from concurrent.futures import ThreadPoolExecutor
import ast
import json
Expand All @@ -15,7 +17,7 @@
class GranuleSearch:
"""Searches for CMR granules, with paging"""

# pylint: disable=too-many-instance-attributes,too-many-arguments,too-many-locals
# pylint: disable=too-many-instance-attributes,too-many-arguments,too-many-locals,too-many-positional-arguments

def __init__(self,
base_url,
Expand Down Expand Up @@ -198,7 +200,7 @@ def get_one_granule(self, granule_name):
"""Request a single granule from CMR using granule_name or concept_id"""

url = f"{self._base_url}/search/granules.umm_json?"

# Regex for granule concept id
pattern = r"^G\d{10}-"
url += (f"concept_id={granule_name}" if re.match(pattern, granule_name) else
Expand Down Expand Up @@ -239,7 +241,8 @@ def get_one_granule(self, granule_name):

def get_granules_from_list(self, granule_list):
"""Iterate through granule_list, get cmr for each item in parallel, and return a list of umm granule json"""


# pylint: disable=broad-except
def safe_get_granule(granule_name):
"""Safely get one granule, catching exceptions"""
try:
Expand All @@ -248,12 +251,11 @@ def safe_get_granule(granule_name):
return None

with ThreadPoolExecutor() as executor:
granules = list(executor.map(lambda granule_name:
safe_get_granule(granule_name), granule_list))
granules = list(executor.map(safe_get_granule, granule_list))

# Filter out any None values due to exceptions
return [granule for granule in granules if granule is not None]

#
# Helpers
#
Expand Down
2 changes: 1 addition & 1 deletion podaac/hitide_backfill_tool/cnm_message_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class CnmMessageWriter:
"""Creates a Cumulus CNM message from granule."""

# pylint: disable=too-many-instance-attributes,too-many-arguments
# pylint: disable=too-many-instance-attributes,too-many-arguments,too-many-positional-arguments

def __init__(self,
message_config,
Expand Down
2 changes: 1 addition & 1 deletion podaac/hitide_backfill_tool/config_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def create_defaults(env):
"aws_profile": "ngap-services-sit"
}

raise f"create_defaults({env}) - env must be ops | uat | sit"
raise Exception(f"create_defaults({env}) - env must be ops | uat | sit")


def create_config(args=None):
Expand Down

0 comments on commit 5e7e3c6

Please sign in to comment.