Skip to content

Commit

Permalink
[Dependencies][Changed] The roles member
Browse files Browse the repository at this point in the history
- Each dependency can really have 1 role (even when plural)
- The registered dependency can have multiple roles
- The code assumed the general case, but is impossible
  • Loading branch information
set-soft committed Jan 24, 2024
1 parent 6d6075b commit f5a0231
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 96 deletions.
4 changes: 2 additions & 2 deletions kibot/config_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -1273,7 +1273,7 @@ def print_dependencies(markdown=True, jsn=False, rst=False):
# Compute the importance of each dependency
for dep in RegDependency.get_registered().values():
importance = 0
for r in dep.roles:
for r in dep.role:
local = r.output != 'global'
if r.mandatory:
importance += LOCAL_MANDATORY if local else GLOBAL_MANDATORY
Expand Down Expand Up @@ -1331,7 +1331,7 @@ def print_dependencies(markdown=True, jsn=False, rst=False):
optional = []
version = None
max_version = None
for r in dep.roles:
for r in dep.role:
if r.mandatory:
needed.append(global2human(r.output))
else:
Expand Down
52 changes: 19 additions & 33 deletions kibot/dep_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,9 +649,9 @@ def check_tool_binary_version(full_name, dep, no_cache=False):
return full_name, None
# Do we need a particular version?
needs = (0, 0, 0)
for r in dep.roles:
if r.version and r.version > needs:
needs = r.version
ver = dep.role.version
if ver and ver > needs:
needs = ver
if needs == (0, 0, 0):
# Any version is Ok
logger.debugl(2, '- No particular version needed')
Expand Down Expand Up @@ -766,9 +766,9 @@ def check_tool_python_version(mod, dep):
version_check_fail = False
# Do we need a particular version?
needs = (0, 0, 0)
for r in dep.roles:
if r.version and r.version > needs:
needs = r.version
ver = dep.role.version
if ver and ver > needs:
needs = ver
if needs == (0, 0, 0):
# Any version is Ok
logger.debugl(2, '- No particular version needed')
Expand Down Expand Up @@ -824,23 +824,12 @@ def get_version(role):
return ''


def show_roles(roles, fatal):
optional = []
for r in roles:
if not r.mandatory:
optional.append(r)
output = r.output
if output != 'global':
do_log_err('Output that needs it: '+output, fatal)
if optional:
if len(optional) == 1:
o = optional[0]
desc = o.desc[0].lower()+o.desc[1:]
do_log_err('Used to {}{}'.format(desc, get_version(o)), fatal)
else:
do_log_err('Used to:', fatal)
for o in optional:
do_log_err('- {}{}'.format(o.desc, get_version(o)), fatal)
def show_roles(role, fatal):
if role.output != 'global':
do_log_err('Output that needs it: '+role.output, fatal)
if not role.mandatory:
desc = role.desc[0].lower()+role.desc[1:]
do_log_err('Used to {}{}'.format(desc, get_version(role)), fatal)


def get_dep_data(context, dep):
Expand Down Expand Up @@ -881,7 +870,7 @@ def check_tool_dep_get_ver(context, dep, fatal=False):
do_log_err('- Recommended extra Arch packages: '+' '.join(dep.extra_arch), fatal)
for comment in dep.comments:
do_log_err(comment, fatal)
show_roles(dep.roles, fatal)
show_roles(dep.role, fatal)
do_log_err(TRY_INSTALL_CHECK, fatal)
if fatal:
exit(MISSING_TOOL)
Expand Down Expand Up @@ -915,7 +904,7 @@ def __init__(self, desc=None, version=None, output=None, max_version=None):
class ToolDependency(object):
""" Class used to define tools needed for an output """
def __init__(self, output, name, url=None, url_down=None, is_python=False, deb=None, in_debian=True, extra_deb=None,
roles=None, plugin_dirs=None, command=None, pypi_name=None, module_name=None, no_cmd_line_version=False,
role=None, plugin_dirs=None, command=None, pypi_name=None, module_name=None, no_cmd_line_version=False,
help_option=None, no_cmd_line_version_old=False, downloader=None, arch=None, extra_arch=None, tests=None):
# The associated output
self.output = output
Expand Down Expand Up @@ -956,13 +945,10 @@ def __init__(self, output, name, url=None, url_down=None, is_python=False, deb=N
self.help_option = help_option if help_option is not None else '--version'
self.tests = tests
# Roles
if roles is None:
roles = [ToolDependencyRole()]
elif not isinstance(roles, list):
roles = [roles]
for r in roles:
r.output = output
self.roles = roles
if role is None:
role = ToolDependencyRole()
role.output = output
self.role = role


def register_dep(context, dep):
Expand Down Expand Up @@ -1017,7 +1003,7 @@ def register_dep(context, dep):
tests = dep.get('tests', [])
# logger.error('{}:{} {} {}'.format(context, name, downloader, pypi_name))
# TODO: Make it *ARGS
td = ToolDependency(context, name, roles=role, url=url, url_down=url_down, deb=deb, in_debian=in_debian,
td = ToolDependency(context, name, role=role, url=url, url_down=url_down, deb=deb, in_debian=in_debian,
extra_deb=extra_deb, is_python=is_python, module_name=module_name, plugin_dirs=plugin_dirs,
command=command, help_option=help_option, pypi_name=pypi_name,
no_cmd_line_version_old=no_cmd_line_version_old, downloader=downloader, arch=arch,
Expand Down
1 change: 1 addition & 0 deletions kibot/out_bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
python_module: true
debian: python3-xlsxwriter
arch: python-xlsxwriter
version: 1.1.2
downloader: python
"""
import csv
Expand Down
6 changes: 4 additions & 2 deletions kibot/registrable.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,11 @@ def register(cl, aclass):
if name in cl._registered:
# Already registered, add the roles
old_reg = cl._registered[name]
old_reg.roles.extend(aclass.roles)
old_reg.role.append(aclass.role)
else:
cl._registered[name] = aclass
cp = copy(aclass)
cp.role = [aclass.role]
cl._registered[name] = cp


def solve_variant(variant):
Expand Down
Loading

0 comments on commit f5a0231

Please sign in to comment.