# HG changeset patch # User Vincent Hatakeyama <vincent.hatakeyama@xcg-consulting.fr> # Date 1643107388 -3600 # Tue Jan 25 11:43:08 2022 +0100 # Node ID b4dd490c61c89db491eef8a715ced2f7b194037b # Parent a467c19eedbf8ce0bbaeee53be4e5f0888b42160 👕 Use black default line length diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -130,4 +130,3 @@ script: - DOCKER_BASE_IMAGE_NAME="$TEMP_IMAGE" tag-img - DOCKER_BASE_IMAGE_NAME="$TEMP_IMAGE" DOCKER_IMAGE="xcgd/odoo_scripts" tag-img - diff --git a/NEWS.rst b/NEWS.rst --- a/NEWS.rst +++ b/NEWS.rst @@ -9,6 +9,8 @@ Explicitly disable base import with version it is not tested (it did not work with 13.0 anyway). +Use black default line length. + 14.0.0 ------ diff --git a/doc/autotodo.py b/doc/autotodo.py --- a/doc/autotodo.py +++ b/doc/autotodo.py @@ -53,9 +53,7 @@ path = i[0] line = i[1] lines = (line - 3, line + 4) - class_name = ":class:`%s`" % os.path.basename( - os.path.splitext(path)[0] - ) + class_name = ":class:`%s`" % os.path.basename(os.path.splitext(path)[0]) f.write( "%s\n" "%s\n\n" diff --git a/odoo_scripts/conf2reST.py b/odoo_scripts/conf2reST.py --- a/odoo_scripts/conf2reST.py +++ b/odoo_scripts/conf2reST.py @@ -48,9 +48,7 @@ str(__date__), ) # Argument parsing - parser = basic_parser( - description=program_license, version=program_version_message - ) + parser = basic_parser(description=program_license, version=program_version_message) parser.add_argument( "-d", "--directory", @@ -75,8 +73,7 @@ setup_path = os.path.join(directory, "setup.cfg") parser.read(setup_path) addon_dirs = set( - os.path.dirname(path) - for path in parser.get("odoo_scripts", "modules").split() + os.path.dirname(path) for path in parser.get("odoo_scripts", "modules").split() ) # pip3 freeze @@ -118,9 +115,7 @@ if parser.has_option(section, "track"): rst[group][section]["version"] = parser.get(section, "track") if parser.has_option(section, "repository"): - rst[group][section]["repository"] = parser.get( - section, "pulluri" - ) + rst[group][section]["repository"] = parser.get(section, "pulluri") # handle nest.yaml case confnest_path = os.path.join(directory, "nest.yaml") diff --git a/odoo_scripts/config.py b/odoo_scripts/config.py --- a/odoo_scripts/config.py +++ b/odoo_scripts/config.py @@ -37,18 +37,14 @@ _logger.warning("Missing %s", setup_path) else: config_parser.read(setup_path) - section = ( - config_parser[SECTION] if SECTION in config_parser else dict() - ) + section = config_parser[SECTION] if SECTION in config_parser else dict() # read expanded configurations information expanded_info = defaultdict(dict) for key in section: if key.startswith("expand."): remaining_key = key.split(".")[1:] - expanded_info[remaining_key[0]][ - remaining_key[1] - ] = section.get(key) + expanded_info[remaining_key[0]][remaining_key[1]] = section.get(key) for name, value in expanded_info.items(): value["parent_configuration"] = self @@ -64,9 +60,7 @@ relative_path = os.path.join( os.path.relpath( path, - parent_configuration.path - if parent_configuration.path - else "", + parent_configuration.path if parent_configuration.path else "", ), value["path"], ) @@ -75,9 +69,7 @@ if blacklist and re.match(blacklist, relative_path): _logger.info( "Ignoring directory '%s' due to blacklisting", - os.path.join(path, value["path"]) - if path - else value["path"], + os.path.join(path, value["path"]) if path else value["path"], ) else: if path: @@ -122,9 +114,7 @@ values = section.get(key, "").split() # XXX eventually add option to not include path set_values.update( - set_from_glob_values( - path, values, key != OTHER_SOURCES_KEY - ) + set_from_glob_values(path, values, key != OTHER_SOURCES_KEY) ) setattr(self, key, list(set_values)) @@ -172,11 +162,7 @@ found = True if key in section: local_value = section.get(key, default_value) - if ( - found - and value != default_value - and local_value != value - ): + if found and value != default_value and local_value != value: raise Exception( "Key %s in expanded configuration and locally set" " with different values" % key @@ -223,9 +209,7 @@ def __call__(cls, *args, **kwargs): if cls not in cls._instances: - cls._instances[cls] = super(Singleton, cls).__call__( - *args, **kwargs - ) + cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs) return cls._instances[cls] diff --git a/odoo_scripts/do_tests.py b/odoo_scripts/do_tests.py --- a/odoo_scripts/do_tests.py +++ b/odoo_scripts/do_tests.py @@ -57,9 +57,7 @@ # TODO add a way to store configuration options in a project file # Argument parsing - parser = basic_parser( - description=program_license, version=program_version_message - ) + parser = basic_parser(description=program_license, version=program_version_message) docker_group = parser.add_mutually_exclusive_group() docker_group.add_argument( "--docker", @@ -109,9 +107,7 @@ default=None, choices=odoo_log_levels, ) - parser.add_argument( - "--no-create-database", dest="createdb", action="store_false" - ) + parser.add_argument("--no-create-database", dest="createdb", action="store_false") parser.add_argument( "-i", "--install", @@ -142,8 +138,7 @@ ) parser.add_argument( "--load-language", - help="specifies the languages for the translations you want to be" - " loaded", + help="specifies the languages for the translations you want to be" " loaded", default=None, dest="LOAD_LANGUAGE", ) @@ -159,12 +154,8 @@ odoo_db_user = nmspc.db_user odoo_db_password = nmspc.db_password recreate_db = nmspc.createdb - install_log_level = ( - nmspc.log_level if nmspc.log_level else nmspc.install_log_level - ) - test_log_level = ( - nmspc.log_level if nmspc.log_level else nmspc.test_log_level - ) + install_log_level = nmspc.log_level if nmspc.log_level else nmspc.install_log_level + test_log_level = nmspc.log_level if nmspc.log_level else nmspc.test_log_level override_installed_module = nmspc.install override_tested_module = nmspc.test dbport = nmspc.dbport @@ -197,9 +188,7 @@ if not odoo_db_password: if c.has_option("options", "db_password"): odoo_db_password = c.get("options", "db_password") - if c.has_option("options", "unaccent") and c.getboolean( - "options", "unaccent" - ): + if c.has_option("options", "unaccent") and c.getboolean("options", "unaccent"): extensions.append("unaccent") else: _logger.debug("No sample configuration %s", sample_conf) @@ -286,8 +275,7 @@ # not injection safe but you are on your own machine # with already full access to db cursor.execute( - "CREATE ROLE %s LOGIN CREATEDB PASSWORD %%s" - % odoo_db_user, + "CREATE ROLE %s LOGIN CREATEDB PASSWORD %%s" % odoo_db_user, (odoo_db_password,), ) connection.commit() @@ -300,9 +288,7 @@ _logger.debug("Drop database %s", dbname) cursor.execute('DROP DATABASE IF EXISTS "%s"' % dbname) _logger.debug("Create database %s", dbname) - cursor.execute( - 'CREATE DATABASE "%s" OWNER %s' % (dbname, odoo_db_user) - ) + cursor.execute('CREATE DATABASE "%s" OWNER %s' % (dbname, odoo_db_user)) odoo_connection = connect( user=pg_user, database=dbname, host=socket_path, port=5432 ) diff --git a/odoo_scripts/docker_build.py b/odoo_scripts/docker_build.py --- a/odoo_scripts/docker_build.py +++ b/odoo_scripts/docker_build.py @@ -78,15 +78,13 @@ ) parser.add_argument( "--build-arg", - help="build arg for the image, formated like FOO=BAR " - "[default: %(default)s]", + help="build arg for the image, formatted like FOO=BAR [default: %(default)s]", default=None, nargs="*", ) parser.add_argument( "--no-pull", - help="indicate to docker to not pull the base image " - "[default: %(default)s]", + help="indicate to docker to not pull the base image [default: %(default)s]", action="store_true", ) # TODO (maybe) add argument for other build arg @@ -128,12 +126,8 @@ buildargs["SENTRY_RELEASE"] = tags if tags: tags = tags.split() - buildargs["VCS_URL"] = check_output( - ["hg", "paths", "default"] - ).decode() - buildargs["VCS_REF"] = check_output( - ["hg", "identify", "--id"] - ).decode() + buildargs["VCS_URL"] = check_output(["hg", "paths", "default"]).decode() + buildargs["VCS_REF"] = check_output(["hg", "identify", "--id"]).decode() buildargs["BUILD_DATE"] = datetime.datetime.now().isoformat() if nmspc.build_arg: for arg in nmspc.build_arg: @@ -146,16 +140,11 @@ call(["cp", dockerfile, debug_dockerfile]) with open(debug_dockerfile, "a") as myfile: - myfile.write( - "\n# Developer helpers\nUSER root\nRUN apt-get update -qq\n" - ) - myfile.write( - "RUN DEBIAN_FRONTEND=noninteractive apt-get install -y -qq " - ) + myfile.write("\n# Developer helpers\nUSER root\nRUN apt-get update -qq\n") + myfile.write("RUN DEBIAN_FRONTEND=noninteractive apt-get install -y -qq ") if odoo_type in ("odoo11", "odoo13", "odoo15"): myfile.write( - "python3-watchdog python3-ipdb python3-pyinotify " - "python3-wheel\n" + "python3-watchdog python3-ipdb python3-pyinotify " "python3-wheel\n" ) # newer setuptools_scm>6 is not compatible with python 3.5 due # to the use of f-strings @@ -206,9 +195,7 @@ if push: _logger.info("Docker push %s", repository) - for line in docker_client.images.push( - repository, stream=True, decode=True - ): + for line in docker_client.images.push(repository, stream=True, decode=True): _logger.debug(line) for tag in tags: _logger.info("Docker push %s:%s", repository, tag) diff --git a/odoo_scripts/docker_client.py b/odoo_scripts/docker_client.py --- a/odoo_scripts/docker_client.py +++ b/odoo_scripts/docker_client.py @@ -8,9 +8,7 @@ _logger = logging.getLogger(__name__) if docker.__version__ < "3.4.0": - _logger.warning( - "Unexepected python docker version: %s", docker.__version__ - ) + _logger.warning("Unexepected python docker version: %s", docker.__version__) # TODO detect that user is member of docker group diff --git a/odoo_scripts/docker_dev_start.py b/odoo_scripts/docker_dev_start.py --- a/odoo_scripts/docker_dev_start.py +++ b/odoo_scripts/docker_dev_start.py @@ -69,9 +69,7 @@ # TODO add a way to store configuration options in a project file # Argument parsing - parser = basic_parser( - description=program_license, version=program_version_message - ) + parser = basic_parser(description=program_license, version=program_version_message) parser.add_argument( "--name", help="Container name to use [default: %(default)s]", @@ -100,9 +98,7 @@ help="Database [default: %(default)s]", default=None, ) - parser.add_argument( - "-p", "--dbport", help="Change database port", default=None - ) + parser.add_argument("-p", "--dbport", help="Change database port", default=None) group = parser.add_mutually_exclusive_group() group.add_argument( "-u", @@ -440,8 +436,7 @@ local_ip = addresses[0] except ImportError: _logger.warn( - "Consider installing python netifaces" - " to ease local IP detection" + "Consider installing python netifaces" " to ease local IP detection" ) if not local_ip: import socket @@ -522,9 +517,7 @@ "/usr/local/lib/python2.7/dist-packages/" "openerp-7.0-py2.7.egg/openerp/data" ) - filestore_volume_name = "{}{}".format( - base_data_volume_name, "_filestore" - ) + filestore_volume_name = "{}{}".format(base_data_volume_name, "_filestore") client.create_volume(filestore_volume_name, {"mounted in": target}) mounts.append(target, filestore_volume_name) else: @@ -538,9 +531,7 @@ chown_directories = ["/mnt"] if odoo_type not in ("odoo7", "odoo8"): chown_directories.append("/var/lib/odoo") - _logger.info( - "chown container’s %s to Odoo user", ", ".join(chown_directories) - ) + _logger.info("chown container’s %s to Odoo user", ", ".join(chown_directories)) client.containers.run( image, command=["odoo", "--recursive"] + chown_directories, @@ -573,9 +564,7 @@ else: extra_volumes = ["/var/lib/odoo"] for extra_volume in extra_volumes: - volume_name = "{}_{}".format( - project_name, extra_volume.replace("/", "_") - ) + volume_name = "{}_{}".format(project_name, extra_volume.replace("/", "_")) DockerClient.create_volume( volume_name, { @@ -606,13 +595,9 @@ if not odoo_help: if start_postgresql: if db_host: - _logger.warning( - "Ignoring given db_host when starting postgres" - ) + _logger.warning("Ignoring given db_host when starting postgres") if dbport: - _logger.warning( - "Ignoring given db_port when starting postgres" - ) + _logger.warning("Ignoring given db_port when starting postgres") db_host = "/var/run/postgresql" dbport = 5432 # Use socket rather than export port (avoid having to find a @@ -685,9 +670,7 @@ else: _logger.fatal("Cannot connect to database with user %s", user) _logger.fatal(exception) - _logger.info( - "You can add the --create-user argument to create it" - ) + _logger.info("You can add the --create-user argument to create it") return 16 arg.append("--db_host") @@ -735,9 +718,7 @@ if pre_sql_script: if start_postgresql: pre_sql_script_basename = os.path.basename(pre_sql_script) - _logger.info( - "Copying SQL script %s in docker", pre_sql_script_basename - ) + _logger.info("Copying SQL script %s in docker", pre_sql_script_basename) inside_pre_sql_script = "/tmp/{}".format(pre_sql_script_basename) client.put_file(pre_sql_script, pg, inside_pre_sql_script) _logger.info( @@ -757,20 +738,14 @@ ] ) if exit_code > 0: - _logger.fatal( - "Error when running SQL script %s", pre_sql_script - ) + _logger.fatal("Error when running SQL script %s", pre_sql_script) return 16 _logger.info("Removing SQL script %s in docker", pre_sql_script) # remove script pg.exec_run(["rm", inside_pre_sql_script]) else: - _logger.info( - "Running SQL script %s in %s", pre_sql_script, database - ) - script = call( - ["psql", "-U", user, "-d", database, "-f", pre_sql_script] - ) + _logger.info("Running SQL script %s in %s", pre_sql_script, database) + script = call(["psql", "-U", user, "-d", database, "-f", pre_sql_script]) if script > 0: _logger.fatal("Error when running SQL script %s", script) return 16 @@ -850,20 +825,15 @@ ) mounts.append( Mount( - "/usr/local/lib/%s/dist-packages/odoo/addons/base" - % python, + "/usr/local/lib/%s/dist-packages/odoo/addons/base" % python, os.path.join(odoo_sources, "odoo", "addons", "base"), "bind", ) ) elif odoo_type in ("odoo7", "odoo8"): - mounts.append( - Mount("/opt/odoo/sources/odoo", odoo_sources, "bind") - ) + mounts.append(Mount("/opt/odoo/sources/odoo", odoo_sources, "bind")) else: - raise Exception( - "Unexpected odoo_type when binding sources: %s" % odoo_type - ) + raise Exception("Unexpected odoo_type when binding sources: %s" % odoo_type) # avoid chowning at each run, faster but can cause trouble # newer odoo images does not use this environment variable anymore diff --git a/odoo_scripts/docker_isort.py b/odoo_scripts/docker_isort.py --- a/odoo_scripts/docker_isort.py +++ b/odoo_scripts/docker_isort.py @@ -109,9 +109,7 @@ try: client.images.pull(repository=repository, tag=tag) except docker.errors.APIError: - _logger.warning( - "No connection to server, using existing version, if any" - ) + _logger.warning("No connection to server, using existing version, if any") _logger.info("Running isort for Odoo (%s)", image) container = None diff --git a/odoo_scripts/docker_postgresql.py b/odoo_scripts/docker_postgresql.py --- a/odoo_scripts/docker_postgresql.py +++ b/odoo_scripts/docker_postgresql.py @@ -50,9 +50,7 @@ name = "postgresql-{}-{}".format(postgresql_version, project_name) # need to pull otherwise the containers.create might fail docker_client.images.pull(repository=pg_repository, tag=version) - pg_data_volume_name = "postgresql_{}-{}".format( - postgresql_version, project_name - ) + pg_data_volume_name = "postgresql_{}-{}".format(postgresql_version, project_name) path: str = None env = dict() env["POSTGRES_PASSWORD"] = POSTGRES_PASSWORD @@ -68,9 +66,7 @@ _logger.info("Removing postgresql container %s", pg_container.name) pg_container.remove() except docker.errors.NotFound: - _logger.info( - "Postgresql container %s already stopped", pg_container.name - ) + _logger.info("Postgresql container %s already stopped", pg_container.name) # crash because docker or pg changes the owner of the directory # temp_directory.cleanup() @@ -92,9 +88,7 @@ if host_pg_port: port_bindings[5432] = host_pg_port else: - path = tempfile.TemporaryDirectory( - prefix="odoo_scripts_postgres_socket-" - ).name + path = tempfile.TemporaryDirectory(prefix="odoo_scripts_postgres_socket-").name volumes[path] = {"bind": "/var/run/postgresql", "mode": "rw"} _logger.debug("Creating postgresql container") pg = docker_client.containers.create( diff --git a/odoo_scripts/docker_py3o.py b/odoo_scripts/docker_py3o.py --- a/odoo_scripts/docker_py3o.py +++ b/odoo_scripts/docker_py3o.py @@ -33,14 +33,11 @@ fusion_image = "{}:{}".format(fusion_repository, fusion_version) try: _logger.debug("Pulling %s", fusion_repository) - docker_client.images.pull( - repository=fusion_repository, tag=fusion_version - ) + docker_client.images.pull(repository=fusion_repository, tag=fusion_version) except Exception as e: _logger.warning("Exception when trying to pull: %s", e) if any( - fusion_name == container.name - for container in docker_client.containers.list() + fusion_name == container.name for container in docker_client.containers.list() ): _logger.debug("%s Container already running", fusion_name) remove_and_stop(docker_client, fusion_name) diff --git a/odoo_scripts/import_base_import.py b/odoo_scripts/import_base_import.py --- a/odoo_scripts/import_base_import.py +++ b/odoo_scripts/import_base_import.py @@ -11,10 +11,7 @@ from requests_toolbelt import MultipartEncoder from . import odoo_connect_parser, odoo_login -from .importing import ( - add_importing_file_parsing, - extract_model_lang_from_parsed, -) +from .importing import add_importing_file_parsing, extract_model_lang_from_parsed from .parsing import apply _logger = logging.getLogger(__name__) @@ -35,13 +32,9 @@ model_filenames: List[Dict[str, str]], update_parameter: bool = True, ) -> int: - o, session_id = odoo_login( - database, host, login, password, port, protocol, timeout - ) + o, session_id = odoo_login(database, host, login, password, port, protocol, timeout) if o.version not in ("11.0",): - _logger.fatal( - "Base Import is not compatible with version %s", o.version - ) + _logger.fatal("Base Import is not compatible with version %s", o.version) return 2 import_obj = o.env["base_import.import"] @@ -74,16 +67,12 @@ model = element["model"] csv_file = element["filename"] lang = element["lang"] - _logger.info( - "Importing - %s in model %s (lang %s)", csv_file, model, lang - ) + _logger.info("Importing - %s in model %s (lang %s)", csv_file, model, lang) context = { "lang": lang, # TODO add tz maybe } - import_dlg_id = import_obj.create( - {"res_model": model}, context=context - ) + import_dlg_id = import_obj.create({"res_model": model}, context=context) with open(csv_file, "rb") as f: m = MultipartEncoder( fields={ @@ -101,22 +90,16 @@ # in Odoo, context contains user lang, but that is ok so far _logger.debug("response: %s", response) # This returns a lot of stuff we don't need, except for the field list. - fields = import_obj.parse_preview(import_dlg_id, import_options)[ - "headers" - ] + fields = import_obj.parse_preview(import_dlg_id, import_options)["headers"] # Got fields; now run the import. errors = list() # this is where setting the context is necessary - results = import_obj.do( - import_dlg_id, fields, import_options, context=context - ) + results = import_obj.do(import_dlg_id, fields, import_options, context=context) for result in results: if result["type"] == "error": errors.append(result["message"]) if errors: - _logger.fatal( - "Error while importing - %s in model %s:", csv_file, model - ) + _logger.fatal("Error while importing - %s in model %s:", csv_file, model) for error in errors: _logger.warning(" - %s", error) return 1 @@ -125,9 +108,7 @@ if update_parameter: _logger.debug("Setting import_csv parameter") - param_obj.set_param( - "import_base_import.write_date", str(datetime.now()) - ) + param_obj.set_param("import_base_import.write_date", str(datetime.now())) _logger.info("Done.") return 0 diff --git a/odoo_scripts/import_jsonrpc.py b/odoo_scripts/import_jsonrpc.py --- a/odoo_scripts/import_jsonrpc.py +++ b/odoo_scripts/import_jsonrpc.py @@ -11,18 +11,15 @@ from dateutil.parser import isoparse from odoorpc.error import RPCError -from .importing import ( - add_importing_file_parsing, - extract_model_lang_from_parsed, -) +from .importing import add_importing_file_parsing, extract_model_lang_from_parsed from .odoo import odoo_connect_parser, odoo_login from .parsing import apply _logger = logging.getLogger(__name__) -__version__ = "1.2.0" +__version__ = "1.2.1" __date__ = "2020-02-17" -__updated__ = "2022-01-17" +__updated__ = "2022-01-25" def import_with_jsonrpc( @@ -35,13 +32,13 @@ timeout: int, model_filenames: List[Dict[str, str]], delimiter: str = ",", - extra_context: Dict[str, str] = dict(), + extra_context: Dict[str, str] = None, allow_import_errors: bool = False, allow_missing_refs: bool = False, ) -> int: - o, session_id = odoo_login( - database, host, login, password, port, protocol, timeout - ) + if extra_context is None: + extra_context = {} + o, session_id = odoo_login(database, host, login, password, port, protocol, timeout) imd = o.env["ir.model.data"] imf = o.env["ir.model.fields"] @@ -69,15 +66,11 @@ [("name", "=", xml_id), ("module", "=", module)] ) record_id = ( - imd.read(imd_id, ["res_id"])[0]["res_id"] - if imd_id - else None + imd.read(imd_id, ["res_id"])[0]["res_id"] if imd_id else None ) else: full_xmlid = xmlid if "." in xmlid else "." + xmlid - record_id = imd.xmlid_to_res_id( - full_xmlid, raise_if_not_found - ) + record_id = imd.xmlid_to_res_id(full_xmlid, raise_if_not_found) except RPCError as error: if allow_missing_refs: _logger.warning(str(error)) @@ -88,9 +81,7 @@ return xmlid_cache[xmlid] def _get_imf(model: str, field_name: str): - imf_ids = imf.search( - [("model", "=", model), ("name", "=", field_name)] - ) + imf_ids = imf.search([("model", "=", model), ("name", "=", field_name)]) if not imf_ids: raise Exception("No field {} in {}".format(field_name, model)) return imf.browse(imf_ids)[0] @@ -162,9 +153,7 @@ model = element["model"] csv_file = element["filename"] lang = element["lang"] - _logger.info( - "Importing - %s in model %s (lang %s)", csv_file, model, lang - ) + _logger.info("Importing - %s in model %s (lang %s)", csv_file, model, lang) yaml_filename = path.join(path.dirname(csv_file), "import.yaml") yaml_delimiter = old_context = None if path.exists(yaml_filename): @@ -211,9 +200,7 @@ _logger.debug("Reading from headers") for column_name in row.keys(): odoo_field_name = column_name - if column_name.endswith("/id") or column_name.endswith( - ":id" - ): + if column_name.endswith("/id") or column_name.endswith(":id"): odoo_field_name = column_name[:-3] if odoo_field_name != "id": _logger.debug("%s: %s", model, odoo_field_name) @@ -294,9 +281,7 @@ _logger.error("Values (%s): %s", xmlid, values) raise if created_id and xmlid: - _logger.debug( - "Adding xmlid %s for %d", xmlid, created_id - ) + _logger.debug("Adding xmlid %s for %d", xmlid, created_id) imd.create( { "name": name, @@ -314,9 +299,7 @@ len(wrote), ) - _logger.info( - "%s: created %d, wrote %d", model, len(created), len(wrote) - ) + _logger.info("%s: created %d, wrote %d", model, len(created), len(wrote)) if import_errors: _logger.warning("%s: %d errors", model, len(import_errors)) with open(f"{csv_file}-errors.txt", "w") as error_f: @@ -364,9 +347,7 @@ parser.add_argument( "--delimiter", help="CSV delimiter [default: %(default)s]", default="," ) - parser.add_argument( - "--context", help="Extra context (key=value)", action="append" - ) + parser.add_argument("--context", help="Extra context (key=value)", action="append") parser.add_argument( "--allow-import-errors", help=( @@ -402,9 +383,7 @@ protocol=nmspc.protocol, timeout=nmspc.timeout, database=nmspc.database, - model_filenames=extract_model_lang_from_parsed( - nmspc, r"(.*/)?import\.yaml" - ), + model_filenames=extract_model_lang_from_parsed(nmspc, r"(.*/)?import\.yaml"), delimiter=nmspc.delimiter, extra_context=extra_context, allow_import_errors=nmspc.allow_import_errors, diff --git a/odoo_scripts/import_sql.py b/odoo_scripts/import_sql.py --- a/odoo_scripts/import_sql.py +++ b/odoo_scripts/import_sql.py @@ -6,10 +6,7 @@ import sys from typing import List, Tuple -from .importing import ( - add_importing_file_parsing, - extract_model_table_from_parsed, -) +from .importing import add_importing_file_parsing, extract_model_table_from_parsed from .postgres import postgres_apply, postgres_connect_parser _logger = logging.getLogger(__name__) @@ -50,17 +47,11 @@ # do Odoo model to table conversion # (same as _build_model_attributes) table = model.replace(".", "_") - _logger.info( - "Importing - %s in %s (table %s)", csv_file, model, table - ) + _logger.info("Importing - %s in %s (table %s)", csv_file, model, table) has_date_init = _column_exists(cur, "ir_model_data", "date_init") - has_date_update = _column_exists( - cur, "ir_model_data", "date_update" - ) + has_date_update = _column_exists(cur, "ir_model_data", "date_update") with open(csv_file, "r") as file: - reader = csv.DictReader( - file, delimiter=delimiter, quotechar='"' - ) + reader = csv.DictReader(file, delimiter=delimiter, quotechar='"') headers_check = False created = written = 0 for row in reader: @@ -69,9 +60,9 @@ _logger.debug("Checking headers") many2x_columns = list() for column_name in row.keys(): - if column_name.endswith( - "/id" - ) or column_name.endswith(":id"): + if column_name.endswith("/id") or column_name.endswith( + ":id" + ): many2x_columns.append(column_name) if many2x_columns: msg = ( @@ -99,9 +90,7 @@ imd_data = cur.fetchone() if imd_data: imd_id, res_id = imd_data - _logger.debug( - "Found id %d for xmlid %s", res_id, xmlid - ) + _logger.debug("Found id %d for xmlid %s", res_id, xmlid) # if the id exists, do an update query = ( "UPDATE {table} " @@ -134,8 +123,7 @@ ).format( table=table, columns=",".join( - ["create_date", "write_date"] - + list(row.keys()) + ["create_date", "write_date"] + list(row.keys()) ), data_placeholders=",".join( ["(now() at time zone 'UTC')"] * 2 @@ -176,12 +164,10 @@ ).format( table=table, columns=",".join( - ["create_date", "write_date"] - + list(row.keys()) + ["create_date", "write_date"] + list(row.keys()) ), data_placeholders=",".join( - ["(now() at time zone 'UTC')"] * 2 - + ["%s"] * len(row) + ["(now() at time zone 'UTC')"] * 2 + ["%s"] * len(row) ), ) _execute(cur, query, tuple(row.values())) @@ -193,9 +179,7 @@ created, written, ) - _logger.info( - "%s: created %d, wrote %d", csv_file, created, written - ) + _logger.info("%s: created %d, wrote %d", csv_file, created, written) connection.commit() _logger.info("Commited.") diff --git a/odoo_scripts/importing.py b/odoo_scripts/importing.py --- a/odoo_scripts/importing.py +++ b/odoo_scripts/importing.py @@ -30,13 +30,9 @@ r")" ) expected_filenames_pattern = ( - re.compile(expected_filenames) - if expected_filenames is not None - else None + re.compile(expected_filenames) if expected_filenames is not None else None ) - return extract_info_from_parsed( - namespace, pattern, expected_filenames_pattern - ) + return extract_info_from_parsed(namespace, pattern, expected_filenames_pattern) def extract_model_table_from_parsed( @@ -52,9 +48,7 @@ r")" ) expected_filenames_pattern = None - return extract_info_from_parsed( - namespace, pattern, expected_filenames_pattern - ) + return extract_info_from_parsed(namespace, pattern, expected_filenames_pattern) def extract_info_from_parsed( @@ -87,9 +81,7 @@ file_list.extend(files) if directories: for directory in directories: - for root, subdirectories, files in os.walk( - directory, followlinks=True - ): + for root, subdirectories, files in os.walk(directory, followlinks=True): subdirectories.sort() file_list.extend(os.path.join(root, f) for f in sorted(files)) @@ -99,15 +91,10 @@ if result: model_filenames.append(result.groupdict()) else: - if ( - expected_filenames_pattern - and expected_filenames_pattern.match(filename) + if expected_filenames_pattern and expected_filenames_pattern.match( + filename ): - _logger.debug( - 'Expected file name "%s" found, ignored', filename - ) + _logger.debug('Expected file name "%s" found, ignored', filename) else: - _logger.warning( - 'Unrecognized file name "%s", ignored', filename - ) + _logger.warning('Unrecognized file name "%s", ignored', filename) return model_filenames diff --git a/odoo_scripts/odoo.py b/odoo_scripts/odoo.py --- a/odoo_scripts/odoo.py +++ b/odoo_scripts/odoo.py @@ -74,9 +74,7 @@ parser.add_argument( "--timeout", help="Odoo timeout [default: %(default)s]", default=36000 ) - parser.add_argument( - "-d", "--database", help="Odoo database", required=True - ) + parser.add_argument("-d", "--database", help="Odoo database", required=True) return parser diff --git a/odoo_scripts/parsing.py b/odoo_scripts/parsing.py --- a/odoo_scripts/parsing.py +++ b/odoo_scripts/parsing.py @@ -41,14 +41,10 @@ level = logging.CRITICAL elif verbosity > 0: level = logging.DEBUG - coloredlogs.install( - level, fmt="%(asctime)s %(levelname)8s %(name)s %(message)s" - ) + coloredlogs.install(level, fmt="%(asctime)s %(levelname)8s %(name)s %(message)s") -def basic_parser( - description: Optional[str], version: str -) -> argparse.ArgumentParser: +def basic_parser(description: Optional[str], version: str) -> argparse.ArgumentParser: """Create a basic parser""" parser = argparse.ArgumentParser( description=description, diff --git a/odoo_scripts/update_duplicate_sources.py b/odoo_scripts/update_duplicate_sources.py --- a/odoo_scripts/update_duplicate_sources.py +++ b/odoo_scripts/update_duplicate_sources.py @@ -65,9 +65,7 @@ _update_duplicate_sources_mercurial(**kwargs) -def _update_duplicate_sources_mercurial( - directory: str = ".", path: str = "default" -): +def _update_duplicate_sources_mercurial(directory: str = ".", path: str = "default"): """ :arg directory: path to the base directory :arg path: path to use (from `.hg/hgrc`) @@ -98,9 +96,7 @@ duplicate_destination = b"sources" if os.path.exists(duplicate_destination): raise Exception( - "Destination directory '{}' exists!".format( - u(duplicate_destination) - ) + "Destination directory '{}' exists!".format(u(duplicate_destination)) ) _logger.info("Cloning in %s", u(duplicate_destination)) hg.clone(source=duplicate_path, dest=duplicate_destination) @@ -122,9 +118,7 @@ # shell script) if not branch_exists_in_duplicate: hg_duplicate.update(b"tip") - _logger.info( - "Branch %s not found in duplicate, updating to tip", u(branch) - ) + _logger.info("Branch %s not found in duplicate, updating to tip", u(branch)) # rsync content inside the other directory cmd = ( [ diff --git a/pyproject.toml b/pyproject.toml --- a/pyproject.toml +++ b/pyproject.toml @@ -4,14 +4,9 @@ # See <https://pypi.org/project/black/>. -# black defaults to "line-length = 88"; we prefer "line-length = 79" for now to -# please our various tools / IDEs / linters. [tool.black] -line-length = 79 target = 3.6 [tool.isort] profile = "black" -include_trailing_comma = true -line_length = 79 diff --git a/setup.cfg b/setup.cfg --- a/setup.cfg +++ b/setup.cfg @@ -18,3 +18,6 @@ [bumpversion:file:odoo_scripts/__init__.py] [bumpversion:file:setup.py] + +[flake8] +max-line-length = 88