Skip to content
Permalink
Browse files
fix: avoid superfluous calls of conda info that have slowed down Snak…
…emake since 6.4.1. (#1099)
  • Loading branch information
johanneskoester committed Jul 19, 2021
1 parent 38c4155 commit e9909273c22a316dbd7301a243498e3c2a372642
Showing 1 changed file with 19 additions and 13 deletions.
@@ -414,27 +414,33 @@ def __new__(cls, container_img=None, prefix_path=None):
with cls.lock:
if container_img not in cls.instances:
inst = super().__new__(cls)
inst.__init__(container_img=container_img, prefix_path=prefix_path)
cls.instances[container_img] = inst
inst._check()
return inst
else:
return cls.instances[container_img]

def __init__(self, container_img=None, prefix_path=None):
from snakemake.deployment import singularity
from snakemake.shell import shell
if not self.is_initialized: # avoid superfluous init calls
from snakemake.deployment import singularity
from snakemake.shell import shell

if isinstance(container_img, singularity.Image):
container_img = container_img.path
self.container_img = container_img

if prefix_path is None or container_img is not None:
self.prefix_path = json.loads(
shell.check_output(self._get_cmd("conda info --json"))
)["conda_prefix"]
else:
self.prefix_path = prefix_path

if isinstance(container_img, singularity.Image):
container_img = container_img.path
self.container_img = container_img
# check conda installation
self._check()

if prefix_path is None or container_img is not None:
self.prefix_path = json.loads(
shell.check_output(self._get_cmd("conda info --json"))
)["conda_prefix"]
else:
self.prefix_path = prefix_path
@property
def is_initialized(self):
return hasattr(self, "prefix_path")

def _get_cmd(self, cmd):
if self.container_img:

0 comments on commit e990927

Please sign in to comment.