Skip to content

Commit 7ca2b40

Browse files
authored
Merge pull request #874 from mvdbeek/allow_python_version_selection
Allow selection of python version when starting managed Galaxy
2 parents 911ac8c + fd1a9e8 commit 7ca2b40

18 files changed

Lines changed: 160 additions & 80 deletions

.travis.yml

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,35 @@
11
language: python
22
sudo: false
3-
python: 2.7
43
env:
54
global:
65
- PLANEMO_SKIP_REDUNDANT_TESTS=1
76
- PLANEMO_ENABLE_POSTGRES_TESTS=1
87
- PLANEMO_SKIP_GALAXY_CWL_TESTS=1
98
- PLANEMO_TEST_WORKFLOW_RUN_PROFILE=travisworkflowtests
10-
matrix:
11-
- TOX_ENV=py27-lint
12-
- TOX_ENV=py34-lint
13-
- TOX_ENV=py27-lint-readme
14-
- TOX_ENV=py27-lint-docs
15-
- TOX_ENV=py34-quick
16-
- TOX_ENV=py27
17-
- TOX_ENV=py34
18-
- TOX_ENV=py27-lint-docstrings
19-
20-
install:
21-
- pip install tox coveralls
22-
239
matrix:
10+
include:
11+
- python: 2.7
12+
env: TOX_ENV=py27-lint
13+
- python: 2.7
14+
env: TOX_ENV=py27-lint-readme
15+
- python: 2.7
16+
env: TOX_ENV=py27-lint-docs
17+
- python: 2.7
18+
env: TOX_ENV=py27-lint-docstrings
19+
- python: 3.6
20+
env: TOX_ENV=py36-lint
21+
- python: 3.6
22+
env: TOX_ENV=py36-quick
23+
- python: 2.7
24+
env: TOX_ENV=py27
25+
- python: 3.6
26+
env: TOX_ENV=py36
2427
allow_failures:
2528
- env: TOX_ENV=py27-lint-docstrings
2629

30+
install:
31+
- pip install tox coveralls
32+
2733
script: tox -e $TOX_ENV
2834

2935
after_success:

planemo/galaxy/config.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from galaxy.containers.docker_model import DockerVolume
1414
from galaxy.tools.deps import docker_util
1515
from galaxy.tools.deps.commands import argv_to_str
16+
from pkg_resources import parse_version
1617
from six import (
1718
add_metaclass,
1819
iteritems
@@ -34,6 +35,7 @@
3435
)
3536
from planemo.mulled import build_involucro_context
3637
from planemo.shed import tool_shed_url
38+
from planemo.virtualenv import DEFAULT_PYTHON_VERSION
3739
from .api import (
3840
DEFAULT_MASTER_API_KEY,
3941
gi,
@@ -397,6 +399,10 @@ def config_join(*args):
397399
)
398400
_ensure_directory(shed_tool_path)
399401
port = _get_port(kwds)
402+
if parse_version(kwds.get('galaxy_python_version', DEFAULT_PYTHON_VERSION)) >= parse_version('3'):
403+
# on python 3 we use gunicorn,
404+
# which requires 'main' as server name
405+
server_name = 'main'
400406
template_args = dict(
401407
port=port,
402408
host=kwds.get("host", "127.0.0.1"),
@@ -941,6 +947,14 @@ def startup_command(self, ctx, **kwds):
941947
run_script += " --server-name %s" % shlex_quote(self.server_name)
942948
server_ini = os.path.join(self.config_directory, "galaxy.ini")
943949
self.env["GALAXY_CONFIG_FILE"] = server_ini
950+
if parse_version(kwds.get('galaxy_python_version', DEFAULT_PYTHON_VERSION)) >= parse_version('3'):
951+
# We need to start under gunicorn
952+
self.env['APP_WEBSERVER'] = 'gunicorn'
953+
self.env['GUNICORN_CMD_ARGS'] = "--bind={host}:{port} --name={server_name}".format(
954+
host=kwds['host'],
955+
port=kwds['port'],
956+
server_name=self.server_name,
957+
)
944958
cd_to_galaxy_command = ['cd', self.galaxy_root]
945959
return shell_join(
946960
cd_to_galaxy_command,
@@ -1233,19 +1247,13 @@ def _galaxy_source(kwds):
12331247

12341248

12351249
def _install_with_command(ctx, config_directory, command, env, kwds):
1236-
# TODO: --watchdog
1237-
pip_installs = []
1238-
if pip_installs:
1239-
pip_install_command = ['pip', 'install'] + pip_installs
1240-
else:
1241-
pip_install_command = ""
12421250
setup_venv_command = setup_venv(ctx, kwds)
1251+
env['__PYVENV_LAUNCHER__'] = ''
12431252
install_cmd = shell_join(
12441253
['cd', config_directory],
12451254
command,
12461255
['cd', 'galaxy-dev'],
12471256
setup_venv_command,
1248-
pip_install_command,
12491257
setup_common_startup_args(),
12501258
COMMAND_STARTUP_COMMAND,
12511259
)
@@ -1255,15 +1263,20 @@ def _install_with_command(ctx, config_directory, command, env, kwds):
12551263
def _ensure_galaxy_repository_available(ctx, kwds):
12561264
workspace = ctx.workspace
12571265
cwl = kwds.get("cwl", False)
1258-
gx_repo = os.path.join(workspace, "gx_repo")
1266+
galaxy_source = kwds.get('galaxy_source')
1267+
if galaxy_source and galaxy_source != DEFAULT_GALAXY_SOURCE:
1268+
sanitized_repo_name = "".join(c if c.isalnum() else '_' for c in kwds['galaxy_source']).rstrip()[:255]
1269+
gx_repo = os.path.join(workspace, "gx_repo_%s" % sanitized_repo_name)
1270+
else:
1271+
gx_repo = os.path.join(workspace, "gx_repo")
12591272
if cwl:
12601273
gx_repo += "_cwl"
12611274
if os.path.exists(gx_repo):
12621275
# Attempt fetch - but don't fail if not interweb, etc...
1263-
shell("git --git-dir %s fetch >/dev/null 2>&1" % gx_repo)
1276+
shell("git --git-dir %s remote update >/dev/null 2>&1" % gx_repo)
12641277
else:
12651278
remote_repo = _galaxy_source(kwds)
1266-
command = git.command_clone(ctx, remote_repo, gx_repo, bare=True)
1279+
command = git.command_clone(ctx, remote_repo, gx_repo, mirror=True)
12671280
shell(command)
12681281
return gx_repo
12691282

planemo/galaxy/run.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
from six.moves import shlex_quote
77

88
from planemo.io import info, shell_join
9-
from planemo.virtualenv import create_command
9+
from planemo.virtualenv import (
10+
create_command,
11+
DEFAULT_PYTHON_VERSION,
12+
)
1013

1114

1215
# Activate galaxy's virtualenv if present (needed for tests say but not for
@@ -39,7 +42,7 @@ def setup_venv(ctx, kwds):
3942
return ""
4043

4144
create_template_params = {
42-
'create_virtualenv': create_command("$GALAXY_VIRTUAL_ENV")
45+
'create_virtualenv': create_command("$GALAXY_VIRTUAL_ENV", kwds.get('galaxy_python_version'))
4346
}
4447
return shell_join(
4548
locate_galaxy_virtualenv(ctx, kwds),
@@ -55,6 +58,9 @@ def locate_galaxy_virtualenv(ctx, kwds):
5558
workspace = ctx.workspace
5659
galaxy_branch = kwds.get("galaxy_branch") or "master"
5760
shared_venv_path = os.path.join(workspace, "gx_venv")
61+
galaxy_python_version = kwds.get('galaxy_python_version', DEFAULT_PYTHON_VERSION)
62+
if galaxy_python_version != DEFAULT_PYTHON_VERSION:
63+
shared_venv_path = "%s_%s" % (shared_venv_path, galaxy_python_version)
5864
if galaxy_branch != "master":
5965
shared_venv_path = "%s_%s" % (shared_venv_path, galaxy_branch)
6066
venv_command = CACHED_VIRTUAL_ENV_COMMAND % shlex_quote(shared_venv_path)

planemo/git.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,17 @@ def checkout(ctx, remote_repo, local_path, branch=None, remote="origin", from_br
5959
io.communicate(["git", "merge", "--ff-only", "%s/%s" % (remote, from_branch)], env=env)
6060

6161

62-
def command_clone(ctx, src, dest, bare=False, branch=None):
62+
def command_clone(ctx, src, dest, mirror=False, branch=None):
6363
"""Produce a command-line string to clone a repository.
6464
6565
Take in ``ctx`` to allow more configurability down the road.
6666
"""
67-
bare_arg = ""
68-
if bare:
69-
bare_arg = "--bare"
70-
branch_arg = ""
67+
cmd = ['git', 'clone']
68+
if mirror:
69+
cmd.append("--mirror")
7170
if branch is not None:
72-
branch_arg = "--branch '%s'" % branch
73-
cmd = "git clone %s %s '%s' '%s'" % (bare_arg, branch_arg, src, dest)
71+
cmd.extend(["--branch", branch])
72+
cmd.extend([src, dest])
7473
return cmd
7574

7675

planemo/io.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,10 @@ def kill_pid_file(pid_file):
182182

183183
pid = int(open(pid_file, "r").read())
184184
kill_posix(pid)
185+
try:
186+
os.unlink(pid_file)
187+
except Exception:
188+
pass
185189

186190

187191
def kill_posix(pid):
@@ -323,7 +327,7 @@ def path_startswith(p):
323327
norm_p = norm(p)
324328
norm_exclude_path = norm(exclude_path)
325329
if norm_p.startswith(norm_exclude_path):
326-
return norm_p[len(norm_exclude_path):len(norm_exclude_path)+1] in ['', os.sep]
330+
return norm_p[len(norm_exclude_path):len(norm_exclude_path) + 1] in ['', os.sep]
327331
return False
328332
return path_startswith
329333

planemo/options.py

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,16 @@ def galaxy_email_option():
129129
)
130130

131131

132+
def galaxy_python_version():
133+
return planemo_option(
134+
'--galaxy_python_version',
135+
use_global_config=True,
136+
default='2.7',
137+
type=click.Choice(['2', '2.7', '3', '3.3', '3.4', '3.5', '3.6', '3.7']),
138+
help="Python version to start Galaxy under",
139+
)
140+
141+
132142
def galaxy_root_option():
133143
return planemo_option(
134144
"--galaxy_root",
@@ -1059,6 +1069,7 @@ def galaxy_config_options():
10591069
def galaxy_target_options():
10601070
return _compose(
10611071
galaxy_root_option(),
1072+
galaxy_python_version(),
10621073
galaxy_database_seed_option(),
10631074
extra_tools_option(),
10641075
install_galaxy_option(),
@@ -1153,32 +1164,32 @@ def training_topic_option():
11531164

11541165
def training_tutorial_name_option():
11551166
return planemo_option(
1156-
"--tutorial_name",
1157-
help="Name (directory name) of the tutorial to create or to modify"
1167+
"--tutorial_name",
1168+
help="Name (directory name) of the tutorial to create or to modify"
11581169
)
11591170

11601171

11611172
def training_tutorial_name_req_option():
11621173
return planemo_option(
1163-
"--tutorial_name",
1164-
required=True,
1165-
help="Name (directory name) of the tutorial to modify"
1174+
"--tutorial_name",
1175+
required=True,
1176+
help="Name (directory name) of the tutorial to modify"
11661177
)
11671178

11681179

11691180
def training_datatype_option():
11701181
return planemo_option(
1171-
"--datatypes",
1172-
type=click.Path(file_okay=True, resolve_path=True),
1173-
help="YAML file with the correspondance between Zenodo extension and Galaxy datatypes",
1174-
default="shared/datatypes.yaml"
1182+
"--datatypes",
1183+
type=click.Path(file_okay=True, resolve_path=True),
1184+
help="YAML file with the correspondance between Zenodo extension and Galaxy datatypes",
1185+
default="shared/datatypes.yaml"
11751186
)
11761187

11771188

11781189
def training_zenodo_option():
11791190
return planemo_option(
1180-
"--zenodo_link",
1181-
help="Zenodo URL with the input data")
1191+
"--zenodo_link",
1192+
help="Zenodo URL with the input data")
11821193

11831194

11841195
def training_tutorial_worflow_option():

planemo/shed2tap/base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,12 +380,12 @@ def _tar_folders(filename):
380380
folders.add(i.name.rstrip("/"))
381381
else:
382382
folders.add(os.path.split(i.name)[0])
383-
return folders
383+
return list(folders)
384384

385385

386386
def _zip_folders(filename):
387387
archive = zipfile.ZipFile(filename, "r")
388-
return set(i.filename.rstrip("/") for i in archive.infolist() if i.filename.endswith("/"))
388+
return list(set(i.filename.rstrip("/") for i in archive.infolist() if i.filename.endswith("/")))
389389

390390

391391
def _common_prefix(folders):
@@ -523,7 +523,7 @@ def _commands_and_downloaded_file(url, target_filename=None, sha256sum=None):
523523
' echo "Downloading %s"' % downloaded_filename,
524524
' curl -L -o "$DOWNLOAD_CACHE/%s" "%s"' % (downloaded_filename, url),
525525
' cp "$DOWNLOAD_CACHE/%s" "%s"' % (downloaded_filename, target_filename),
526-
]
526+
]
527527
if sha256sum:
528528
# This is inserted into the if-else for a fresh download only.
529529
# Note double space between checksum and filename:

planemo/training/tool_input.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def get_formatted_repeat_desc(self):
145145
# add description of parameters in the repeat
146146
repeat_paramlist += templates.render(INPUT_SECTION, **{
147147
'space': SPACE * (self.level),
148-
'section_label': "%s: %s" % (ind+1, self.tool_inp_desc['title'])})
148+
'section_label': "%s: %s" % (ind + 1, self.tool_inp_desc['title'])})
149149
repeat_paramlist += paramlist_in_repeat
150150
self.level = cur_level
151151
self.wf_param_values = tmp_wf_param_values
@@ -218,17 +218,17 @@ def get_input_tool_name(step_id, steps):
218218
def get_empty_input():
219219
"""Get the string for an empty input."""
220220
return templates.render(INPUT_FILE_TEMPLATE, **{
221-
'space': 1*SPACE,
221+
'space': 1 * SPACE,
222222
'icon': 'param-file',
223223
'input_name': 'Input file',
224224
'input_value': 'File'
225-
})
225+
})
226226

227227

228228
def get_empty_param():
229229
"""Get the string for an empty param."""
230230
return templates.render(INPUT_PARAM, **{
231-
'space': 1*SPACE,
231+
'space': 1 * SPACE,
232232
'param_label': 'Parameter',
233233
'param_value': 'a value'
234-
})
234+
})

planemo/training/tutorial.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -227,17 +227,17 @@ def init_from_kwds(self, kwds):
227227
self.title = kwds["tutorial_title"]
228228
self.zenodo_link = kwds["zenodo_link"] if kwds["zenodo_link"] else ''
229229
self.questions = [
230-
"Which biological questions are addressed by the tutorial?",
231-
"Which bioinformatics techniques are important to know for this type of data?"]
230+
"Which biological questions are addressed by the tutorial?",
231+
"Which bioinformatics techniques are important to know for this type of data?"]
232232
self.objectives = [
233-
"The learning objectives are the goals of the tutorial",
234-
"They will be informed by your audience and will communicate to them and to yourself what you should focus on during the course",
235-
"They are single sentences describing what a learner should be able to do once they have completed the tutorial",
236-
"You can use Bloom's Taxonomy to write effective learning objectives"]
233+
"The learning objectives are the goals of the tutorial",
234+
"They will be informed by your audience and will communicate to them and to yourself what you should focus on during the course",
235+
"They are single sentences describing what a learner should be able to do once they have completed the tutorial",
236+
"You can use Bloom's Taxonomy to write effective learning objectives"]
237237
self.time = "3H"
238238
self.key_points = [
239-
"The take-home messages",
240-
"They will appear at the end of the tutorial"]
239+
"The take-home messages",
240+
"They will appear at the end of the tutorial"]
241241
self.contributors = ["contributor1", "contributor2"]
242242
self.init_wf_fp = kwds['workflow']
243243
self.init_wf_id = kwds['workflow_id']

0 commit comments

Comments
 (0)