Mercurial > repos > shellac > sam_consensus_v3
comparison env/lib/python3.9/site-packages/planemo/galaxy/serve.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 serving out development Galaxy servers.""" | |
2 from __future__ import print_function | |
3 | |
4 import contextlib | |
5 import os | |
6 import time | |
7 | |
8 from planemo import ( | |
9 io, | |
10 network_util | |
11 ) | |
12 from .config import galaxy_config | |
13 from .ephemeris_sleep import sleep | |
14 from .run import ( | |
15 run_galaxy_command, | |
16 ) | |
17 INSTALLING_MESSAGE = "Installing repositories - this may take some time..." | |
18 | |
19 | |
20 def serve(ctx, runnables=None, **kwds): | |
21 if runnables is None: | |
22 runnables = [] | |
23 """Serve a Galaxy instance with artifacts defined by paths.""" | |
24 try: | |
25 return _serve(ctx, runnables, **kwds) | |
26 except Exception as e: | |
27 ctx.vlog("Problem serving Galaxy", exception=e) | |
28 raise | |
29 | |
30 | |
31 def _serve(ctx, runnables, **kwds): | |
32 engine = kwds.get("engine", "galaxy") | |
33 if engine == "docker_galaxy": | |
34 kwds["dockerize"] = True | |
35 | |
36 daemon = kwds.get("daemon", False) | |
37 if daemon: | |
38 kwds["no_cleanup"] = True | |
39 | |
40 port = kwds.get("port", None) | |
41 if port is None: | |
42 port = network_util.get_free_port() | |
43 kwds["port"] = port | |
44 | |
45 with galaxy_config(ctx, runnables, **kwds) as config: | |
46 cmd = config.startup_command(ctx, **kwds) | |
47 action = "Starting Galaxy" | |
48 exit_code = run_galaxy_command( | |
49 ctx, | |
50 cmd, | |
51 config.env, | |
52 action, | |
53 ) | |
54 if exit_code: | |
55 message = "Problem running Galaxy command [%s]." % config.log_contents | |
56 io.warn(message) | |
57 raise Exception(message) | |
58 host = kwds.get("host", "127.0.0.1") | |
59 | |
60 timeout = 500 | |
61 galaxy_url = "http://%s:%s" % (host, port) | |
62 galaxy_alive = sleep(galaxy_url, verbose=ctx.verbose, timeout=timeout) | |
63 if not galaxy_alive: | |
64 raise Exception("Attempted to serve Galaxy at %s, but it failed to start in %d seconds." % (galaxy_url, timeout)) | |
65 config.install_workflows() | |
66 if kwds.get("pid_file"): | |
67 real_pid_file = config.pid_file | |
68 if os.path.exists(config.pid_file): | |
69 os.symlink(real_pid_file, kwds["pid_file"]) | |
70 else: | |
71 io.warn("Can't find Galaxy pid file [%s] to link" % real_pid_file) | |
72 return config | |
73 | |
74 | |
75 @contextlib.contextmanager | |
76 def shed_serve(ctx, install_args_list, **kwds): | |
77 """Serve a daemon instance of Galaxy with specified repositories installed.""" | |
78 with serve_daemon(ctx, **kwds) as config: | |
79 install_deps = not kwds.get("skip_dependencies", False) | |
80 print(INSTALLING_MESSAGE) | |
81 io.info(INSTALLING_MESSAGE) | |
82 for install_args in install_args_list: | |
83 install_args["install_tool_dependencies"] = install_deps | |
84 install_args["install_repository_dependencies"] = True | |
85 install_args["new_tool_panel_section_label"] = "Shed Installs" | |
86 config.install_repo( | |
87 **install_args | |
88 ) | |
89 try: | |
90 config.wait_for_all_installed() | |
91 except Exception: | |
92 if ctx.verbose: | |
93 print("Failed to install tool repositories, Galaxy log:") | |
94 print(config.log_contents) | |
95 print("Galaxy root:") | |
96 io.shell(['ls', config.galaxy_root]) | |
97 raise | |
98 yield config | |
99 | |
100 | |
101 @contextlib.contextmanager | |
102 def serve_daemon(ctx, runnables=None, **kwds): | |
103 """Serve a daemonized Galaxy instance with artifacts defined by paths.""" | |
104 if runnables is None: | |
105 runnables = [] | |
106 config = None | |
107 try: | |
108 kwds["daemon"] = True | |
109 config = serve(ctx, runnables, **kwds) | |
110 yield config | |
111 finally: | |
112 if config: | |
113 if ctx.verbose: | |
114 print("Galaxy Log:") | |
115 print(config.log_contents) | |
116 config.kill() | |
117 if not kwds.get("no_cleanup", False): | |
118 config.cleanup() | |
119 | |
120 | |
121 def sleep_for_serve(): | |
122 # This is bad, do something better... | |
123 time.sleep(1000000) | |
124 | |
125 | |
126 __all__ = ( | |
127 "serve", | |
128 "serve_daemon", | |
129 "shed_serve", | |
130 ) |