Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow variants for extension name in metadata.ini #15290

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 36 additions & 6 deletions modules/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
from modules.gitpython_hack import Repo
from modules.paths_internal import extensions_dir, extensions_builtin_dir, script_path # noqa: F401

extensions: list[Extension] = []
extension_paths: dict[str, Extension] = {}
loaded_extensions: dict[str, Exception] = {}


os.makedirs(extensions_dir, exist_ok=True)

Expand Down Expand Up @@ -50,7 +54,7 @@ def __init__(self, path, canonical_name):
self.canonical_name = self.config.get("Extension", "Name", fallback=canonical_name)
self.canonical_name = canonical_name.lower().strip()

self.requires = self.get_script_requirements("Requires", "Extension")
self.requires = None

def get_script_requirements(self, field, section, extra_section=None):
"""reads a list of requirements from the config; field is the name of the field in the ini file,
Expand All @@ -62,7 +66,33 @@ def get_script_requirements(self, field, section, extra_section=None):
if extra_section:
x = x + ', ' + self.config.get(extra_section, field, fallback='')

return self.parse_list(x.lower())
tmp_list = self.parse_list(x.lower())

if len(tmp_list) >= 3:
names_variants = []
i = 0
while i < len(tmp_list) - 2:
if tmp_list[i] != "|":
names_variants.append([tmp_list[i]])
i += 1
else:
names_variants[-1].append(tmp_list[i + 1])
i += 2
while i < len(tmp_list):
names_variants.append([tmp_list[i]])
i += 1

result_list = []

for name_variants in names_variants:
for variant in name_variants:
if variant in loaded_extensions.keys():
break
result_list.append(variant)
else:
result_list = tmp_list

return result_list

def parse_list(self, text):
"""converts a line from config ("ext1 ext2, ext3 ") into a python list (["ext1", "ext2", "ext3"])"""
Expand Down Expand Up @@ -213,6 +243,7 @@ def fetch_and_reset_hard(self, commit='origin'):
def list_extensions():
extensions.clear()
extension_paths.clear()
loaded_extensions.clear()

if shared.cmd_opts.disable_all_extensions:
print("*** \"--disable-all-extensions\" arg was used, will not load any extensions ***")
Expand All @@ -223,7 +254,6 @@ def list_extensions():
elif shared.opts.disable_all_extensions == "extra":
print("*** \"Disable all extensions\" option was set, will only load built-in extensions ***")

loaded_extensions = {}

# scan through extensions directory and load metadata
for dirname in [extensions_builtin_dir, extensions_dir]:
Expand All @@ -250,6 +280,9 @@ def list_extensions():
extension_paths[extension.path] = extension
loaded_extensions[canonical_name] = extension

for extension in extensions:
extension.metadata.requires = extension.metadata.get_script_requirements("Requires", "Extension")

# check for requirements
for extension in extensions:
if not extension.enabled:
Expand Down Expand Up @@ -279,6 +312,3 @@ def find_extension(filename):

return None


extensions: list[Extension] = []
extension_paths: dict[str, Extension] = {}