diff --git a/NEWS.rst b/NEWS.rst index e6330dda2ab190b761639864d048a4452956b2ff_TkVXUy5yc3Q=..4d31b40354b57ac4d4123ce4b18409dd879c0645_TkVXUy5yc3Q= 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -2,6 +2,11 @@ History ======= +12.0.0 +------ + +Default to not doing flake8 and isort in do_tests. + 11.1.0 ------ diff --git a/odoo_scripts/do_tests.py b/odoo_scripts/do_tests.py index e6330dda2ab190b761639864d048a4452956b2ff_b2Rvb19zY3JpcHRzL2RvX3Rlc3RzLnB5..4d31b40354b57ac4d4123ce4b18409dd879c0645_b2Rvb19zY3JpcHRzL2RvX3Rlc3RzLnB5 100755 --- a/odoo_scripts/do_tests.py +++ b/odoo_scripts/do_tests.py @@ -14,10 +14,10 @@ from .config import Config from .docker_dev_start import main as docker_dev_start_main -from .docker_flake8 import flake8 -from .docker_isort import isort +from .docker_flake8 import apply_flake8, parser_add_flake8_group +from .docker_isort import apply_isort, parser_add_isort_group from .docker_postgresql import POSTGRES_PASSWORD from .parsing import apply, basic_parser _logger = logging.getLogger(__name__) @@ -19,7 +19,7 @@ from .docker_postgresql import POSTGRES_PASSWORD from .parsing import apply, basic_parser _logger = logging.getLogger(__name__) -__version__ = "2.0.0" +__version__ = "3.0.0" __date__ = "2018-04-13" @@ -25,5 +25,5 @@ __date__ = "2018-04-13" -__updated__ = "2020-09-15" +__updated__ = "2021-10-21" def main(argv=None): # IGNORE:C0111 @@ -148,6 +148,8 @@ default=None, dest="LOAD_LANGUAGE", ) + parser_add_flake8_group(parser) + parser_add_isort_group(parser) # TODO options # - db host/uri (include socket) # - db user for creation/remove @@ -244,9 +246,8 @@ args.append("--dbport") args.append(dbport) - # only run flake8 and isort once rather than once per docker_dev_start call - flake8(odoo_type) - isort() + apply_flake8(nmspc, odoo_type) + apply_isort(nmspc) if nmspc.log_handler: for lh in nmspc.log_handler: args.append("--log-handler") diff --git a/odoo_scripts/docker_dev_start.py b/odoo_scripts/docker_dev_start.py index e6330dda2ab190b761639864d048a4452956b2ff_b2Rvb19zY3JpcHRzL2RvY2tlcl9kZXZfc3RhcnQucHk=..4d31b40354b57ac4d4123ce4b18409dd879c0645_b2Rvb19zY3JpcHRzL2RvY2tlcl9kZXZfc3RhcnQucHk= 100755 --- a/odoo_scripts/docker_dev_start.py +++ b/odoo_scripts/docker_dev_start.py @@ -18,8 +18,8 @@ from . import docker_build from .config import Config from .docker_client import DockerClient -from .docker_flake8 import flake8 -from .docker_isort import isort +from .docker_flake8 import apply_flake8, parser_add_flake8_group +from .docker_isort import apply_isort, parser_add_isort_group from .docker_postgresql import POSTGRES_PASSWORD, docker_run_postgresql from .docker_py3o import start_py3o from .parsing import apply, basic_parser @@ -46,7 +46,7 @@ program_license = """%s Created by Vincent Hatakeyama on %s. - Copyright 2017, 2018, 2019, 2020 XCG Consulting. All rights reserved. + Copyright 2017, 2018, 2019, 2020, 2021 XCG Consulting. All rights reserved. Licensed under the MIT License @@ -156,36 +156,8 @@ help="Start a Postgresql docker", action="store_true", ) - flake8_group = parser.add_mutually_exclusive_group() - flake8_group.add_argument( - "--flake8", - help="Run flake8", - action="store_true", - dest="flake8", - default=False, - ) - flake8_group.add_argument( - "--no-flake8", - help="Do not run flake8 [default]", - action="store_false", - dest="flake8", - default=False, - ) - isort_group = parser.add_mutually_exclusive_group() - isort_group.add_argument( - "--isort", - help="Run isort", - action="store_true", - dest="isort", - default=False, - ) - isort_group.add_argument( - "--no-isort", - help="Do not run isort [default]", - action="store_false", - dest="isort", - default=False, - ) + parser_add_flake8_group(parser) + parser_add_isort_group(parser) parser.add_argument( "--odoo-help", help="Pass --help to odoo binary [default: %(default)s]", @@ -317,8 +289,6 @@ use_host_network = nmspc.host_network _logger.debug("Use host network: %s", str(use_host_network)) start_postgresql = nmspc.start_postgresql - run_flake8 = nmspc.flake8 - run_isort = nmspc.isort odoo_help = nmspc.odoo_help dev = nmspc.dev dev_opts = nmspc.dev_opts @@ -789,11 +759,8 @@ arg.append("--addons-path") arg.append(",".join(all_addons_dir)) - if run_flake8: - flake8(odoo_type) - - if run_isort: - isort() + apply_flake8(nmspc, odoo_type) + apply_isort(nmspc) # developer mode options if dev: diff --git a/odoo_scripts/docker_flake8.py b/odoo_scripts/docker_flake8.py index e6330dda2ab190b761639864d048a4452956b2ff_b2Rvb19zY3JpcHRzL2RvY2tlcl9mbGFrZTgucHk=..4d31b40354b57ac4d4123ce4b18409dd879c0645_b2Rvb19zY3JpcHRzL2RvY2tlcl9mbGFrZTgucHk= 100644 --- a/odoo_scripts/docker_flake8.py +++ b/odoo_scripts/docker_flake8.py @@ -2,6 +2,7 @@ # vim: set shiftwidth=4 softtabstop=4: """Run flake8 in a docker """ +import argparse import atexit import logging import os @@ -45,4 +46,30 @@ return parser +def parser_add_flake8_group(parser: argparse.ArgumentParser): + """Add flake8 option (--flake8/--no-flake8) to the given parser. + Defaults to not using flake8.""" + flake8_group = parser.add_mutually_exclusive_group() + flake8_group.add_argument( + "--flake8", + help="Run flake8", + action="store_true", + dest="flake8", + default=False, + ) + flake8_group.add_argument( + "--no-flake8", + help="Do not run flake8 [default]", + action="store_false", + dest="flake8", + default=False, + ) + + +def apply_flake8(namespace: argparse.Namespace, odoo_type: str): + """Run flake8 if the option was set.""" + if namespace.flake8: + flake8(odoo_type) + + def main(argv=None): @@ -48,6 +75,5 @@ def main(argv=None): - """Copy modules for a build, callable version that parses arguments - """ + """Copy modules for a build, callable version that parses arguments""" parser = __parser() nmspc = parser.parse_args(argv) apply(nmspc) @@ -56,9 +82,8 @@ return flake8(odoo_type) -def flake8(odoo_type): - """Run flake8 - """ +def flake8(odoo_type: str): + """Run flake8""" client = DockerClient.client repository = "xcgd/flake8" if odoo_type in ("odoo7", "odoo8", "odoo9", "odoo10"): diff --git a/odoo_scripts/docker_isort.py b/odoo_scripts/docker_isort.py index e6330dda2ab190b761639864d048a4452956b2ff_b2Rvb19zY3JpcHRzL2RvY2tlcl9pc29ydC5weQ==..4d31b40354b57ac4d4123ce4b18409dd879c0645_b2Rvb19zY3JpcHRzL2RvY2tlcl9pc29ydC5weQ== 100644 --- a/odoo_scripts/docker_isort.py +++ b/odoo_scripts/docker_isort.py @@ -2,6 +2,7 @@ # vim: set shiftwidth=4 softtabstop=4: """Run isort in a docker """ +import argparse import atexit import logging import os @@ -12,5 +13,5 @@ from .docker_client import DockerClient from .parsing import apply, basic_parser -__version__ = "1.0.0" +__version__ = "1.0.1" __date__ = "2020-09-10" @@ -16,5 +17,5 @@ __date__ = "2020-09-10" -__updated__ = "2020-09-10" +__updated__ = "2021-10-21" _logger = logging.getLogger(__name__) @@ -46,4 +47,30 @@ return parser +def parser_add_isort_group(parser: argparse.ArgumentParser): + """Add isort option (--isort/--no-isort) to the given parser. + Defaults to not using isort.""" + isort_group = parser.add_mutually_exclusive_group() + isort_group.add_argument( + "--isort", + help="Run isort", + action="store_true", + dest="isort", + default=False, + ) + isort_group.add_argument( + "--no-isort", + help="Do not run isort [default]", + action="store_false", + dest="isort", + default=False, + ) + + +def apply_isort(namespace: argparse.Namespace): + """Run isort if the option was set.""" + if namespace.isort: + isort() + + def main(argv=None): @@ -49,6 +76,5 @@ def main(argv=None): - """Copy modules for a build, callable version that parses arguments - """ + """Copy modules for a build, callable version that parses arguments""" parser = __parser() nmspc = parser.parse_args(argv) apply(nmspc) @@ -57,8 +83,7 @@ def isort(pull=True): - """Run isort - """ + """Run isort""" client = DockerClient.client if pull: _logger.info("Pulling isort")