Skip to content

Commit 408ba7c

Browse files
committed
style: make black, flake8 and isort happy
1 parent 9160232 commit 408ba7c

File tree

4 files changed

+55
-49
lines changed

4 files changed

+55
-49
lines changed

planemo/database/postgres_singularity.py

Lines changed: 51 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,13 @@
33
import os
44
import subprocess
55
import time
6+
from tempfile import mkdtemp
67

7-
from galaxy.tool_util.deps import (
8-
singularity_util,
9-
)
108
from galaxy.util.commands import execute
119

10+
from planemo.io import info
1211
from .interface import DatabaseSource
13-
from tempfile import mkdtemp
14-
from planemo.io import (
15-
info,
16-
)
17-
from .postgres import (
18-
ExecutesPostgresSqlMixin,
19-
)
20-
12+
from .postgres import ExecutesPostgresSqlMixin
2113

2214
DEFAULT_CONTAINER_NAME = "planemopostgres"
2315
DEFAULT_POSTGRES_DATABASE_NAME = "galaxy"
@@ -27,43 +19,53 @@
2719
DEFAULT_DOCKERIMAGE = "postgres:14.2-alpine3.15"
2820
DEFAULT_SIF_NAME = "postgres_14_2-alpine3_15.sif"
2921

30-
DEFAULT_CONNECTION_STRING = f"postgresql://{DEFAULT_POSTGRES_USER}:{DEFAULT_POSTGRES_PASSWORD}@localhost:{DEFAULT_POSTGRES_PORT_EXPOSE}/{DEFAULT_POSTGRES_DATABASE_NAME}"
22+
DEFAULT_CONNECTION_STRING = f"postgresql://{DEFAULT_POSTGRES_USER}:{DEFAULT_POSTGRES_PASSWORD}@localhost:{DEFAULT_POSTGRES_PORT_EXPOSE}/{DEFAULT_POSTGRES_DATABASE_NAME}"
3123

3224

3325
def start_postgres_singularity(
34-
singularity_path, container_instance_name, database_location, databasename=DEFAULT_POSTGRES_DATABASE_NAME, user=DEFAULT_POSTGRES_USER, password=DEFAULT_POSTGRES_PASSWORD, **kwds
26+
singularity_path,
27+
container_instance_name,
28+
database_location,
29+
databasename=DEFAULT_POSTGRES_DATABASE_NAME,
30+
user=DEFAULT_POSTGRES_USER,
31+
password=DEFAULT_POSTGRES_PASSWORD,
32+
**kwds,
3533
):
3634
info(f"Postgres database stored at: {database_location}")
37-
pgdata_path = os.path.join(database_location, 'pgdata')
38-
pgrun_path = os.path.join(database_location, 'pgrun')
35+
pgdata_path = os.path.join(database_location, "pgdata")
36+
pgrun_path = os.path.join(database_location, "pgrun")
3937

4038
if not os.path.exists(pgdata_path):
4139
os.makedirs(pgdata_path)
4240
if not os.path.exists(pgrun_path):
4341
os.makedirs(pgrun_path)
4442

45-
version_file = os.path.join(pgdata_path, 'PG_VERSION')
43+
version_file = os.path.join(pgdata_path, "PG_VERSION")
4644
if not os.path.exists(version_file):
4745
# Run container for a short while to initialize the database
4846
# The database will not be initilizaed during a
49-
# 'singularity instance start' command
47+
# "singularity instance start" command
5048
init_database_command = [
5149
singularity_path,
52-
'run',
53-
'-B', f'{pgdata_path}:/var/lib/postgresql/data',
54-
'-B', f'{pgrun_path}:/var/run/postgresql',
55-
'-e',
56-
'-C',
57-
'--env', f'POSTGRES_DB={databasename}',
58-
'--env', f'POSTGRES_USER={user}',
59-
'--env', f'POSTGRES_PASSWORD={password}',
60-
'--env', 'POSTGRES_INITDB_ARGS=\'--encoding=UTF-8\'',
50+
"run",
51+
"-B",
52+
f"{pgdata_path}:/var/lib/postgresql/data",
53+
"-B",
54+
f"{pgrun_path}:/var/run/postgresql",
55+
"-e",
56+
"-C",
57+
"--env",
58+
f"POSTGRES_DB={databasename}",
59+
"--env",
60+
f"POSTGRES_USER={user}",
61+
"--env",
62+
f"POSTGRES_PASSWORD={password}",
63+
"--env",
64+
"POSTGRES_INITDB_ARGS='--encoding=UTF-8'",
6165
f"docker://{DEFAULT_DOCKERIMAGE}",
6266
]
6367
info(f"Initilizing postgres database in folder: {pgdata_path}")
64-
process = subprocess.Popen(init_database_command,
65-
stdout=subprocess.PIPE,
66-
stderr=subprocess.PIPE)
68+
process = subprocess.Popen(init_database_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
6769
# Give the container time to initialize the database
6870
for _ in range(10):
6971
if os.path.exists(version_file):
@@ -80,12 +82,14 @@ def start_postgres_singularity(
8082
# when starting a instance of the container.
8183
run_command = [
8284
singularity_path,
83-
'instance',
84-
'start',
85-
'-B', f'{pgdata_path}:/var/lib/postgresql/data',
86-
'-B', f'{pgrun_path}:/var/run/postgresql',
87-
'-e',
88-
'-C',
85+
"instance",
86+
"start",
87+
"-B",
88+
f"{pgdata_path}:/var/lib/postgresql/data",
89+
"-B",
90+
f"{pgrun_path}:/var/run/postgresql",
91+
"-e",
92+
"-C",
8993
f"docker://{DEFAULT_DOCKERIMAGE}",
9094
container_instance_name,
9195
]
@@ -112,20 +116,22 @@ def __init__(self, **kwds):
112116
self.database_password = DEFAULT_POSTGRES_PASSWORD
113117
self.database_host = "localhost" # TODO: Make docker host
114118
self.database_port = DEFAULT_POSTGRES_PORT_EXPOSE
115-
if 'postgres_storage_location' in kwds and kwds['postgres_storage_location'] is not None:
116-
self.database_location = kwds['postgres_storage_location']
119+
if "postgres_storage_location" in kwds and kwds["postgres_storage_location"] is not None:
120+
self.database_location = kwds["postgres_storage_location"]
117121
else:
118-
self.database_location = os.path.join(mkdtemp(suffix='_planemo_postgres_db'))
119-
self.container_instance_name = f'{DEFAULT_CONTAINER_NAME}-{int(time.time()*1000000)}'
122+
self.database_location = os.path.join(mkdtemp(suffix="_planemo_postgres_db"))
123+
self.container_instance_name = f"{DEFAULT_CONTAINER_NAME} - {int(time.time()*1000000)}"
120124
self._kwds = kwds
121125

122126
def __enter__(self):
123-
start_postgres_singularity(singularity_path=self.singularity_path,
124-
database_location=self.database_location,
125-
user=self.database_user,
126-
password=self.database_password,
127-
container_instance_name=self.container_instance_name,
128-
**self._kwds)
127+
start_postgres_singularity(
128+
singularity_path=self.singularity_path,
129+
database_location=self.database_location,
130+
user=self.database_user,
131+
password=self.database_password,
132+
container_instance_name=self.container_instance_name,
133+
**self._kwds,
134+
)
129135

130136
def __exit__(self, exc_type, exc_value, traceback):
131137
stop_postgress_singularity(self.container_instance_name)

planemo/engine/factory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def build_engine(ctx, **kwds):
2626
"""Build an engine from the supplied planemo configuration."""
2727
engine_type_str = kwds.get("engine", "galaxy")
2828
if engine_type_str == "galaxy":
29-
if 'database_type' in kwds and kwds['database_type'] == 'postgres_singularity':
29+
if "database_type" in kwds and kwds["database_type"] == "postgres_singularity":
3030
engine_type = LocalManagedGalaxyEngineWithSingularityDB
3131
else:
3232
engine_type = LocalManagedGalaxyEngine

planemo/engine/galaxy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from galaxy.tool_util.verify import interactor
1313

1414
from planemo import io
15+
from planemo.database.postgres_singularity import SingularityPostgresDatabaseSource
1516
from planemo.galaxy.activity import (
1617
execute,
1718
execute_rerun,
@@ -26,7 +27,6 @@
2627
Rerunnable,
2728
RunnableType,
2829
)
29-
from planemo.database.postgres_singularity import SingularityPostgresDatabaseSource
3030
from .interface import BaseEngine
3131

3232
if TYPE_CHECKING:

planemo/galaxy/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333

3434
from planemo import git
3535
from planemo.config import OptionSource
36-
from planemo.deps import ensure_dependency_resolvers_conf_configured
3736
from planemo.database import postgres_singularity
37+
from planemo.deps import ensure_dependency_resolvers_conf_configured
3838
from planemo.docker import docker_host_args
3939
from planemo.galaxy.workflows import (
4040
get_toolshed_url_for_tool_id,
@@ -1136,7 +1136,7 @@ def default_use_path_paste(self):
11361136

11371137

11381138
def _database_connection(database_location, **kwds):
1139-
if 'database_type' in kwds and kwds['database_type'] == 'postgres_singularity':
1139+
if "database_type" in kwds and kwds["database_type"] == "postgres_singularity":
11401140
default_connection = postgres_singularity.DEFAULT_CONNECTION_STRING
11411141
else:
11421142
default_connection = DATABASE_LOCATION_TEMPLATE % database_location

0 commit comments

Comments
 (0)