2014-08-24 09:42:48 +02:00
|
|
|
from parser import command, argument, call
|
2018-07-09 23:22:26 +02:00
|
|
|
import yaml
|
|
|
|
import requirements
|
2014-08-24 09:42:48 +02:00
|
|
|
|
2015-01-22 18:29:12 +01:00
|
|
|
FAIL = '\033[91m'
|
|
|
|
SUCCESS = '\033[92m'
|
2018-07-09 23:22:26 +02:00
|
|
|
RESET = '\033[0m'
|
2014-08-24 09:42:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
@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:
|
2018-07-09 23:22:26 +02:00
|
|
|
travis = yaml.load(f)
|
|
|
|
for line in travis['script']:
|
|
|
|
print('Run: {}'.format(line))
|
|
|
|
return_code = call(line)
|
2015-01-22 18:29:12 +01:00
|
|
|
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='?',
|
2018-07-09 23:22:26 +02:00
|
|
|
default='requirements.txt')
|
2014-08-24 09:42:48 +02:00
|
|
|
@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.
|
|
|
|
|
2018-07-09 23:22:26 +02:00
|
|
|
Uses requirements.txt by default.
|
2014-08-24 09:42:48 +02:00
|
|
|
|
2016-08-13 09:06:03 +02:00
|
|
|
The following line will install the version:
|
|
|
|
|
|
|
|
pip install $(python make min_requirements)
|
|
|
|
"""
|
2014-08-24 09:42:48 +02:00
|
|
|
def get_lowest_versions(requirements_file):
|
2018-07-09 23:22:26 +02:00
|
|
|
with open(requirements_file) as f:
|
|
|
|
for req in requirements.parse(f):
|
|
|
|
if req.specifier:
|
|
|
|
for spec, version in req.specs:
|
|
|
|
if spec == ">=":
|
|
|
|
yield "{}=={}".format(req.name, 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')
|