2014-08-24 09:42:48 +02:00
|
|
|
import re
|
|
|
|
|
|
|
|
from parser import command, argument, call
|
|
|
|
|
2015-01-22 18:29:12 +01:00
|
|
|
FAIL = '\033[91m'
|
|
|
|
SUCCESS = '\033[92m'
|
|
|
|
RESET = '\033[0m'
|
|
|
|
|
2014-08-24 09:42:48 +02:00
|
|
|
|
|
|
|
@argument('module', nargs='?', default='')
|
|
|
|
@command('test', help='runs the tests')
|
|
|
|
def test(args=None):
|
|
|
|
"""
|
|
|
|
Runs the tests.
|
|
|
|
"""
|
|
|
|
module = getattr(args, 'module', '')
|
2015-06-30 02:37:57 +02:00
|
|
|
if module == '':
|
|
|
|
module = 'tests'
|
|
|
|
else:
|
|
|
|
module = 'tests.{}'.format(module)
|
2015-01-25 00:34:14 +01:00
|
|
|
return call("DJANGO_SETTINGS_MODULE='tests.settings' coverage run "
|
2015-06-30 02:37:57 +02:00
|
|
|
"./manage.py test {}".format(module))
|
2014-08-24 09:42:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
@argument('--plain', action='store_true')
|
|
|
|
@command('coverage', help='Runs all tests and builds the coverage html files')
|
|
|
|
def coverage(args=None, plain=None):
|
|
|
|
"""
|
|
|
|
Runs the tests and creates a coverage report.
|
|
|
|
|
|
|
|
By default it creates a html report. With the argument --plain, it creates
|
|
|
|
a plain report and fails under a certain amount of untested lines.
|
|
|
|
"""
|
|
|
|
if plain is None:
|
|
|
|
plain = getattr(args, 'plain', False)
|
|
|
|
if plain:
|
|
|
|
return call('coverage report -m --fail-under=80')
|
|
|
|
else:
|
|
|
|
return call('coverage html')
|
|
|
|
|
|
|
|
|
|
|
|
@command('check', help='Checks for pep8 errors in openslides and tests')
|
|
|
|
def check(args=None):
|
|
|
|
"""
|
|
|
|
Checks for pep8 and other code styling conventions.
|
|
|
|
"""
|
|
|
|
return call('flake8 --max-line-length=150 --statistics openslides tests')
|
|
|
|
|
|
|
|
|
|
|
|
@command('travis', help='Runs the code that travis does')
|
|
|
|
def travis(args=None):
|
|
|
|
"""
|
|
|
|
Runs all commands that travis tests.
|
|
|
|
"""
|
|
|
|
return_codes = []
|
|
|
|
with open('.travis.yml') as f:
|
|
|
|
script_lines = False
|
|
|
|
for line in (line.strip() for line in f.readlines()):
|
|
|
|
if line == 'script:':
|
|
|
|
script_lines = True
|
|
|
|
continue
|
2015-01-22 18:29:12 +01:00
|
|
|
if not script_lines or not line:
|
2014-08-24 09:42:48 +02:00
|
|
|
continue
|
|
|
|
|
|
|
|
match = re.search(r'"(.*)"', line)
|
2015-01-22 18:29:12 +01:00
|
|
|
print('Run: %s' % match.group(1))
|
|
|
|
return_code = call(match.group(1))
|
|
|
|
return_codes.append(return_code)
|
|
|
|
if return_code:
|
|
|
|
print(FAIL + 'fail!\n' + RESET)
|
|
|
|
else:
|
|
|
|
print(SUCCESS + 'success!\n' + RESET)
|
2014-08-24 09:42:48 +02:00
|
|
|
|
|
|
|
# Retuns True if one command exited with a different statuscode then 1
|
|
|
|
return bool(list(filter(bool, return_codes)))
|
|
|
|
|
|
|
|
|
|
|
|
@argument('-r', '--requirements', nargs='?',
|
|
|
|
default='requirements_production.txt')
|
|
|
|
@command('min_requirements',
|
|
|
|
help='Prints a pip line to install the minimum supported versions of '
|
|
|
|
'the requirements.')
|
|
|
|
def min_requirements(args=None):
|
|
|
|
"""
|
|
|
|
Prints a pip install command to install the minimal supported versions of a
|
|
|
|
requirement file.
|
|
|
|
|
|
|
|
Uses requirements_production.txt by default.
|
|
|
|
|
2016-08-13 09:06:03 +02:00
|
|
|
The following line will install the version:
|
|
|
|
|
|
|
|
pip install $(python make min_requirements)
|
|
|
|
"""
|
2015-06-30 02:37:57 +02:00
|
|
|
import pip
|
2014-08-24 09:42:48 +02:00
|
|
|
|
|
|
|
def get_lowest_versions(requirements_file):
|
2015-06-30 02:37:57 +02:00
|
|
|
for line in pip.req.parse_requirements(requirements_file, session=pip.download.PipSession()):
|
2016-08-13 09:06:03 +02:00
|
|
|
for specifier in line.req.specifier:
|
|
|
|
if specifier.operator == '>=':
|
|
|
|
min_version = specifier.version
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
raise ValueError('Not supported line {}'.format(line))
|
|
|
|
yield '%s==%s' % (line.req.name, min_version)
|
2014-08-24 09:42:48 +02:00
|
|
|
|
2016-08-13 09:06:03 +02:00
|
|
|
print(' '.join(get_lowest_versions(args.requirements)))
|
2015-01-22 18:29:12 +01:00
|
|
|
|
|
|
|
|
|
|
|
@command('clear',
|
|
|
|
help='Deletes unneeded files and folders')
|
2015-06-30 02:37:57 +02:00
|
|
|
def clean(args=None):
|
2015-01-22 18:29:12 +01:00
|
|
|
"""
|
|
|
|
Deletes all .pyc and .orig files and empty folders.
|
|
|
|
"""
|
|
|
|
call('find -name "*.pyc" -delete')
|
|
|
|
call('find -name "*.orig" -delete')
|
|
|
|
call('find -type d -empty -delete')
|
2015-01-30 11:58:36 +01:00
|
|
|
|
2015-01-21 08:57:45 +01:00
|
|
|
|
|
|
|
@command('isort',
|
|
|
|
help='Sorts all imports in all python files.')
|
|
|
|
def isort(args=None):
|
|
|
|
return call('isort --recursive openslides tests')
|