eive-tmtc/lint.py

43 lines
1.3 KiB
Python
Raw Permalink Normal View History

2021-06-30 11:18:57 +02:00
#!/usr/bin/env python3
import os
import sys
def main():
2022-03-01 16:57:40 +01:00
exclude_dirs_flag = ""
if not os.path.exists("setup.cfg"):
exclude_dirs_flag = (
"--exclude .git,__pycache__,docs/conf.py,old,build,dist,venv"
)
2022-01-18 14:03:56 +01:00
additional_flags_both_steps = "--count --statistics"
additional_flags_first_step = "--select=E9,F63,F7,F82 --show-source"
2022-03-01 17:13:20 +01:00
python_exe = ""
if os.name == "nt":
python_exe = "py -m"
2022-03-01 16:57:40 +01:00
flake8_first_step_cmd = (
2022-03-01 17:13:20 +01:00
f"{python_exe} flake8 . {additional_flags_both_steps} "
2022-03-01 16:57:40 +01:00
f"{additional_flags_first_step} {exclude_dirs_flag}"
)
2021-08-09 11:38:37 +02:00
status = os.system(flake8_first_step_cmd)
2022-03-01 16:57:40 +01:00
if os.name == "nt":
if status != 0:
print(f"Flake8 linter errors with status {status}")
else:
if os.WEXITSTATUS(status) != 0:
print(f"Flake8 linter errors with status {status}")
sys.exit(0)
additional_flags_second_step = (
'--exit-zero --max-complexity=10 --per-file-ignores="__init__.py:F401"'
)
if not os.path.exists("setup.cfg"):
additional_flags_second_step += " --max-line-length=100"
2022-01-18 14:03:56 +01:00
flake8_second_step_cmd = (
2022-03-01 17:13:20 +01:00
f"{python_exe} flake8 . {additional_flags_both_steps} {additional_flags_second_step}"
2022-03-01 16:57:40 +01:00
f" {exclude_dirs_flag}"
2022-01-18 14:03:56 +01:00
)
2021-08-09 11:38:37 +02:00
os.system(flake8_second_step_cmd)
2021-06-30 11:18:57 +02:00
if __name__ == "__main__":
main()