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

:sparkles: Also mount songs when running pylint with docker_pylint

parent fcec01f8b0e2
No related branches found
No related tags found
1 merge request!111✨ Also mount songs when running pylint with docker_pylint
This commit is part of merge request !111. Comments created here will be created in the context of that merge request.
...@@ -2,6 +2,11 @@ ...@@ -2,6 +2,11 @@
History History
======= =======
16.3.0
------
Also mount songs when running pylint with ``docker_pylint``.
16.2.0 16.2.0
------ ------
......
"""Class that encapsulate the docker client""" """Class that encapsulate the docker client and provide common methods"""
import atexit import atexit
import logging import logging
import os import os
...@@ -202,3 +202,24 @@ ...@@ -202,3 +202,24 @@
mount_dict[full_target_path] = full_project_path mount_dict[full_target_path] = full_project_path
return mount_list, mount_dict return mount_list, mount_dict
def anthem_mounts(project_path: str, pythons: tuple[str]) -> List[Mount]:
"""Return a list of monts for all the anthem songs present in the super project."""
mounts: List[Mount] = []
# also mount songs for anthem to avoid having to rebuild the image when they
# are changed.
if os.path.exists("songs"):
for root, dirs, _files in os.walk("songs"):
for directory in dirs:
# with older odoo this will not be set
for python in pythons:
mounts.append(
Mount(
f"/usr/local/lib/{python}/dist-packages/{root}/{directory}",
os.path.join(project_path, root, directory),
"bind",
read_only=True,
)
)
return mounts
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
Config, Config,
) )
from .docker_build import add_build_options, build_local_image, get_build_options from .docker_build import add_build_options, build_local_image, get_build_options
from .docker_client import DockerClient, modules_mount from .docker_client import DockerClient, anthem_mounts, modules_mount
from .docker_flake8 import apply_flake8, parser_add_flake8_group from .docker_flake8 import apply_flake8, parser_add_flake8_group
from .docker_isort import apply_isort, parser_add_isort_group from .docker_isort import apply_isort, parser_add_isort_group
from .docker_postgresql import POSTGRES_PASSWORD, docker_run_postgresql from .docker_postgresql import POSTGRES_PASSWORD, docker_run_postgresql
...@@ -956,21 +956,7 @@ ...@@ -956,21 +956,7 @@
read_only=True, read_only=True,
) )
) )
# also mount songs for anthem to avoid having to rebuild the image when they mounts.extend(anthem_mounts(project_path, pythons))
# are changed.
if os.path.exists("songs"):
for root, dirs, _files in os.walk("songs"):
for dir in dirs:
# with older odoo this will not be set
for python in pythons:
mounts.append(
Mount(
f"/usr/local/lib/{python}/dist-packages/{root}/{dir}",
os.path.join(project_path, root, dir),
"bind",
read_only=True,
)
)
options["environment"].update( options["environment"].update(
{ {
......
...@@ -10,5 +10,5 @@ ...@@ -10,5 +10,5 @@
from docker.types import Mount from docker.types import Mount
from .config import ODOO_15, Config from .config import ODOO_7, ODOO_8, ODOO_10, ODOO_11, ODOO_13, ODOO_15, Config
from .docker_build import add_build_options, build_local_image, get_build_options from .docker_build import add_build_options, build_local_image, get_build_options
...@@ -14,4 +14,4 @@ ...@@ -14,4 +14,4 @@
from .docker_build import add_build_options, build_local_image, get_build_options from .docker_build import add_build_options, build_local_image, get_build_options
from .docker_client import DockerClient, modules_mount from .docker_client import DockerClient, anthem_mounts, modules_mount
from .parsing import apply, basic_parser from .parsing import apply, basic_parser
...@@ -16,4 +16,4 @@ ...@@ -16,4 +16,4 @@
from .parsing import apply, basic_parser from .parsing import apply, basic_parser
__version__ = "1.0.0" __version__ = "1.1.0"
__date__ = "2022-01-26" __date__ = "2022-01-26"
...@@ -19,5 +19,5 @@ ...@@ -19,5 +19,5 @@
__date__ = "2022-01-26" __date__ = "2022-01-26"
__updated__ = "2022-01-27" __updated__ = "2022-04-20"
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
...@@ -26,12 +26,7 @@ ...@@ -26,12 +26,7 @@
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 = """%s
...@@ -37,5 +32,5 @@ ...@@ -37,5 +32,5 @@
Created by Vincent Hatakeyama on %s. Created by Vincent Hatakeyama on {__date__}.
Copyright 2022 XCG Consulting. All rights reserved. Copyright 2022 XCG Consulting. All rights reserved.
Licensed under the MIT License Licensed under the MIT License
...@@ -44,10 +39,7 @@ ...@@ -44,10 +39,7 @@
or conditions of any kind, either express or implied. or conditions of any kind, either express or implied.
USAGE USAGE
""" % ( """
program_shortdesc,
str(__date__),
)
parser = basic_parser(program_license, program_version_message) parser = basic_parser(program_license, program_version_message)
return parser return parser
...@@ -86,5 +78,5 @@ ...@@ -86,5 +78,5 @@
project_path = os.path.realpath(".") project_path = os.path.realpath(".")
# always use project image # always use project image
c = Config() config = Config()
...@@ -90,8 +82,8 @@ ...@@ -90,8 +82,8 @@
odoo_type = c.odoo_type odoo_type = config.odoo_type
mounts: List[Mount] = [] mounts: List[Mount] = []
environment = {} environment = {}
target_source_dict: Dict[str, str] = {} target_source_dict: Dict[str, str] = {}
# odoo configuration is not read so put the modules in the path # odoo configuration is not read so put the modules in the path
...@@ -92,9 +84,9 @@ ...@@ -92,9 +84,9 @@
mounts: List[Mount] = [] mounts: List[Mount] = []
environment = {} environment = {}
target_source_dict: Dict[str, str] = {} target_source_dict: Dict[str, str] = {}
# odoo configuration is not read so put the modules in the path # odoo configuration is not read so put the modules in the path
if odoo_type in ("odoo10", "odoo11", "odoo13", ODOO_15): if odoo_type in (ODOO_10, ODOO_11, ODOO_13, ODOO_15):
if odoo_type == "odoo10": if odoo_type == ODOO_10:
pythons = ("python2.7",) pythons = ("python2.7",)
...@@ -100,3 +92,3 @@ ...@@ -100,3 +92,3 @@
pythons = ("python2.7",) pythons = ("python2.7",)
elif odoo_type == "odoo11": elif odoo_type == ODOO_11:
pythons = ("python3.5", "python3.6") pythons = ("python3.5", "python3.6")
...@@ -102,7 +94,7 @@ ...@@ -102,7 +94,7 @@
pythons = ("python3.5", "python3.6") pythons = ("python3.5", "python3.6")
elif odoo_type == "odoo13": elif odoo_type == ODOO_13:
pythons = ("python3.8",) pythons = ("python3.8",)
elif odoo_type == ODOO_15: elif odoo_type == ODOO_15:
pythons = ("python3.9",) pythons = ("python3.9",)
for python in pythons: for python in pythons:
result = modules_mount( result = modules_mount(
...@@ -104,11 +96,11 @@ ...@@ -104,11 +96,11 @@
pythons = ("python3.8",) pythons = ("python3.8",)
elif odoo_type == ODOO_15: elif odoo_type == ODOO_15:
pythons = ("python3.9",) pythons = ("python3.9",)
for python in pythons: for python in pythons:
result = modules_mount( result = modules_mount(
c.modules, config.modules,
project_path, project_path,
f"/usr/local/lib/{python}/dist-packages/odoo/addons", f"/usr/local/lib/{python}/dist-packages/odoo/addons",
) )
mounts.extend(result[0]) mounts.extend(result[0])
target_source_dict.update(result[1]) target_source_dict.update(result[1])
...@@ -110,7 +102,7 @@ ...@@ -110,7 +102,7 @@
project_path, project_path,
f"/usr/local/lib/{python}/dist-packages/odoo/addons", f"/usr/local/lib/{python}/dist-packages/odoo/addons",
) )
mounts.extend(result[0]) mounts.extend(result[0])
target_source_dict.update(result[1]) target_source_dict.update(result[1])
elif odoo_type in ("odoo7", "odoo8"): elif odoo_type in (ODOO_7, ODOO_8):
mounts, target_source_dict = modules_mount( mounts, target_source_dict = modules_mount(
...@@ -116,5 +108,5 @@ ...@@ -116,5 +108,5 @@
mounts, target_source_dict = modules_mount( mounts, target_source_dict = modules_mount(
c.modules, project_path, "/opt/odoo/sources/odoo/addons" config.modules, project_path, "/opt/odoo/sources/odoo/addons"
) )
# Add a volume to store cache # Add a volume to store cache
...@@ -124,7 +116,9 @@ ...@@ -124,7 +116,9 @@
mounts.append(Mount(cache_target_path, cache_volume_name)) mounts.append(Mount(cache_target_path, cache_volume_name))
environment["PYLINTHOME"] = cache_target_path environment["PYLINTHOME"] = cache_target_path
mounts.extend(anthem_mounts(project_path, pythons))
build_local_image(build_options) build_local_image(build_options)
_logger.info("Running pylint") _logger.info("Running pylint")
return DockerClient.run( return DockerClient.run(
...@@ -127,9 +121,9 @@ ...@@ -127,9 +121,9 @@
build_local_image(build_options) build_local_image(build_options)
_logger.info("Running pylint") _logger.info("Running pylint")
return DockerClient.run( return DockerClient.run(
c.local_image, config.local_image,
c.local_tag, config.local_tag,
{ {
"entrypoint": "pylint", "entrypoint": "pylint",
"command": modules + ["--load-plugins=pylint_odoo"], "command": modules + ["--load-plugins=pylint_odoo"],
......
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