/usr/lib/python2.7/dist-packages/easydev/multisetup.py is in python-easydev 0.9.35+dfsg-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 | # -*- python -*-
# -*- coding: utf-8 -*-
#
# This file is part of the easydev software
#
# Copyright (c) 2011-2017
#
# File author(s): Thomas Cokelaer <cokelaer@gmail.com>
#
# Distributed under the GPLv3 License.
# See accompanying file LICENSE.txt or copy at
# http://www.gnu.org/licenses/gpl-3.0.html
#
# Website: https://github.com/cokelaer/easydev
# Documentation: http://easydev-python.readthedocs.io
#
##############################################################################
"""Calling setup.py recursively and/or in multi python packages.
The commands are similar to those expected by setup.py. In addition,
there are a few commands dedicated to multisetup (see --help).
:Example:
.. doctest::
:options: +SKIP
>>> python multisetup install --quiet
>>> python multisetup install sdist --dist-dir ../dist
>>> python multisetup --keep-going install sdist --dist-dir ../dist
Based on OpenAlea.Misc http://openalea.gforge.inria.fr
"""
__license__ = "GPLv3"
__revision__ = "$Id$"
import sys
import os
from subprocess import PIPE, Popen
try:
from easydev.console import bold, red, green, \
color_terminal, nocolor, underline, purple
except ImportError:
pass
"""
args = sys.argv[1:]
if len(args) == 1 and args[0] in ['-h', '--help']:
Multisetup.help()
else:
if 'develop -u' in args:
dirs.reverse()
"""
class Multisetup(object):
"""The main base class to build Multisetup instances
In practice, you create a python script with this kind of code::
if __name__ == "__main__"
from easydev.multisetup import Multisetup
import sys
packages = ['pkg1', 'pkg2']
mysetup = Multisetup(commands=sys.argv[1:], packages=packages)
mysetup.run()
"""
def __init__(self, commands, packages=None, curdir='.', verbose=True):
""".. rubric:: Constructor
:param commands: list of user commands or command (see :meth:`parse_commands`)
accepted commands are --packages, --exclude-packages, -quiet, --keep-going
:param list packages: list of packages to process
:param str curdir: current directory default is .
:param bool verbose: verbose option
:type commands: a string or list of strings
The argument `commands` must be a list of strings combining arguments
from multisetup and setup.
:Examples:
.. doctest::
:options: +SKIP
>>> Multisetup("install --keep-going", ['pkg1', 'pkg2'], '.', verbose=True)
>>> Multisetup(["install","--keep-going"], ['pkg1', 'pkg2'], '.', verbose=True)
"""
if len(commands) == 1 and commands[0] in ['-h', '--help']:
Multisetup.help()
if 'develop -u' in " ".join(commands):
packages.reverse()
# default
self.curdir = os.path.abspath(curdir)
if isinstance(commands, list):
self.commands = list(commands)
elif isinstance(commands, str):
self.commands = list(commands.split(" "))
else:
raise TypeError("commands argument must be a list of arguments or a string")
self.packages = list(packages)
self.verbose = verbose
self.force = False
# parsing user arguments
self.parse_packages()
# self.parse_intern_commands()
self.parse_commands()
@classmethod
def help(cls):
"""help: to get more help and usage
"""
print("""
MultiSetup allows to build and install all the packages found in this
directory usinf the same commands and setuptools.
Examples:
---------
# Developer mode : Installation of the pks from svn
>>> python multisetup.py develop
# User mode: Installation of the packages on the system as root
>>> python multisetup.py install
# Administrator mode: Create distribution of the packages
>>> python multisetup.py nosetests -w test install bdist_egg -d ../dist sdist -d ../dist
Common commands:
multisetup.py sdist -d ./dist will create a source distribution underneath 'dist/'
multisetup.py install will install the package
Global options:
--quiet do not show setup outputs [default=False]
-k, --keep-going force the commands running[default=False]
-h, --help show detailed help message
--packages list of packages to run
[default: none]
--exclude-packages list of packages to not run
print "usage: multisetup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
""")
def parse_packages(self):
"""Search and remove package(S) from multisetup command (e.g., --package)
.. todo:: known issue: python multisetup.py --packages with two
packages will be confused by following commands. Must be put
at the end of the command
"""
if '--packages' in self.commands:
index = self.commands.index('--packages')
self.commands.remove('--packages')
self.packages = set()
found = True
while found is True:
try: #test is no more argument
self.commands[index]
except: # then breaks
break
# otherwise if next argument starts with -, break
if self.commands[index].startswith('-'):
break
# or carry on to gather package names
else:
self.packages.add(self.commands[index])
self.commands.remove(self.commands[index])
continue
#self.commands.pop(index)
if '--exclude-packages' in self.commands:
# keep track of --exclude-package index
index = self.commands.index('--exclude-packages')
# remove it from the commands
self.commands.remove('--exclude-packages')
# remove all packages provided afterwards until next arguments is found
found = True
while found is True:
# look for next argument/package that may be the end of the command
try:
package_to_remove = self.commands[index]
except:
break
# if this is a valid package name
if package_to_remove in self.packages:
# remove it from the package list
self.packages.remove(package_to_remove)
# and from the command line
self.commands.remove(package_to_remove)
# until we found another package
continue
# otherwise, it is an argument that
else:
#starts with a - sign
if package_to_remove.startswith('-'):
break
# or is invalid
raise ValueError('--exclude-packages error: package %s not found in package list' \
% self.commands[index])
#self.commands.pop(index)
def parse_commands(self):
"""Search and remove multisetup options
Get the user command line arguments (self.commands) that are dedicated
to multisetup such as --help, --quiet, --keep-going so that the
remaining commands are fully comptatible with setuptools.
"""
if '--quiet' in self.commands:
self.verbose = False
self.commands.remove('--quiet')
if '-k' in self.commands:
self.force = True
self.commands.remove('-k')
if '--keep-going' in self.commands:
self.force = True
self.commands.remove('--keep-going')
L = len(self.commands)
i = 0
while (i < L):
if self.commands[i].startswith('-'):
try:
self.commands[i-1] = self.commands[i-1] + ' ' + self.commands[i] + ' ' + self.commands[i+1]
self.commands.pop(i)
self.commands.pop(i)
except:
self.commands[i-1] = self.commands[i-1] + ' ' + self.commands[i]
self.commands.pop(i)
else:
i += 1
L = len(self.commands)
def run(self, color=True):
"""Executes 'python setup.py' with the user commands on all packages. """
if color:
try:
from easydev.console import bold, red, green, \
color_terminal, nocolor, underline, purple
except:
try:
sys.path.insert(0, os.path.join('deploy', 'src', 'deploy'))
from console import bold, red, green, \
color_terminal, nocolor, underline, purple
except:
pass
if not color_terminal():
# Windows' poor cmd box doesn't understand ANSI sequences
nocolor()
else:
bold = purple = red = green = underline = str
print(bold("Running multisetup version %s" % __revision__.split()[2]))
#project_dir = self.curdir.basename()
directories = [package for package in self.packages]
print('Will process the following directories: ',)
for directory in directories:
print(bold(directory)),
#print bold(directory.basename()),
print('')
try:
for directory in directories:
try:
os.chdir(directory)
print(underline('Entering %s package'
% os.path.basename(directory)))
# % directory.basename())
except OSError as err:
print(underline('Entering %s package'
% os.path.basename(directory)))
print(red("cannot find this directory (%s)"
% os.path.basename(directory)))
print(err)
print('Python exec : ' , sys.executable)
#print underline('Entering %s package' % directory.basename())
for cmd in self.commands:
setup_command = '%s setup.py %s ' % (sys.executable,cmd)
print("\tExecuting " + setup_command + '...processing',)
#Run setup.py with user commands
outputs = None
errors = None
if self.verbose:
process = Popen(setup_command,
shell=True)
status = process.wait()
else:
process = Popen(setup_command, stdout=PIPE, stderr=PIPE,
shell=True)
#status = process.wait()
outputs, errors = process.communicate()
if process.returncode == 0:
print(green('done'))
else:
if not self.verbose:
print(red('\tFailed. ( error code %s) ' %
(process.returncode)))
os.chdir(self.curdir)
if not self.force:
raise RuntimeError()
if 'pylint' in cmd:
if outputs is not None:
for x in outputs.split('\n'):
if x.startswith('Your code has been'):
print(purple('\t%s' % x))
if 'nosetests' in cmd:
if errors is not None:
for x in errors.split('\n'):
if x.startswith('TOTAL'):
res = x.replace('TOTAL', 'Total coverage')
res = " ".join (res.split())
print(purple('\t%s' % res))
if x.startswith('Ran'):
print(purple('\t%s' % x))
if x.startswith('FAILED'):
print(purple('\t%s' % x))
else:
print(purple('all right'))
os.chdir(self.curdir)
except RuntimeError:
sys.exit()
os.chdir(self.curdir)
|