jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/736530 )
Change subject: [IMPR] Allow family files in base_dir by default ......................................................................
[IMPR] Allow family files in base_dir by default
private family files can be registered via register_families_folder() function already. Register 'families' folder in basedir by default within config.py.
Change-Id: Ic84fbc6b95910b9b144faa8309c54f3ed3714a11 --- M pywikibot/config.py 1 file changed, 17 insertions(+), 1 deletion(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/config.py b/pywikibot/config.py index d573ada..13c79c1 100644 --- a/pywikibot/config.py +++ b/pywikibot/config.py @@ -395,14 +395,27 @@ family_files[family_name] = file_path
-def register_families_folder(folder_path: str) -> None: +def register_families_folder(folder_path: str, + not_exists_ok: bool = False) -> None: """Register all family class files contained in a directory.
+ .. versionadded:: 7.0 + The *not_exists_ok* parameter + :param folder_path: The path of a folder containing family files. The families may also be inside a zip archive structure. + :param not_exists_ok: When true, ignore FileNotFoundError + :raises FileNotFoundError: Family folder does not exist :raises NotADirectoryError: folder_path is not a directory """ suffix = '_family.py' + + if not os.path.exists(folder_path): + if not_exists_ok: + return + raise FileNotFoundError('Family folder {!r} does not exist' + .format(folder_path)) + if os.path.isdir(folder_path): for file_name in os.listdir(folder_path): if file_name.endswith(suffix): @@ -435,6 +448,9 @@ # Get the names of all known families, and initialize with empty dictionaries. # ‘families/’ is a subdirectory of the directory in which config.py is found. register_families_folder(os.path.join(os.path.dirname(__file__), 'families')) +# ‘families/’ can also be stored in the base directory +register_families_folder(os.path.join(base_dir, 'families'), + not_exists_ok=True)
# ############# USER INTERFACE SETTINGS ##############
pywikibot-commits@lists.wikimedia.org