jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/668661 )
Change subject: [bugfix] Re-enable setting private family files ......................................................................
[bugfix] Re-enable setting private family files
- register_families_folder and register_family_file does not work with Python 3 without globals() are passed to exec() function. Now use user_families_paths list and user_families dict to reimplement setting private family files. This has the advantage that user-config.py does not need to have executable code, which is shouldn't, see PAWS. - usernames and disambiguation_comment are defaultdict instances. It is not necessary to set their items to an empty dict which would override user-config settings. - revert generate_user_files.py documentation related to register_famil??_* functions. More documentation is found in EXTERNAL FAMILIES SETTINGS.
Bug: T270949 Change-Id: If0dd4eb47a5c13545c27b460bd1d05b5769f3262 --- M generate_user_files.py M pywikibot/config2.py 2 files changed, 25 insertions(+), 38 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/generate_user_files.py b/generate_user_files.py index 6e81771..a4140d9 100755 --- a/generate_user_files.py +++ b/generate_user_files.py @@ -175,34 +175,9 @@ # This is an automatically generated file. You can find more configuration # parameters in 'config.py' file.
-# The family of sites to work on by default. -# -# ‘site.py’ imports ‘families/xxx_family.py’, so if you want to change -# this variable, you need to use the name of one of the existing family files -# in that folder or write your own, custom family file. -# -# For ‘site.py’ to be able to read your custom family file, you must -# save it to ‘families/xxx_family.py’, where ‘xxx‘ is the codename of the -# family that your custom ‘xxx_family.py’ family file defines. -# -# You can also save your custom family files to a different folder. As long -# as you follow the ‘xxx_family.py’ naming convention, you can register your -# custom folder in this configuration file with the following global function: -# -# register_families_folder(folder_path) -# -# Alternatively, you can register particular family files that do not need -# to follow the ‘xxx_family.py’ naming convention using the following -# global function: -# -# register_family_file(family_name, file_path) -# -# Where ‘family_name’ is the family code (the ‘xxx’ in standard family file -# names) and ‘file_path’ is the absolute path to the target family file. -# -# If you use either of these functions to define the family to work on by -# default (the ‘family’ variable below), you must place the function call -# before the definition of the ‘family’ variable. +# The family of sites we are working on. wikipedia.py will import +# families/xxx_family.py so if you want to change this variable, +# you need to write such a file. family = '{main_family}'
# The language code of the site we're working on. diff --git a/pywikibot/config2.py b/pywikibot/config2.py index 38f0300..91204be 100644 --- a/pywikibot/config2.py +++ b/pywikibot/config2.py @@ -14,13 +14,7 @@ PYWIKIBOT_NO_USER_CONFIG=2. If pywikibot is installed as a site-package the behaviour is like PYWIKIBOT_NO_USER_CONFIG=2 is set.
-Provides two functions to register family classes which can be used in -the user-config: - - - register_family_file - - register_families_folder - -Other functions made available to user-config: +Functions made available to user-config:
- user_home_path
@@ -32,7 +26,7 @@ - shortpath """ # -# (C) Pywikibot team, 2003-2020 +# (C) Pywikibot team, 2003-2021 # # Distributed under the terms of the MIT license. # @@ -400,8 +394,6 @@ Parameter file_path may be a path or an url. family.AutoFamily function is used when the url is given. """ - usernames[family_name] = {} - disambiguation_comment[family_name] = {} family_files[family_name] = file_path
@@ -570,6 +562,21 @@ # user_script_paths = ['scripts.myscripts'] user_script_paths = [] # type: List[str]
+# ############# EXTERNAL FAMILIES SETTINGS ############## +# Set your own family path to lookup for your family files. +# +# Your private family path may be either an absolute or a relative path. +# You may have multiple paths defined in user_families_paths list. +# +# You may also define various family files stored in the user_families +# dict. Use the family name as dict key and the path or an url als value. +# +# samples: +# user_families_paths = ['data/families'] +# user_families = {'mywiki': 'https://de.wikipedia.org%27%7D +user_families_paths = [] # type: List[str] +user_families = {} # type: dict + # ############# SOLVE_DISAMBIGUATION SETTINGS ############ # # Set disambiguation_comment[FAMILY][LANG] to a non-empty string to override @@ -1010,6 +1017,11 @@ " permission or set 'ignore_file_security_warnings' to true.") sys.exit(1)
+# Setup custom family files +for file_path in user_families_paths: + register_families_folder(file_path) +for name, path in user_families.items(): + register_family_file(name, path) # # When called as main program, list all configuration variables #