comparison env/lib/python3.7/site-packages/planemo/virtualenv.py @ 2:6af9afd405e9 draft

"planemo upload commit 0a63dd5f4d38a1f6944587f52a8cd79874177fc1"
author shellac
date Thu, 14 May 2020 14:56:58 -0400
parents 26e78fe6e8c4
children
comparison
equal deleted inserted replaced
1:75ca89e9b81c 2:6af9afd405e9
1 """ Utilities for using virtualenv as library and planemo command.
2 """
3 from __future__ import absolute_import
4
5 import os
6 import sys
7
8 import virtualenv
9 from galaxy.tool_util.deps.commands import which
10
11
12 DEFAULT_PYTHON_VERSION = os.environ.get("PLANEMO_DEFAULT_PYTHON_VERSION", "2.7")
13
14
15 def create_and_exit(virtualenv_path, **kwds):
16 sys.argv = ["virtualenv", virtualenv_path]
17 python = kwds.get("python", None)
18 if python:
19 sys.argv.extend(["--python", python])
20 return virtualenv.main()
21
22
23 def create_command(virtualenv_path, galaxy_python_version=None):
24 """ If virtualenv is on Planemo's path use it, otherwise use the planemo
25 subcommand virtualenv to create the virtualenv.
26 """
27 planemo_path = os.path.abspath(sys.argv[0])
28 virtualenv_on_path = which("virtualenv")
29 if virtualenv_on_path:
30 base_command = [
31 os.path.abspath(virtualenv_on_path),
32 ]
33 else:
34 base_command = [
35 planemo_path, "virtualenv",
36 ]
37
38 command = base_command
39
40 # Create a virtualenv with the selected python version.
41 # default to 2.7
42 if galaxy_python_version is None:
43 galaxy_python_version = DEFAULT_PYTHON_VERSION
44 python = which("python%s" % galaxy_python_version)
45 if python:
46 python = os.path.abspath(python)
47 command.extend(["-p", python])
48 command.append(virtualenv_path)
49 return " ".join(command)