summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzhurong <aaronzhu1121@gmail.com>2017-12-04 13:29:50 +0800
committerzhurong <aaronzhu1121@gmail.com>2017-12-04 13:29:50 +0800
commitfb32c17d930e81f4ca36168b9438a196357223f9 (patch)
tree1b885751d946a9d33ff13da38ec017bde544430e
parent60dea91a748824cb08c48d898323c01e4989b256 (diff)
Remove the unused install venv scriptes
We can simply create the venv just use "tox -evenv". Change-Id: Ib9e7ae9827f522491ddad3000926624b203c0e98
Notes
Notes (review): Code-Review+2: Felipe Monteiro <felipe.monteiro@att.com> Code-Review+2: zhurong <aaronzhu1121@gmail.com> Workflow+1: zhurong <aaronzhu1121@gmail.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Tue, 05 Dec 2017 07:11:22 +0000 Reviewed-on: https://review.openstack.org/525056 Project: openstack/murano Branch: refs/heads/master
-rw-r--r--tools/install_venv.py75
-rw-r--r--tools/install_venv_common.py171
-rwxr-xr-xtools/with_venv.sh4
3 files changed, 0 insertions, 250 deletions
diff --git a/tools/install_venv.py b/tools/install_venv.py
deleted file mode 100644
index 113407f..0000000
--- a/tools/install_venv.py
+++ /dev/null
@@ -1,75 +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# Copyright (c) 2013 Hewlett-Packard Development Company, L.P.
8#
9# Licensed under the Apache License, Version 2.0 (the "License"); you may
10# not use this file except in compliance with the License. You may obtain
11# a copy of the License at
12#
13# http://www.apache.org/licenses/LICENSE-2.0
14#
15# Unless required by applicable law or agreed to in writing, software
16# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18# License for the specific language governing permissions and limitations
19# under the License.
20
21import os
22import sys
23
24from six.moves import configparser
25
26import install_venv_common as install_venv
27
28
29def print_help(project, venv, root):
30 help = """
31 %(project)s development environment setup is complete.
32
33 %(project)s development uses virtualenv to track and manage Python
34 dependencies while in development and testing.
35
36 To activate the %(project)s virtualenv for the extent of your current
37 shell session you can run:
38
39 $ source %(venv)s/bin/activate
40
41 Or, if you prefer, you can run commands in the virtualenv on a case by
42 case basis by running:
43
44 $ %(root)s/tools/with_venv.sh <your command>
45 """
46 print(help % dict(project=project, venv=venv, root=root))
47
48
49def main(argv):
50 root = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
51
52 if os.environ.get('tools_path'):
53 root = os.environ['tools_path']
54 venv = os.path.join(root, '.venv')
55 if os.environ.get('venv'):
56 venv = os.environ['venv']
57
58 pip_requires = os.path.join(root, 'requirements.txt')
59 test_requires = os.path.join(root, 'test-requirements.txt')
60 py_version = "python%s.%s" % (sys.version_info[0], sys.version_info[1])
61 setup_cfg = configparser.ConfigParser()
62 setup_cfg.read(os.path.join(root, 'setup.cfg'))
63 project = setup_cfg.get('metadata', 'name')
64
65 install = install_venv.InstallVenv(
66 root, venv, pip_requires, test_requires, py_version, project)
67 options = install.parse_args(argv)
68 install.check_python_version()
69 install.check_dependencies()
70 install.create_virtualenv(no_site_packages=options.no_site_packages)
71 install.install_dependencies()
72 print_help(project, venv, root)
73
74if __name__ == '__main__':
75 main(sys.argv)
diff --git a/tools/install_venv_common.py b/tools/install_venv_common.py
deleted file mode 100644
index 8c205a0..0000000
--- a/tools/install_venv_common.py
+++ /dev/null
@@ -1,171 +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
105 def pip_install(self, *args):
106 self.run_command(['tools/with_venv.sh',
107 'pip', 'install', '--upgrade'] + list(args),
108 redirect_output=False)
109
110 def install_dependencies(self):
111 print('Installing dependencies with pip (this can take a while)...')
112
113 # First things first, make sure our venv has the latest pip and
114 # setuptools and pbr
115 self.pip_install('pip>=1.4')
116 self.pip_install('setuptools')
117 self.pip_install('pbr')
118
119 self.pip_install('-r', self.requirements, '-r', self.test_requirements)
120
121 def parse_args(self, argv):
122 """Parses command-line arguments."""
123 parser = optparse.OptionParser()
124 parser.add_option('-n', '--no-site-packages',
125 action='store_true',
126 help="Do not inherit packages from global Python "
127 "install.")
128 return parser.parse_args(argv[1:])[0]
129
130
131class Distro(InstallVenv):
132
133 def check_cmd(self, cmd):
134 return bool(self.run_command(['which', cmd],
135 check_exit_code=False).strip())
136
137 def install_virtualenv(self):
138 if self.check_cmd('virtualenv'):
139 return
140
141 if self.check_cmd('easy_install'):
142 print('Installing virtualenv via easy_install...', end=' ')
143 if self.run_command(['easy_install', 'virtualenv']):
144 print('Succeeded')
145 return
146 else:
147 print('Failed')
148
149 self.die('ERROR: virtualenv not found.\n\n%s development'
150 ' requires virtualenv, please install it using your'
151 ' favorite package management tool' % self.project)
152
153
154class Fedora(Distro):
155 """This covers all Fedora-based distributions.
156
157 Includes: Fedora, RHEL, CentOS, Scientific Linux
158 """
159
160 def check_pkg(self, pkg):
161 return self.run_command_with_code(['rpm', '-q', pkg],
162 check_exit_code=False)[1] == 0
163
164 def install_virtualenv(self):
165 if self.check_cmd('virtualenv'):
166 return
167
168 if not self.check_pkg('python-virtualenv'):
169 self.die("Please install 'python-virtualenv'.")
170
171 super(Fedora, self).install_virtualenv()
diff --git a/tools/with_venv.sh b/tools/with_venv.sh
deleted file mode 100755
index c8d2940..0000000
--- a/tools/with_venv.sh
+++ /dev/null
@@ -1,4 +0,0 @@
1#!/bin/bash
2TOOLS=`dirname $0`
3VENV=$TOOLS/../.venv
4source $VENV/bin/activate && $@