summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2017-12-05 06:30:49 +0000
committerGerrit Code Review <review@openstack.org>2017-12-05 06:30:49 +0000
commit2475bac42fe158d1a751ce53f5eda405295858f5 (patch)
tree862c32753d3845eda0d8ae9c8a05e1dc68f0c15b
parent020be60db6e1fc2fbf0ca871c12d1fead04b06e7 (diff)
parent771b00602fe6ebd3210c8ee2cac6459f9d0a188c (diff)
Merge "Remove the unused install venv scriptes"
-rw-r--r--tools/install_venv.py71
-rw-r--r--tools/install_venv_common.py172
-rwxr-xr-xtools/with_venv.sh7
3 files changed, 0 insertions, 250 deletions
diff --git a/tools/install_venv.py b/tools/install_venv.py
deleted file mode 100644
index de23c18..0000000
--- a/tools/install_venv.py
+++ /dev/null
@@ -1,71 +0,0 @@
1# Copyright 2010 United States Government as represented by the
2# Administrator of the National Aeronautics and Space Administration.
3# All Rights Reserved.
4#
5# Copyright 2010 OpenStack Foundation
6# Copyright 2013 IBM Corp.
7#
8# Licensed under the Apache License, Version 2.0 (the "License"); you may
9# not use this file except in compliance with the License. You may obtain
10# a copy of the License at
11#
12# http://www.apache.org/licenses/LICENSE-2.0
13#
14# Unless required by applicable law or agreed to in writing, software
15# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17# License for the specific language governing permissions and limitations
18# under the License.
19
20import os
21import sys
22
23import install_venv_common as install_venv # noqa
24
25
26def print_help(venv, root):
27 help = """
28 OpenStack development environment setup is complete.
29
30 OpenStack development uses virtualenv to track and manage Python
31 dependencies while in development and testing.
32
33 To activate the OpenStack virtualenv for the extent of your current shell
34 session you can run:
35
36 $ . %s/bin/activate
37
38 Or, if you prefer, you can run commands in the virtualenv on a case by case
39 basis by running:
40
41 $ %s/tools/with_venv.sh <your command>
42
43 Also, make test will automatically use the virtualenv.
44 """
45 print(help % (venv, root))
46
47
48def main(argv):
49 root = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
50
51 if os.environ.get('tools_path'):
52 root = os.environ['tools_path']
53 venv = os.path.join(root, '.venv')
54 if os.environ.get('VENV'):
55 venv = os.environ['VENV']
56
57 pip_requires = os.path.join(root, 'requirements.txt')
58 test_requires = os.path.join(root, 'test-requirements.txt')
59 py_version = "python%s.%s" % (sys.version_info[0], sys.version_info[1])
60 project = 'OpenStack'
61 install = install_venv.InstallVenv(root, venv, pip_requires, test_requires,
62 py_version, project)
63 options = install.parse_args(argv)
64 install.check_python_version()
65 install.check_dependencies()
66 install.create_virtualenv(no_site_packages=options.no_site_packages)
67 install.install_dependencies()
68 print_help(venv, root)
69
70if __name__ == '__main__':
71 main(sys.argv)
diff --git a/tools/install_venv_common.py b/tools/install_venv_common.py
deleted file mode 100644
index e279159..0000000
--- a/tools/install_venv_common.py
+++ /dev/null
@@ -1,172 +0,0 @@
1# Copyright 2013 OpenStack Foundation
2# Copyright 2013 IBM Corp.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
16"""Provides methods needed by installation script for OpenStack development
17virtual environments.
18
19Since this script is used to bootstrap a virtualenv from the system's Python
20environment, it should be kept strictly compatible with Python 2.6.
21
22Synced in from openstack-common
23"""
24
25from __future__ import print_function
26
27import optparse
28import os
29import subprocess
30import sys
31
32
33class InstallVenv(object):
34
35 def __init__(self, root, venv, requirements,
36 test_requirements, py_version,
37 project):
38 self.root = root
39 self.venv = venv
40 self.requirements = requirements
41 self.test_requirements = test_requirements
42 self.py_version = py_version
43 self.project = project
44
45 def die(self, message, *args):
46 print(message % args, file=sys.stderr)
47 sys.exit(1)
48
49 def check_python_version(self):
50 if sys.version_info < (2, 6):
51 self.die("Need Python Version >= 2.6")
52
53 def run_command_with_code(self, cmd, redirect_output=True,
54 check_exit_code=True):
55 """Runs a command in an out-of-process shell.
56
57 Returns the output of that command. Working directory is self.root.
58 """
59 if redirect_output:
60 stdout = subprocess.PIPE
61 else:
62 stdout = None
63
64 proc = subprocess.Popen(cmd, cwd=self.root, stdout=stdout)
65 output = proc.communicate()[0]
66 if check_exit_code and proc.returncode != 0:
67 self.die('Command "%s" failed.\n%s', ' '.join(cmd), output)
68 return (output, proc.returncode)
69
70 def run_command(self, cmd, redirect_output=True, check_exit_code=True):
71 return self.run_command_with_code(cmd, redirect_output,
72 check_exit_code)[0]
73
74 def get_distro(self):
75 if (os.path.exists('/etc/fedora-release') or
76 os.path.exists('/etc/redhat-release')):
77 return Fedora(
78 self.root, self.venv, self.requirements,
79 self.test_requirements, self.py_version, self.project)
80 else:
81 return Distro(
82 self.root, self.venv, self.requirements,
83 self.test_requirements, self.py_version, self.project)
84
85 def check_dependencies(self):
86 self.get_distro().install_virtualenv()
87
88 def create_virtualenv(self, no_site_packages=True):
89 """Creates the virtual environment and installs PIP.
90
91 Creates the virtual environment and installs PIP only into the
92 virtual environment.
93 """
94 if not os.path.isdir(self.venv):
95 print('Creating venv...', end=' ')
96 if no_site_packages:
97 self.run_command(['virtualenv', '-q', '--no-site-packages',
98 self.venv])
99 else:
100 self.run_command(['virtualenv', '-q', self.venv])
101 print('done.')
102 else:
103 print("venv already exists...")
104 pass
105
106 def pip_install(self, *args):
107 self.run_command(['tools/with_venv.sh',
108 'pip', 'install', '--upgrade'] + list(args),
109 redirect_output=False)
110
111 def install_dependencies(self):
112 print('Installing dependencies with pip (this can take a while)...')
113
114 # First things first, make sure our venv has the latest pip and
115 # setuptools and pbr
116 self.pip_install('pip>=1.4')
117 self.pip_install('setuptools')
118 self.pip_install('pbr')
119
120 self.pip_install('-r', self.requirements, '-r', self.test_requirements)
121
122 def parse_args(self, argv):
123 """Parses command-line arguments."""
124 parser = optparse.OptionParser()
125 parser.add_option('-n', '--no-site-packages',
126 action='store_true',
127 help="Do not inherit packages from global Python "
128 "install.")
129 return parser.parse_args(argv[1:])[0]
130
131
132class Distro(InstallVenv):
133
134 def check_cmd(self, cmd):
135 return bool(self.run_command(['which', cmd],
136 check_exit_code=False).strip())
137
138 def install_virtualenv(self):
139 if self.check_cmd('virtualenv'):
140 return
141
142 if self.check_cmd('easy_install'):
143 print('Installing virtualenv via easy_install...', end=' ')
144 if self.run_command(['easy_install', 'virtualenv']):
145 print('Succeeded')
146 return
147 else:
148 print('Failed')
149
150 self.die('ERROR: virtualenv not found.\n\n%s development'
151 ' requires virtualenv, please install it using your'
152 ' favorite package management tool' % self.project)
153
154
155class Fedora(Distro):
156 """This covers all Fedora-based distributions.
157
158 Includes: Fedora, RHEL, CentOS, Scientific Linux
159 """
160
161 def check_pkg(self, pkg):
162 return self.run_command_with_code(['rpm', '-q', pkg],
163 check_exit_code=False)[1] == 0
164
165 def install_virtualenv(self):
166 if self.check_cmd('virtualenv'):
167 return
168
169 if not self.check_pkg('python-virtualenv'):
170 self.die("Please install 'python-virtualenv'.")
171
172 super(Fedora, self).install_virtualenv()
diff --git a/tools/with_venv.sh b/tools/with_venv.sh
deleted file mode 100755
index 7303990..0000000
--- a/tools/with_venv.sh
+++ /dev/null
@@ -1,7 +0,0 @@
1#!/bin/bash
2TOOLS_PATH=${TOOLS_PATH:-$(dirname $0)}
3VENV_PATH=${VENV_PATH:-${TOOLS_PATH}}
4VENV_DIR=${VENV_NAME:-/../.venv}
5TOOLS=${TOOLS_PATH}
6VENV=${VENV:-${VENV_PATH}/${VENV_DIR}}
7source ${VENV}/bin/activate && "$@"