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
|
|
|
|
2019-01-06 16:22:33 +01:00
|
|
|
FAIL = "\033[91m"
|
|
|
|
SUCCESS = "\033[92m"
|
|
|
|
RESET = "\033[0m"
|
2014-08-24 09:42:48 +02:00
|
|
|
|
|
|
|
|
2019-01-06 16:22:33 +01:00
|
|
|
@command("check", help="Checks for pep8 errors in openslides and tests")
|
2014-08-24 09:42:48 +02:00
|
|
|
def check(args=None):
|
|
|
|
"""
|
|
|
|
Checks for pep8 and other code styling conventions.
|
|
|
|
"""
|
2019-01-06 16:22:33 +01:00
|
|
|
value = call("flake8 --max-line-length=150 --statistics openslides tests")
|
|
|
|
value += call("python -m mypy openslides/ tests/")
|
2018-11-05 09:04:41 +01:00
|
|
|
return value
|
2014-08-24 09:42:48 +02:00
|
|
|
|
|
|
|
|
2019-01-06 16:22:33 +01:00
|
|
|
@command("travis", help="Runs the code that travis does")
|
2014-08-24 09:42:48 +02:00
|
|
|
def travis(args=None):
|
|
|
|
"""
|
|
|
|
Runs all commands that travis tests.
|
|
|
|
"""
|
|
|
|
return_codes = []
|
2019-01-06 16:22:33 +01:00
|
|
|
with open(".travis.yml") as f:
|
2018-07-09 23:22:26 +02:00
|
|
|
travis = yaml.load(f)
|
2019-01-06 16:22:33 +01:00
|
|
|
for line in travis["script"]:
|
2019-01-12 23:01:42 +01:00
|
|
|
print(f"Run: {line}")
|
2018-07-09 23:22:26 +02:00
|
|
|
return_code = call(line)
|
2015-01-22 18:29:12 +01:00
|
|
|
return_codes.append(return_code)
|
|
|
|
if return_code:
|
2019-01-06 16:22:33 +01:00
|
|
|
print(FAIL + "fail!\n" + RESET)
|
2015-01-22 18:29:12 +01:00
|
|
|
else:
|
2019-01-06 16:22:33 +01:00
|
|
|
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)))
|
|
|
|
|
|
|
|
|
2019-01-06 16:22:33 +01:00
|
|
|
@argument("-r", "--requirements", nargs="?", default="requirements.txt")
|
|
|
|
@command(
|
|
|
|
"min_requirements",
|
|
|
|
help="Prints a pip line to install the minimum supported versions of "
|
|
|
|
"the requirements.",
|
|
|
|
)
|
2014-08-24 09:42:48 +02:00
|
|
|
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)
|
|
|
|
"""
|
2019-01-06 16:22:33 +01:00
|
|
|
|
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 == ">=":
|
2019-01-12 23:01:42 +01:00
|
|
|
yield f"{req.name}=={version}"
|
2014-08-24 09:42:48 +02:00
|
|
|
|
2019-01-06 16:22:33 +01:00
|
|
|
print(" ".join(get_lowest_versions(args.requirements)))
|
2015-01-22 18:29:12 +01:00
|
|
|
|
|
|
|
|
2019-01-06 16:22:33 +01:00
|
|
|
@command("clean", 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')
|
2019-01-06 16:22:33 +01:00
|
|
|
call("find -type d -empty -delete")
|
2015-01-30 11:58:36 +01:00
|
|
|
|
2015-01-21 08:57:45 +01:00
|
|
|
|
2019-01-06 16:22:33 +01:00
|
|
|
@command("format", help="Format code with isort and black")
|
2015-01-21 08:57:45 +01:00
|
|
|
def isort(args=None):
|
2019-01-06 16:22:33 +01:00
|
|
|
call("isort --recursive openslides tests")
|
2019-03-26 14:57:04 +01:00
|
|
|
call("black --target-version py36 openslides tests")
|