[FIX] poetry update: move lock file if exist
- support non standard versionning pip like 1.3.* - ignore other odoo version and comments
This commit is contained in:
parent
fc73d0b9bd
commit
e7e3a37ed3
1 changed files with 74 additions and 31 deletions
|
|
@ -7,6 +7,7 @@ import ast
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import shutil
|
||||||
from collections import OrderedDict, defaultdict
|
from collections import OrderedDict, defaultdict
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
@ -71,7 +72,7 @@ def get_config():
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--set_version_python",
|
"--set_version_python",
|
||||||
help="Force to change python version, default is from file './.python-version'.",
|
help="Force to change python version, default is from file './.python-odoo-version'.",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--set_version_erplibre",
|
"--set_version_erplibre",
|
||||||
|
|
@ -85,7 +86,7 @@ def get_config():
|
||||||
with open("./.odoo-version", "r", encoding="utf-8") as fichier:
|
with open("./.odoo-version", "r", encoding="utf-8") as fichier:
|
||||||
args.set_version_odoo = fichier.read().strip()
|
args.set_version_odoo = fichier.read().strip()
|
||||||
if not args.set_version_python:
|
if not args.set_version_python:
|
||||||
with open("./.python-version", "r", encoding="utf-8") as fichier:
|
with open("./.python-odoo-version", "r", encoding="utf-8") as fichier:
|
||||||
args.set_version_python = fichier.read().strip()
|
args.set_version_python = fichier.read().strip()
|
||||||
if not args.set_version_erplibre:
|
if not args.set_version_erplibre:
|
||||||
with open("./.erplibre-version", "r", encoding="utf-8") as fichier:
|
with open("./.erplibre-version", "r", encoding="utf-8") as fichier:
|
||||||
|
|
@ -117,23 +118,30 @@ def get_file_from_glob(
|
||||||
force_add_item: list = None,
|
force_add_item: list = None,
|
||||||
):
|
):
|
||||||
lst_v = []
|
lst_v = []
|
||||||
for a in Path(".").rglob(glob_txt):
|
# TODO take all groups odoo##.# from manifest, will create a dependency
|
||||||
a_dirname = os.path.dirname(a)
|
# Hardcode logic from manifest
|
||||||
if a_dirname.startswith(".repo/") or a_dirname.startswith(".venv"):
|
lst_path = [
|
||||||
continue
|
Path(f"./addons.odoo{config.set_version_odoo}").rglob(glob_txt),
|
||||||
if ignore_dir_startswith:
|
Path(f"./odoo{config.set_version_odoo}/odoo").rglob(glob_txt),
|
||||||
ignore_it = False
|
]
|
||||||
for item_ignore_dir in ignore_dir_startswith:
|
for gen_path in lst_path:
|
||||||
if a_dirname.startswith(item_ignore_dir):
|
for a in gen_path:
|
||||||
ignore_it = True
|
a_dirname = os.path.dirname(a)
|
||||||
break
|
if a_dirname.startswith(".repo/") or a_dirname.startswith(".venv"):
|
||||||
if ignore_it:
|
|
||||||
continue
|
continue
|
||||||
if a_dirname.startswith("addons") and not a_dirname.startswith(
|
if ignore_dir_startswith:
|
||||||
f"addons.odoo{config.set_version_odoo}"
|
ignore_it = False
|
||||||
):
|
for item_ignore_dir in ignore_dir_startswith:
|
||||||
continue
|
if a_dirname.startswith(item_ignore_dir):
|
||||||
lst_v.append(a)
|
ignore_it = True
|
||||||
|
break
|
||||||
|
if ignore_it:
|
||||||
|
continue
|
||||||
|
if a_dirname.startswith("addons") and not a_dirname.startswith(
|
||||||
|
f"addons.odoo{config.set_version_odoo}"
|
||||||
|
):
|
||||||
|
continue
|
||||||
|
lst_v.append(a)
|
||||||
if force_add_item:
|
if force_add_item:
|
||||||
for item in force_add_item:
|
for item in force_add_item:
|
||||||
lst_v.append(Path(item))
|
lst_v.append(Path(item))
|
||||||
|
|
@ -290,23 +298,29 @@ def combine_requirements(config):
|
||||||
|
|
||||||
lst_version_requirement = []
|
lst_version_requirement = []
|
||||||
for requirement in lst_requirement:
|
for requirement in lst_requirement:
|
||||||
if ".*" in requirement:
|
# if ".*" in requirement:
|
||||||
requirement = requirement.replace(".*", "")
|
# requirement = requirement.replace(".*", "")
|
||||||
if "~=" in requirement:
|
if "~=" in requirement:
|
||||||
old_requirement = requirement
|
old_requirement = requirement
|
||||||
requirement = requirement.replace("~=", "==")
|
requirement = requirement.replace("~=", "==")
|
||||||
lst_replace_special_sign[requirement] = old_requirement
|
lst_replace_special_sign[requirement] = old_requirement
|
||||||
|
|
||||||
match = re.search(r"[=<>~!]{1,2}(.*)", requirement)
|
requirement_begin = requirement.split(except_sign)[0]
|
||||||
|
match = re.search(r"[=<>~!]{1,2}(.*)", requirement_begin)
|
||||||
if not match:
|
if not match:
|
||||||
# Ignore empty version
|
# Ignore empty version
|
||||||
continue
|
continue
|
||||||
match_version = match.group(1).strip()
|
match_version = match.group(1).strip()
|
||||||
|
if ".*" in match_version:
|
||||||
|
match_version = match_version.replace(".*", "")
|
||||||
match_sign = match.group(0).strip()[: -len(match_version)]
|
match_sign = match.group(0).strip()[: -len(match_version)]
|
||||||
match_app_name = requirement[
|
match_app_name = requirement[
|
||||||
: -(len(match_sign) + len(match_version))
|
: -(len(match_sign) + len(match_version))
|
||||||
]
|
]
|
||||||
result_number = [(match_sign, Version(match_version))]
|
match_version_format = match_version.replace("'", "").replace(
|
||||||
|
'"', ""
|
||||||
|
)
|
||||||
|
result_number = [(match_sign, Version(match_version_format))]
|
||||||
# result_number = iscompatible.parse_requirements(requirement)
|
# result_number = iscompatible.parse_requirements(requirement)
|
||||||
if not result_number:
|
if not result_number:
|
||||||
continue
|
continue
|
||||||
|
|
@ -328,6 +342,10 @@ def combine_requirements(config):
|
||||||
# else:
|
# else:
|
||||||
# version_requirement_upd = version_requirement[0]
|
# version_requirement_upd = version_requirement[0]
|
||||||
version_requirement_upd = version_requirement[0]
|
version_requirement_upd = version_requirement[0]
|
||||||
|
if ".*" in version_requirement_upd:
|
||||||
|
version_requirement_upd = (
|
||||||
|
version_requirement_upd.replace(".*", "")
|
||||||
|
)
|
||||||
try:
|
try:
|
||||||
is_compatible &= iscompatible.iscompatible(
|
is_compatible &= iscompatible.iscompatible(
|
||||||
version_requirement_upd, highest_value[1][0][1]
|
version_requirement_upd, highest_value[1][0][1]
|
||||||
|
|
@ -353,12 +371,18 @@ def combine_requirements(config):
|
||||||
filename_1 = dct_requirements_module_filename.get(
|
filename_1 = dct_requirements_module_filename.get(
|
||||||
key_require
|
key_require
|
||||||
)
|
)
|
||||||
if priority_filename_requirement in filename_1:
|
if not filename_1:
|
||||||
erplibre_value = version_requirement[0]
|
_logger.error(
|
||||||
elif (
|
f"Cannot find key '{key_require}' into list of requirements."
|
||||||
second_priority_filename_requirement in filename_1
|
)
|
||||||
):
|
else:
|
||||||
odoo_value = version_requirement[0]
|
if priority_filename_requirement in filename_1:
|
||||||
|
erplibre_value = version_requirement[0]
|
||||||
|
elif (
|
||||||
|
second_priority_filename_requirement
|
||||||
|
in filename_1
|
||||||
|
):
|
||||||
|
odoo_value = version_requirement[0]
|
||||||
|
|
||||||
if erplibre_value:
|
if erplibre_value:
|
||||||
str_result_choose = (
|
str_result_choose = (
|
||||||
|
|
@ -511,20 +535,39 @@ def main():
|
||||||
# lst_repo = get_all_repo()
|
# lst_repo = get_all_repo()
|
||||||
config = get_config()
|
config = get_config()
|
||||||
|
|
||||||
|
# print(
|
||||||
|
# f"Version: ERPLibre '{config.set_version_erplibre}' : Python ERPLibre '{config.set_version_python_erplibre}' : Poetry '{config.set_version_poetry}' : Odoo '{config.set_version_odoo}' : Python Odoo '{config.set_version_python_odoo}'"
|
||||||
|
# )
|
||||||
print(
|
print(
|
||||||
f"Version: Poetry '{config.set_version_poetry}' : Odoo '{config.set_version_odoo}' : Python '{config.set_version_python}' : ERPLibre '{config.set_version_erplibre}'"
|
f"Version: Poetry '{config.set_version_poetry}' : Odoo '{config.set_version_odoo}' : Python '{config.set_version_python}' : ERPLibre '{config.set_version_erplibre}'"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
poetry_default_lock_path = "./poetry.lock"
|
||||||
|
pyproject_toml_filename = ""
|
||||||
|
poetry_target_lock_path = (
|
||||||
|
f"./requirement/poetry.{config.set_version_erplibre}.lock"
|
||||||
|
)
|
||||||
|
|
||||||
if not config.dry:
|
if not config.dry:
|
||||||
pyproject_toml_filename = f"{config.dir}pyproject.toml"
|
pyproject_toml_filename = f"{config.dir}pyproject.toml"
|
||||||
delete_dependency_poetry(pyproject_toml_filename)
|
delete_dependency_poetry(pyproject_toml_filename)
|
||||||
combine_requirements(config)
|
combine_requirements(config)
|
||||||
if not config.dry:
|
if not config.dry:
|
||||||
if config.force and os.path.isfile("./poetry.lock"):
|
if config.force and os.path.isfile(poetry_default_lock_path):
|
||||||
os.remove("./poetry.lock")
|
os.remove(poetry_default_lock_path)
|
||||||
status = call_poetry_add_build_dependency()
|
status = call_poetry_add_build_dependency()
|
||||||
if status:
|
if status and pyproject_toml_filename:
|
||||||
sorted_dependency_poetry(pyproject_toml_filename)
|
sorted_dependency_poetry(pyproject_toml_filename)
|
||||||
|
if (
|
||||||
|
config.force
|
||||||
|
and not os.path.islink(poetry_default_lock_path)
|
||||||
|
and os.path.isfile(poetry_default_lock_path)
|
||||||
|
and os.path.isfile(poetry_target_lock_path)
|
||||||
|
):
|
||||||
|
# If "./poetry.lock" is not symbolic link, force replace original
|
||||||
|
os.remove(poetry_target_lock_path)
|
||||||
|
shutil.move(poetry_default_lock_path, poetry_target_lock_path)
|
||||||
|
os.symlink(poetry_target_lock_path, poetry_default_lock_path)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue