Skip to content
Snippets Groups Projects
Commit dd7102bc authored by Vincent Hatakeyama's avatar Vincent Hatakeyama
Browse files

:sparkles: add docker_black to run black

parent 499a4f5d
No related branches found
Tags 16.5.0
1 merge request!97✨ add docker_black to run black
...@@ -2,6 +2,11 @@ ...@@ -2,6 +2,11 @@
History History
======= =======
15.3.0
------
Add docker_black to run black on a directory using the project image. Black must be present in that image.
15.2.1 15.2.1
------ ------
......
...@@ -16,6 +16,13 @@ ...@@ -16,6 +16,13 @@
.. important:: As there is no way of indicating sections (worse, it is handling them incorrectly), do not use ``python3 setup.py install``. .. important:: As there is no way of indicating sections (worse, it is handling them incorrectly), do not use ``python3 setup.py install``.
docker_black
------------
Run dockerized black on provided directory. black must be present in the project image.
This is part of the docker section.
docker_isort docker_isort
------------ ------------
......
#!/usr/bin/env python3 #!/usr/bin/env python3
# vim: set shiftwidth=4 softtabstop=4: """Run black in a docker
"""Run prettier in a docker
""" """
import logging import logging
import os import os
...@@ -11,8 +10,8 @@ ...@@ -11,8 +10,8 @@
from .docker_client import DockerClient from .docker_client import DockerClient
from .parsing import apply, basic_parser from .parsing import apply, basic_parser
__version__ = "1.0.1" __version__ = "1.0.0"
__date__ = "2022-02-17" __date__ = "2022-03-03"
__updated__ = "2022-03-03" __updated__ = "2022-03-03"
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
...@@ -16,8 +15,8 @@ ...@@ -16,8 +15,8 @@
__updated__ = "2022-03-03" __updated__ = "2022-03-03"
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
_PRETTIER_DEST = "prettier" _BLACK_DEST = "black"
"""Name of destination variable used for prettier in parsing""" """Name of destination variable used for black in parsing"""
def __parser(): def __parser():
...@@ -21,14 +20,9 @@ ...@@ -21,14 +20,9 @@
def __parser(): def __parser():
program_version = __version__ program_version_message = f"%(prog)s {__version__} ({__updated__})"
program_build_date = str(__updated__) program_short_description = __doc__.split(".", maxsplit=1)[0]
program_version_message = "%%(prog)s %s (%s)" % ( program_license = f"""{program_short_description}
program_version,
program_build_date,
)
program_shortdesc = __doc__.split(".", maxsplit=1)[0]
program_license = f"""{program_shortdesc}
Created by Vincent Hatakeyama on {__date__}. Created by Vincent Hatakeyama on {__date__}.
Copyright 2022 XCG Consulting. All rights reserved. Copyright 2022 XCG Consulting. All rights reserved.
...@@ -45,7 +39,7 @@ ...@@ -45,7 +39,7 @@
parser.add_argument( parser.add_argument(
help="Run pylint on given directory (relative path, for example " help="Run pylint on given directory (relative path, for example "
"github.com/OCA/server-auth)", "github.com/OCA/server-auth)",
dest=_PRETTIER_DEST, dest=_BLACK_DEST,
) )
parser.add_argument( parser.add_argument(
"--write", "--write",
...@@ -62,8 +56,6 @@ ...@@ -62,8 +56,6 @@
add_build_options(parser) add_build_options(parser)
nmspc = parser.parse_args(argv) nmspc = parser.parse_args(argv)
apply(nmspc) apply(nmspc)
return prettier( return black(getattr(nmspc, _BLACK_DEST), nmspc.write, get_build_options(nmspc))
getattr(nmspc, _PRETTIER_DEST), nmspc.write, get_build_options(nmspc)
)
...@@ -68,7 +60,7 @@ ...@@ -68,7 +60,7 @@
def prettier(directory: str, write: bool, build_options, pull: bool = True): def black(directory: str, write: bool, build_options, pull: bool = True):
"""Run prettier""" """Run black"""
config = Config() config = Config()
build_local_image(build_options) build_local_image(build_options)
...@@ -91,11 +83,11 @@ ...@@ -91,11 +83,11 @@
} }
command = ["."] command = ["."]
if write: if not write:
command.append("--write") command.extend(("--check", "--diff"))
_logger.info("Running prettier in %s", path) _logger.info("Running prettier in %s", path)
return DockerClient.run( return DockerClient.run(
config.local_image, config.local_image,
config.local_tag, config.local_tag,
{ {
...@@ -96,10 +88,10 @@ ...@@ -96,10 +88,10 @@
_logger.info("Running prettier in %s", path) _logger.info("Running prettier in %s", path)
return DockerClient.run( return DockerClient.run(
config.local_image, config.local_image,
config.local_tag, config.local_tag,
{ {
"entrypoint": "prettier", "entrypoint": "black",
"user": os.getuid(), "user": os.getuid(),
"command": command, "command": command,
"volumes": volumes, "volumes": volumes,
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
__updated__ = "2022-03-03" __updated__ = "2022-03-03"
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
_PRETTIER_DEST = "prettier" _PRETTIER_DEST = "prettier"
"""Name of destination variable used for prettier in parsing""" """Name of destination variable used for prettier in parsing"""
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
"import_sql=odoo_scripts.import_sql:main [import_sql]", "import_sql=odoo_scripts.import_sql:main [import_sql]",
"docker_dev_start=odoo_scripts.docker_dev_start:main [docker]", "docker_dev_start=odoo_scripts.docker_dev_start:main [docker]",
"do_tests=odoo_scripts.do_tests:main", "do_tests=odoo_scripts.do_tests:main",
"docker_black=odoo_scripts.docker_black:main [docker]",
"docker_build=odoo_scripts.docker_build:main [docker]", "docker_build=odoo_scripts.docker_build:main [docker]",
"docker_build_clean=odoo_scripts.docker_build_clean:main", "docker_build_clean=odoo_scripts.docker_build_clean:main",
"docker_build_copy=odoo_scripts.docker_build_copy:main", "docker_build_copy=odoo_scripts.docker_build_copy:main",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment