Skip to content

Commit ef2da1e

Browse files
committed
Don't special case singularity postgres
1 parent c21fa75 commit ef2da1e

File tree

7 files changed

+56
-53
lines changed

7 files changed

+56
-53
lines changed

planemo/database/interface.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,13 @@ def list_databases(self):
2222
def sqlalchemy_url(self, identifier) -> Optional[str]:
2323
"""Return a URL string for use by sqlalchemy."""
2424

25+
def start(self):
26+
"""Start the database source, if necessary."""
27+
pass
28+
29+
def stop(self):
30+
"""Stop the database source, if necessary."""
31+
pass
32+
2533

2634
__all__ = ("DatabaseSource",)

planemo/database/postgres_docker.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,17 @@ def __init__(self, **kwds):
6363
self.database_port = DEFAULT_POSTGRES_PORT_EXPOSE
6464
self._kwds = kwds
6565
self._docker_host_kwds = dockerfiles.docker_host_args(**kwds)
66+
67+
def start(self):
6668
if not is_running_container(**self._docker_host_kwds):
6769
start_postgres_docker(**self._docker_host_kwds)
6870
# Hack to give docker a bit of time to boot up and allow psql to start.
6971
time.sleep(30)
7072

73+
def stop(self):
74+
if is_running_container(**self._docker_host_kwds):
75+
stop_postgres_docker(**self._docker_host_kwds)
76+
7177
def sqlalchemy_url(self, identifier):
7278
"""Return URL or form postgresql://username:password@localhost/mydatabase."""
7379
return "postgresql://%s:%s@%s:%d/%s" % (

planemo/database/postgres_singularity.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,23 +102,22 @@ def create_database(self, identifier):
102102
def delete_database(self, identifier):
103103
shutil.rmtree(self.database_location, ignore_errors=True)
104104

105-
def __enter__(self):
105+
def start(self):
106106
self.running_process = start_postgres_singularity(
107107
singularity_path=self.singularity_path,
108108
database_location=self.database_location,
109109
user=self.database_user,
110110
password=self.database_password,
111111
)
112-
return self
113112

114-
def __exit__(self, exc_type, exc_value, traceback):
113+
def stop(self):
115114
if self.running_process:
116115
try:
117116
self.running_process.terminate()
118117
postmaster_pid_file = os.path.join(self.database_location, "pgdata", "postmaster.pid")
119118
if os.path.exists(postmaster_pid_file):
120119
os.remove(postmaster_pid_file)
121-
postmaster_lock_file = os.path.join(self.database_location, "pgrun", "pgrun/.s.PGSQL.5432.lock")
120+
postmaster_lock_file = os.path.join(self.database_location, "pgrun", ".s.PGSQL.5432.lock")
122121
if os.path.exists(postmaster_lock_file):
123122
os.remove(postmaster_lock_file)
124123
except Exception as e:

planemo/engine/factory.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
DockerizedManagedGalaxyEngine,
1010
ExternalGalaxyEngine,
1111
LocalManagedGalaxyEngine,
12-
LocalManagedGalaxyEngineWithSingularityDB,
1312
)
1413
from .toil import ToilEngine
1514

@@ -26,10 +25,7 @@ def build_engine(ctx, **kwds):
2625
"""Build an engine from the supplied planemo configuration."""
2726
engine_type_str = kwds.get("engine", "galaxy")
2827
if engine_type_str == "galaxy":
29-
if "database_type" in kwds and kwds["database_type"] == "postgres_singularity":
30-
engine_type = LocalManagedGalaxyEngineWithSingularityDB
31-
else:
32-
engine_type = LocalManagedGalaxyEngine
28+
engine_type = LocalManagedGalaxyEngine
3329
elif engine_type_str == "docker_galaxy":
3430
engine_type = DockerizedManagedGalaxyEngine
3531
elif engine_type_str == "external_galaxy":

planemo/engine/galaxy.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from galaxy.tool_util.verify import interactor
1313

1414
from planemo import io
15-
from planemo.database.postgres_singularity import SingularityPostgresDatabaseSource
1615
from planemo.galaxy.activity import (
1716
execute,
1817
execute_rerun,
@@ -172,20 +171,6 @@ def _serve_kwds(self):
172171
return self._kwds.copy()
173172

174173

175-
class LocalManagedGalaxyEngineWithSingularityDB(LocalManagedGalaxyEngine):
176-
def run(self, runnables, job_paths, output_collectors: Optional[List[Callable]] = None):
177-
with SingularityPostgresDatabaseSource(**self._kwds.copy()) as db_source:
178-
# Get the actual database connection string from the running database
179-
database_identifier = self._kwds.get("database_identifier", "galaxy")
180-
database_connection = db_source.sqlalchemy_url(database_identifier)
181-
182-
# Update kwds with the actual database connection
183-
self._kwds["database_connection"] = database_connection
184-
185-
run_responses = super().run(runnables, job_paths, output_collectors)
186-
return run_responses
187-
188-
189174
class DockerizedManagedGalaxyEngine(LocalManagedGalaxyEngine):
190175
"""An :class:`Engine` implementation backed by Galaxy running in Docker.
191176
@@ -240,5 +225,4 @@ def expand_test_cases(config, test_cases):
240225
"DockerizedManagedGalaxyEngine",
241226
"ExternalGalaxyEngine",
242227
"LocalManagedGalaxyEngine",
243-
"LocalManagedGalaxyEngineWithSingularityDB",
244228
)

planemo/galaxy/config.py

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
from planemo import git
3939
from planemo.config import OptionSource
40+
from planemo.database import create_database_source
4041
from planemo.deps import ensure_dependency_resolvers_conf_configured
4142
from planemo.docker import docker_host_args
4243
from planemo.galaxy.workflows import (
@@ -421,7 +422,6 @@ def config_join(*args):
421422
)
422423
)
423424
_handle_container_resolution(ctx, kwds, properties)
424-
properties["database_connection"] = _database_connection(database_location, **kwds)
425425
if kwds.get("mulled_containers", False):
426426
properties["mulled_channels"] = kwds.get("conda_ensure_channels", "")
427427

@@ -444,15 +444,6 @@ def config_join(*args):
444444
# https://github.com/galaxyproject/planemo/issues/788
445445
env["GALAXY_LOG"] = log_file
446446
env["GALAXY_PID"] = pid_file
447-
write_galaxy_config(
448-
galaxy_root=galaxy_root,
449-
properties=properties,
450-
env=env,
451-
kwds=kwds,
452-
template_args=template_args,
453-
config_join=config_join,
454-
)
455-
456447
_write_tool_conf(ctx, all_tool_paths, tool_conf)
457448
write_file(empty_tool_conf, EMPTY_TOOL_CONF_TEMPLATE)
458449

@@ -461,19 +452,29 @@ def config_join(*args):
461452
write_file(shed_tool_conf, shed_tool_conf_contents, force=False)
462453

463454
write_file(shed_data_manager_config_file, SHED_DATA_MANAGER_CONF_TEMPLATE)
455+
with _database_connection(database_location, **kwds) as database_connection:
456+
properties["database_connection"] = database_connection
457+
write_galaxy_config(
458+
galaxy_root=galaxy_root,
459+
properties=properties,
460+
env=env,
461+
kwds=kwds,
462+
template_args=template_args,
463+
config_join=config_join,
464+
)
464465

465-
yield LocalGalaxyConfig(
466-
ctx,
467-
config_directory,
468-
env,
469-
test_data_dir,
470-
port,
471-
server_name,
472-
master_api_key,
473-
runnables,
474-
galaxy_root,
475-
kwds,
476-
)
466+
yield LocalGalaxyConfig(
467+
ctx,
468+
config_directory,
469+
env,
470+
test_data_dir,
471+
port,
472+
server_name,
473+
master_api_key,
474+
runnables,
475+
galaxy_root,
476+
kwds,
477+
)
477478

478479

479480
def write_galaxy_config(galaxy_root, properties, env, kwds, template_args, config_join):
@@ -1104,10 +1105,17 @@ def default_use_path_paste(self):
11041105
return self.user_is_admin
11051106

11061107

1108+
@contextlib.contextmanager
11071109
def _database_connection(database_location, **kwds):
1108-
default_connection = DATABASE_LOCATION_TEMPLATE % database_location
1109-
database_connection = kwds.get("database_connection") or default_connection
1110-
return database_connection
1110+
if kwds.get("database_type") != "sqlite":
1111+
database_source = create_database_source(**kwds)
1112+
try:
1113+
database_source.start()
1114+
yield database_source.sqlalchemy_url(kwds.get("database_identifier", "galaxy"))
1115+
finally:
1116+
database_source.stop()
1117+
else:
1118+
yield DATABASE_LOCATION_TEMPLATE % database_location
11111119

11121120

11131121
def _find_galaxy_root(ctx, **kwds):

planemo/galaxy/profiles.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def _create_profile_local(ctx, profile_directory, profile_name, kwds):
9696
else:
9797
database_type = "sqlite"
9898

99-
if database_type not in ["sqlite", "postgres_singularity"]:
99+
if database_type not in ["sqlite"]:
100100
database_source = create_database_source(**kwds)
101101
database_identifier = _profile_to_database_identifier(profile_name)
102102
try:
@@ -115,8 +115,10 @@ def _create_profile_local(ctx, profile_directory, profile_name, kwds):
115115
elif database_type == "postgres_singularity":
116116
database_connection + database_source.sqlalchemy_url(database_identifier)
117117
if database_type == "sqlite":
118-
database_location = os.path.join(profile_directory, "galaxy.sqlite")
119-
database_connection = DATABASE_LOCATION_TEMPLATE % database_location
118+
database_source.create_database(
119+
database_identifier,
120+
)
121+
database_connection = database_source.sqlalchemy_url(database_identifier)
120122

121123
return {
122124
"database_type": database_type,

0 commit comments

Comments
 (0)