Skip to content

Commit

Permalink
refactor: ♻️ minor code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
newgene committed Jan 29, 2024
1 parent a758b55 commit 0452159
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
9 changes: 3 additions & 6 deletions biothings/utils/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,9 @@ def drop(self):
self.target_collection.drop()

def get_id_list(self):
try:
# Just keep this line to not break the other feature.
return [x["_id"] for x in self.target_collection.find(projection=[], manipulate=False)]
except TypeError:
# Current version of PyMongo doesn't support manipulate parameter for Cursor.find method
return [x["_id"] for x in self.target_collection.find(projection=[])]
# manipulate parameter is deprecated
# return [x["_id"] for x in self.target_collection.find(projection=[], manipulate=False)]
return [x["_id"] for x in self.target_collection.find(projection=[])]

def get_from_id(self, id):
return self.target_collection.find_one({"_id": id})
Expand Down
32 changes: 17 additions & 15 deletions biothings/utils/parallel.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,8 @@
"""
Utils for running parallel jobs on IPython cluster.
Utils for running parallel jobs.
"""
import copy
import os
import time
import warnings
from concurrent.futures import ProcessPoolExecutor

import biothings

# ipcluster expecting to be in the folder where the app config is
# because ipcluster will just import this file/module, kind of as if
# it was building a main script from this lib
import biothings.config as config

biothings.config_for_app(config)
from biothings.utils.common import ask, timesofar


def run_jobs_on_parallel(worker, task_list, executor_args=None):
"""
Expand All @@ -35,9 +21,22 @@ def run_jobs_on_parallel(worker, task_list, executor_args=None):


def run_jobs_on_ipythoncluster(worker, task_list, shutdown_ipengines_after_done=False):
import warnings
warnings.warn(DeprecationWarning("This function is deprecated! Use run_jobs_on_parallel function instead."))

import os
import time

from ipyparallel import Client
import biothings

# ipcluster expecting to be in the folder where the app config is
# because ipcluster will just import this file/module, kind of as if
# it was building a main script from this lib
import biothings.config as config

biothings.config_for_app(config)
from biothings.utils.common import ask, timesofar

t0 = time.time()
rc = Client(config.CLUSTER_CLIENT_JSON)
Expand Down Expand Up @@ -74,6 +73,9 @@ def run_jobs_on_ipythoncluster(worker, task_list, shutdown_ipengines_after_done=


def collection_partition(src_collection_list, step=100000):
"""This function is deprecated, not used anywhere"""
import copy

if not isinstance(src_collection_list, (list, tuple)):
src_collection_list = [src_collection_list]

Expand Down

0 comments on commit 0452159

Please sign in to comment.