diff --git a/NEWS.rst b/NEWS.rst index 644811469545a8c066ed5d15848c67cd62033554_TkVXUy5yc3Q=..f5078e31a576bb0d46f49ba0cf4acb5cf43e7995_TkVXUy5yc3Q= 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -2,7 +2,7 @@ History ======= -14.1.0 +15.0.0 ------ Odoo 15 compatibility. @@ -11,6 +11,8 @@ Use black default line length. +Change isort options to be able to show differences. + 14.0.0 ------ diff --git a/odoo_scripts/docker_isort.py b/odoo_scripts/docker_isort.py index 644811469545a8c066ed5d15848c67cd62033554_b2Rvb19zY3JpcHRzL2RvY2tlcl9pc29ydC5weQ==..f5078e31a576bb0d46f49ba0cf4acb5cf43e7995_b2Rvb19zY3JpcHRzL2RvY2tlcl9pc29ydC5weQ== 100644 --- a/odoo_scripts/docker_isort.py +++ b/odoo_scripts/docker_isort.py @@ -14,8 +14,8 @@ from .docker_client import DockerClient from .parsing import apply, basic_parser -__version__ = "1.1.0" +__version__ = "2.0.0" __date__ = "2020-09-10" __updated__ = "2022-01-25" _logger = logging.getLogger(__name__) @@ -18,7 +18,14 @@ __date__ = "2020-09-10" __updated__ = "2022-01-25" _logger = logging.getLogger(__name__) +_ISORT_DEST = "isort" +"""Name of destination variable used for isort in parsing""" + +CHECK_MODE = "check" +"""Run isort to check""" +DIFF_MODE = "diff" +"""Run isort to show differences""" def __parser(): @@ -32,7 +39,7 @@ program_license = """%s Created by Vincent Hatakeyama on %s. - Copyright 2020 XCG Consulting. All rights reserved. + Copyright 2020, 2022 XCG Consulting. All rights reserved. Licensed under the MIT License @@ -53,12 +60,19 @@ 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-check", + help="Run isort (check only)", + action="store_const", + dest=_ISORT_DEST, + const=CHECK_MODE, + ) + isort_group.add_argument( + "--isort-diff", + help="Run isort (check only)", + action="store_const", + dest=_ISORT_DEST, + const=DIFF_MODE, ) isort_group.add_argument( "--no-isort", help="Do not run isort [default]", @@ -61,12 +75,12 @@ ) isort_group.add_argument( "--no-isort", help="Do not run isort [default]", - action="store_false", - dest="isort", - default=False, + action="store_const", + dest=_ISORT_DEST, + const=None, ) def apply_isort(namespace: argparse.Namespace, odoo_type: str): """Run isort if the option was set.""" @@ -68,10 +82,11 @@ ) def apply_isort(namespace: argparse.Namespace, odoo_type: str): """Run isort if the option was set.""" - if namespace.isort: - isort(odoo_type) + if _ISORT_DEST in namespace and getattr(namespace, _ISORT_DEST): + return isort(getattr(namespace, _ISORT_DEST), odoo_type) + return 0 def main(argv=None): @@ -81,6 +96,6 @@ apply(nmspc) c = Config() odoo_type = c.odoo_type - return isort(odoo_type) + return isort(DIFF_MODE, odoo_type) @@ -85,6 +100,6 @@ -def isort(odoo_type: str, pull: bool = True): +def isort(mode: str, odoo_type: str, pull: bool = True): """Run isort""" client = DockerClient.client @@ -88,5 +103,10 @@ """Run isort""" client = DockerClient.client + if mode == CHECK_MODE: + command = ["--check"] + if mode == DIFF_MODE: + command = ["--check", "--diff"] + # determine image to use based on odoo version repository = "quay.orus.io/odoo/odoo" @@ -91,5 +111,4 @@ # determine image to use based on odoo version repository = "quay.orus.io/odoo/odoo" - command = ["--check", "."] if odoo_type == "odoo15": tag = "15.0" @@ -94,4 +113,6 @@ if odoo_type == "odoo15": tag = "15.0" + # append the directory, needed with isort≥5.0.0 + command.append(".") elif odoo_type == "odoo13": tag = "13.0" @@ -96,6 +117,5 @@ elif odoo_type == "odoo13": tag = "13.0" - command = ["--check"] else: repository = "xcgd/isort" tag = "odoo" @@ -99,7 +119,6 @@ else: repository = "xcgd/isort" tag = "odoo" - command = ["--check"] image = f"{repository}:{tag}" if pull: @@ -136,4 +155,5 @@ container = client.containers.create( image, entrypoint="isort", + user="root", command=command, @@ -139,5 +159,10 @@ command=command, - volumes={os.environ["PWD"]: {"bind": "/mnt", "mode": "ro"}}, + volumes={ + os.environ["PWD"]: { + "bind": "/mnt", + "mode": "ro" if mode in (CHECK_MODE, DIFF_MODE) else "rw", + } + }, working_dir="/mnt", detach=True, )