comparison env/lib/python3.9/site-packages/galaxy/tool_util/deps/installable.py @ 0:4f3585e2f14b draft default tip

"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author shellac
date Mon, 22 Mar 2021 18:12:50 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4f3585e2f14b
1 """Abstractions for installing local software managed and required by Galaxy/galaxy-lib."""
2
3 import logging
4 import os
5 from abc import (
6 ABCMeta,
7 abstractmethod,
8 abstractproperty,
9 )
10
11
12 from galaxy.util.filelock import (
13 FileLock,
14 FileLockException
15 )
16
17 log = logging.getLogger(__name__)
18
19
20 class InstallableContext(metaclass=ABCMeta):
21 """Represent a directory/configuration of something that can be installed."""
22
23 @abstractmethod
24 def is_installed(self):
25 """Return bool indicating if the configured software is installed."""
26
27 @abstractmethod
28 def can_install(self):
29 """Check preconditions for installation."""
30
31 @abstractproperty
32 def installable_description(self):
33 """Short description of thing being installed for log statements."""
34
35 @abstractproperty
36 def parent_path(self):
37 """Return parent path of the location the installable will be created within."""
38
39
40 def ensure_installed(installable_context, install_func, auto_init):
41 """Make sure target is installed - handle multiple processes potentially attempting installation."""
42 parent_path = installable_context.parent_path
43 desc = installable_context.installable_description
44
45 def _check():
46 if not installable_context.is_installed():
47 if auto_init:
48 if installable_context.can_install():
49 if install_func(installable_context):
50 installed = False
51 log.warning("%s installation requested and failed." % desc)
52 else:
53 installed = installable_context.is_installed()
54 if not installed:
55 log.warning("%s installation requested, seemed to succeed, but not found." % desc)
56 else:
57 installed = False
58 else:
59 installed = False
60 log.warning("%s not installed and auto-installation disabled.", desc)
61 else:
62 installed = True
63 return installed
64
65 if not os.path.lexists(parent_path):
66 os.mkdir(parent_path)
67
68 try:
69 if auto_init and os.access(parent_path, os.W_OK):
70 with FileLock(os.path.join(parent_path, desc.lower()), timeout=300):
71 return _check()
72 else:
73 return _check()
74 except FileLockException:
75 raise Exception("Failed to get file lock for %s" % os.path.join(parent_path, desc.lower()))