[FIX] poetry update: stop on a missing pyproject.toml, offer the switch

The root pyproject.toml and poetry.lock are unversioned symlinks to the
active version's files in requirement/, created by the version switch.
Without them the script died on a FileNotFoundError traceback. It now
names the fix, make switch_odoo_XX for the active Odoo version; on a
terminal it offers to run it and restarts with the same arguments.
Checked: an existing file passes, a missing one exits 1 off a terminal
and on a declined prompt. The accepted path, which runs the switch, is
not tested.

--- FR ---

[FIX] poetry update : arrêt sur pyproject.toml absent, switch proposé

pyproject.toml et poetry.lock à la racine sont des liens non versionnés
vers les fichiers de la version active dans requirement/, créés par le
switch de version. Sans eux, le script mourait sur un FileNotFoundError.
Il nomme désormais le remède, make switch_odoo_XX pour la version Odoo
active ; dans un terminal, il propose de le lancer et se relance avec
les mêmes arguments. Vérifié : un fichier présent passe, un absent sort
en 1 hors terminal et sur un refus. L'acceptation, qui lance le switch,
n'est pas testée.

Assisted-by: Claude Opus 5.5
This commit is contained in:
Mathieu Benoit 2026-09-25 02:54:33 -04:00
parent 884b02f7c5
commit 2a5e83b5c7

View file

@ -8,6 +8,7 @@ import logging
import os import os
import re import re
import shutil import shutil
import sys
from collections import OrderedDict, defaultdict from collections import OrderedDict, defaultdict
from pathlib import Path from pathlib import Path
@ -659,6 +660,39 @@ def get_list_ignored():
return lst_ignore_requirements, ignore_requirement_file return lst_ignore_requirements, ignore_requirement_file
def ensure_pyproject_link(config, pyproject_filename):
"""Stop cleanly when the root pyproject.toml is missing.
pyproject.toml and poetry.lock at the root are symlinks to the active
version's files in requirement/, created by the version switch; they are
not versioned. When absent, or dangling, the fix is `make switch_odoo_XX`.
On a terminal, offer to run it and restart this script with the same
arguments; otherwise print the command and exit with code 1.
:param config: parsed arguments, set_version_odoo gives the make target
:param pyproject_filename: path of the pyproject.toml to open
:return: None when the file exists; never returns otherwise
"""
if os.path.isfile(pyproject_filename):
return
odoo_major = config.set_version_odoo.split(".")[0]
make_cmd = f"make switch_odoo_{odoo_major}"
print(
f"{Fore.RED}ERROR{Style.RESET_ALL} - Missing '{pyproject_filename}':"
" the Poetry links of the active version are not created."
)
print(f"Fix: run '{make_cmd}', then relaunch this script.")
if not sys.stdin.isatty():
sys.exit(1)
answer = input(f"Run '{make_cmd}' and relaunch now? [y/N] ")
if answer.strip().lower() not in ("y", "yes", "o", "oui"):
sys.exit(1)
if os.system(make_cmd) != 0 or not os.path.isfile(pyproject_filename):
print(f"{Fore.RED}ERROR{Style.RESET_ALL} - '{make_cmd}' failed.")
sys.exit(1)
os.execv(sys.executable, [sys.executable] + sys.argv)
def main(): def main():
# repo = Repo(root_path) # repo = Repo(root_path)
# lst_repo = get_all_repo() # lst_repo = get_all_repo()
@ -679,6 +713,7 @@ def main():
if not config.dry: if not config.dry:
pyproject_toml_filename = f"{config.dir}pyproject.toml" pyproject_toml_filename = f"{config.dir}pyproject.toml"
ensure_pyproject_link(config, pyproject_toml_filename)
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: