mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-19 22:50:21 +00:00
monkey patch dump_py_messages to ignore blenderbim dependencies
This commit is contained in:
@@ -81,14 +81,28 @@ def update_translations_from_po():
|
|||||||
bpy.app.translations.register(ADDON_NAME, translations_module.translations_dict)
|
bpy.app.translations.register(ADDON_NAME, translations_module.translations_dict)
|
||||||
|
|
||||||
|
|
||||||
def dump_py_messages(msgs, reports, addons, settings, addons_only=False):
|
def dump_py_messages_monkey_patch(msgs, reports, addons, settings, addons_only=False):
|
||||||
def _get_files(path):
|
ignore_addon_dirs = ["libs"]
|
||||||
|
|
||||||
|
def _get_files(path, ignore_dirs=tuple()):
|
||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
return []
|
return []
|
||||||
if os.path.isdir(path):
|
if os.path.isdir(path):
|
||||||
return [os.path.join(dpath, fn) for dpath, _, fnames in os.walk(path) for fn in fnames
|
files = []
|
||||||
if fn.endswith(".py") and (fn == "__init__.py"
|
for dpath, subdirs, fnames in os.walk(path, topdown=True, followlinks=True):
|
||||||
or not fn.startswith("_"))]
|
if Path(dpath) in ignore_dirs:
|
||||||
|
subdirs.clear() # skip walking through `subdirs`
|
||||||
|
continue
|
||||||
|
|
||||||
|
for fn in fnames:
|
||||||
|
if not fn.endswith(".py"):
|
||||||
|
continue
|
||||||
|
if fn.startswith("_") and fn != "__init__.py":
|
||||||
|
continue
|
||||||
|
files.append(os.path.join(dpath, fn))
|
||||||
|
|
||||||
|
return files
|
||||||
|
|
||||||
return [path]
|
return [path]
|
||||||
|
|
||||||
files = []
|
files = []
|
||||||
@@ -101,7 +115,9 @@ def dump_py_messages(msgs, reports, addons, settings, addons_only=False):
|
|||||||
for mod in addons:
|
for mod in addons:
|
||||||
fn = mod.__file__
|
fn = mod.__file__
|
||||||
if os.path.basename(fn) == "__init__.py":
|
if os.path.basename(fn) == "__init__.py":
|
||||||
files += _get_files(os.path.dirname(fn))
|
parent_dir = Path(fn).parent
|
||||||
|
ignore_dirs = [parent_dir / dpath for dpath in ignore_addon_dirs]
|
||||||
|
files += _get_files(os.path.dirname(fn), ignore_dirs=ignore_dirs)
|
||||||
else:
|
else:
|
||||||
files.append(fn)
|
files.append(fn)
|
||||||
|
|
||||||
@@ -122,6 +138,12 @@ if __name__ == "__main__":
|
|||||||
f" - {ui_translate_settings.BLENDER_I18N_PO_DIR}\n"
|
f" - {ui_translate_settings.BLENDER_I18N_PO_DIR}\n"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# we monkey patch `bl_i18n_utils.bl_extract_messages.dump_py_messages`
|
||||||
|
# as it's doesn't support ignoring folders
|
||||||
|
# and we need it, otherwise translation addon will try to parse strings
|
||||||
|
# from all BlenderBIM dependencies :O
|
||||||
|
bl_i18n_utils.bl_extract_messages.dump_py_messages = dump_py_messages_monkey_patch
|
||||||
|
|
||||||
# setup selected languages
|
# setup selected languages
|
||||||
for lang in i18n_settings.langs:
|
for lang in i18n_settings.langs:
|
||||||
lang.use = lang.uid in SUPPORT_LANGUAGES
|
lang.use = lang.uid in SUPPORT_LANGUAGES
|
||||||
|
|||||||
Reference in New Issue
Block a user