Skip to content

Commit

Permalink
Merge pull request #5880 from shaneknapp/fix-python-linting
Browse files Browse the repository at this point in the history
[DH-227] fixing python linter errors
  • Loading branch information
shaneknapp authored Jul 18, 2024
2 parents 4024b64 + b4366cb commit dd9cb29
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 21 deletions.
15 changes: 6 additions & 9 deletions deployments/biology/image/patches/ncbiquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -395,18 +395,16 @@ 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]
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]
Expand Down Expand Up @@ -663,7 +661,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"):
Expand Down
2 changes: 1 addition & 1 deletion deployments/data8/image/ipython_config.py
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion deployments/edx/image/ipython_config.py
Original file line number Diff line number Diff line change
@@ -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
8 changes: 4 additions & 4 deletions images/node-placeholder-scaler/scaler/scaler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python3
import logging
import datetime
import argparse
import tempfile
import subprocess
Expand Down Expand Up @@ -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():
Expand Down
2 changes: 1 addition & 1 deletion scripts/delete-unused-users.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
17 changes: 12 additions & 5 deletions scripts/git-pre-cloner.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import argparse
import os
import sys
import string
import subprocess

Expand All @@ -27,17 +26,22 @@ 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)
home_dir = home_directory(safe)
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.')
Expand All @@ -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()
Expand Down

0 comments on commit dd9cb29

Please sign in to comment.