From d291a9b21481f124d31c85b7309572e2bc60e85e Mon Sep 17 00:00:00 2001 From: shane knapp Date: Thu, 18 Jul 2024 12:04:47 -0700 Subject: [PATCH 1/2] fixing python linter errors --- deployments/biology/image/patches/ncbiquery.py | 12 ++++-------- deployments/data8/image/ipython_config.py | 2 +- deployments/edx/image/ipython_config.py | 2 +- images/node-placeholder-scaler/scaler/scaler.py | 8 ++++---- scripts/delete-unused-users.py | 2 +- scripts/git-pre-cloner.py | 17 ++++++++++++----- 6 files changed, 23 insertions(+), 20 deletions(-) diff --git a/deployments/biology/image/patches/ncbiquery.py b/deployments/biology/image/patches/ncbiquery.py index a0cb6a44b..161cde01b 100644 --- a/deployments/biology/image/patches/ncbiquery.py +++ b/deployments/biology/image/patches/ncbiquery.py @@ -175,7 +175,7 @@ def get_fuzzy_name_translation(self, name, sim=0.9): result = _db.execute(cmd) try: taxid, spname, score = result.fetchone() - except: + except Exception: pass else: taxid = int(taxid) @@ -299,7 +299,7 @@ def get_name_translator(self, names): query = ','.join(['"%s"' %n for n in six.iterkeys(name2origname)]) cmd = 'select spname, taxid from species where spname IN (%s)' %query - result = self.db.execute('select spname, taxid from species where spname IN (%s)' %query) + result = self.db.execute(cmd) for sp, taxid in result.fetchall(): oname = name2origname[sp.lower()] name2id.setdefault(oname, []).append(taxid) @@ -395,15 +395,12 @@ def get_topology(self, taxids, intermediate_nodes=False, rank_limit=None, collap root_taxid = int(list(taxids)[0]) with open(self.dbfile+".traverse.pkl", "rb") as CACHED_TRAVERSE: prepostorder = pickle.load(CACHED_TRAVERSE) - descendants = {} - found = 0 nodes = {} - hit = 0 visited = set() start = prepostorder.index(root_taxid) try: - end = prepostorder.index(root_taxid, start+1) - subtree = prepostorder[start:end+1] + end = prepostorder.index(root_taxid, start+1) + subtree = prepostorder[start:end+1] except ValueError: # If root taxid is not found in postorder, must be a tip node subtree = [root_taxid] @@ -663,7 +660,6 @@ def load_ncbi_tree_from_dump(tar): name2node = {} node2taxname = {} synonyms = set() - name2rank = {} node2common = {} print("Loading node names...") for line in tar.extractfile("names.dmp"): diff --git a/deployments/data8/image/ipython_config.py b/deployments/data8/image/ipython_config.py index ab5c5b8b6..a8774967b 100644 --- a/deployments/data8/image/ipython_config.py +++ b/deployments/data8/image/ipython_config.py @@ -1,3 +1,3 @@ # Disable history manager, we don't really use it # and by default it puts an sqlite file on NFS, which is not something we wanna do -c.HistoryManager.enabled = False +c.HistoryManager.enabled = False # noqa: F821 diff --git a/deployments/edx/image/ipython_config.py b/deployments/edx/image/ipython_config.py index ab5c5b8b6..a8774967b 100644 --- a/deployments/edx/image/ipython_config.py +++ b/deployments/edx/image/ipython_config.py @@ -1,3 +1,3 @@ # Disable history manager, we don't really use it # and by default it puts an sqlite file on NFS, which is not something we wanna do -c.HistoryManager.enabled = False +c.HistoryManager.enabled = False # noqa: F821 diff --git a/images/node-placeholder-scaler/scaler/scaler.py b/images/node-placeholder-scaler/scaler/scaler.py index bd49bf9a9..7bb240d09 100755 --- a/images/node-placeholder-scaler/scaler/scaler.py +++ b/images/node-placeholder-scaler/scaler/scaler.py @@ -1,6 +1,5 @@ #!/usr/bin/env python3 import logging -import datetime import argparse import tempfile import subprocess @@ -54,15 +53,16 @@ def get_replica_counts(events): pools_replica_config = None try: pools_replica_config = yaml.load(ev.description) - except: + except Exception as e: + logging.error(f"Caught unhandled exception parsing event description:\n{e}") logging.error(f"Error in parsing description of {_event_repr(ev)}") logging.error(f"{ev.description=}") pass if pools_replica_config is None: logging.error(f"No description in event {_event_repr(ev)}") continue - elif type(pools_replica_config) == str: - logging.error(f"Event description not parsed as dictionary.") + elif isinstance(pools_replica_config, str): + logging.error("Event description not parsed as dictionary.") logging.error(f"{ev.description=}") continue for pool_name, count in pools_replica_config.items(): diff --git a/scripts/delete-unused-users.py b/scripts/delete-unused-users.py index 0da572147..6922a7185 100755 --- a/scripts/delete-unused-users.py +++ b/scripts/delete-unused-users.py @@ -142,7 +142,7 @@ def main(args): and if so, delete them! """ if args.credentials and args.hub_url: - logger.error(f"Please use only one of --hub_url or --credentials options when executing the script.") + logger.error("Please use only one of --hub_url or --credentials options when executing the script.") raise if args.hub_url: diff --git a/scripts/git-pre-cloner.py b/scripts/git-pre-cloner.py index fc0f64eb4..6c13466dd 100644 --- a/scripts/git-pre-cloner.py +++ b/scripts/git-pre-cloner.py @@ -2,7 +2,6 @@ import argparse import os -import sys import string import subprocess @@ -27,6 +26,7 @@ def git_clone(): return out = subprocess.check_output(['git', 'clone', args.repo], cwd=local_repo).decode('utf-8') + return out def copy_repo(username): safe = safe_username(username) @@ -34,10 +34,14 @@ def copy_repo(username): source_dir = os.path.join(local_repo, repo_dirname) dest_dir = os.path.join(home_dir, repo_dirname) if os.path.exists(dest_dir): - if args.verbose: print('Skipping {}'.format(safe)) + if args.verbose: + print('Skipping {}'.format(safe)) else: - if args.verbose: print(safe) + if args.verbose: + print(safe) out = subprocess.check_output(['cp', '-a', source_dir, dest_dir]) + return out + return # main parser = argparse.ArgumentParser(description='Pre-clone course assets.') @@ -54,13 +58,16 @@ def copy_repo(username): if not os.path.exists(local_repo): os.mkdir(local_repo) -git_clone() +out = git_clone() +if args.verbose: + print(out) f = open(args.filename) line = f.readline() while line != '': email = line.strip() - if '@berkeley.edu' not in email: continue # just in case + if '@berkeley.edu' not in email: + continue # just in case username = email.split('@')[0] copy_repo(username) line = f.readline() From b4366cbdebf182ccf131a866cd9ba990019d287a Mon Sep 17 00:00:00 2001 From: shane knapp Date: Thu, 18 Jul 2024 12:14:09 -0700 Subject: [PATCH 2/2] fix space/tab drama --- deployments/biology/image/patches/ncbiquery.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/deployments/biology/image/patches/ncbiquery.py b/deployments/biology/image/patches/ncbiquery.py index 161cde01b..5a2192d04 100644 --- a/deployments/biology/image/patches/ncbiquery.py +++ b/deployments/biology/image/patches/ncbiquery.py @@ -403,7 +403,8 @@ def get_topology(self, taxids, intermediate_nodes=False, rank_limit=None, collap subtree = prepostorder[start:end+1] except ValueError: # If root taxid is not found in postorder, must be a tip node - subtree = [root_taxid] + subtree = [root_taxid] + leaves = set([v for v, count in Counter(subtree).items() if count == 1]) nodes[root_taxid] = PhyloTree(name=str(root_taxid)) current_parent = nodes[root_taxid]