Gallaecio created this task. Gallaecio added a subscriber: Gallaecio. Gallaecio added a project: pywikibot-core. Gallaecio changed Security from none to none.
TASK DESCRIPTION I have several calls to register_family_file() on my user-config.py file.
When I use replace.py, having a print statement on the register_family_file() implementation, I can see that the calls are made, and that the family_files keys increase, however by the time execution reaches family.py:Family.load(), config.family_files does not contain but the default families.
TASK DETAIL https://phabricator.wikimedia.org/T78777
REPLY HANDLER ACTIONS Reply to comment or attach files, or !close, !claim, !unsubscribe or !assign <username>.
EMAIL PREFERENCES https://phabricator.wikimedia.org/settings/panel/emailpreferences/
To: Gallaecio Cc: Aklapper, Gallaecio, jayvdb, pywikipedia-bugs
Gallaecio added a comment.
Using "_uc = globals()" before the exec() in config2.py fixed it. I am going to explore that option.
TASK DETAIL https://phabricator.wikimedia.org/T78777
REPLY HANDLER ACTIONS Reply to comment or attach files, or !close, !claim, !unsubscribe or !assign <username>.
EMAIL PREFERENCES https://phabricator.wikimedia.org/settings/panel/emailpreferences/
To: Gallaecio Cc: Aklapper, Gallaecio, jayvdb, pywikipedia-bugs
XZise assigned this task to jayvdb. XZise added a subscriber: XZise. XZise added a comment.
I think https://gerrit.wikimedia.org/r/#/c/170505/ is related to this.
TASK DETAIL https://phabricator.wikimedia.org/T78777
REPLY HANDLER ACTIONS Reply to comment or attach files, or !close, !claim, !unsubscribe or !assign <username>.
EMAIL PREFERENCES https://phabricator.wikimedia.org/settings/panel/emailpreferences/
To: jayvdb, XZise Cc: Aklapper, Gallaecio, XZise, jayvdb, pywikipedia-bugs
Gallaecio added a comment.
I ended up fixing it like this:
diff --git a/pywikibot/config2.py b/pywikibot/config2.py index e7df241..72e6474 100644 --- a/pywikibot/config2.py +++ b/pywikibot/config2.py @@ -819,7 +819,11 @@ for _filename in _fns: _fileuid = _filestatus[4] if sys.platform == 'win32' or _fileuid in [os.getuid(), 0]: if sys.platform == 'win32' or _filemode & 0o02 == 0: - exec(compile(open(_filename).read(), _filename, 'exec'), _uc) + _uc_tmp = globals() + exec(compile(open(_filename).read(), _filename, 'exec'), + _uc_tmp) + for key in _uc: + _uc[key] = _uc_tmp[key] else: print("WARNING: Skipped '%(fn)s': writeable by others." % {'fn': _filename})
However, I am going to test the linked change and use that if it works, which it probably will.
TASK DETAIL https://phabricator.wikimedia.org/T78777
REPLY HANDLER ACTIONS Reply to comment or attach files, or !close, !claim, !unsubscribe or !assign <username>.
EMAIL PREFERENCES https://phabricator.wikimedia.org/settings/panel/emailpreferences/
To: jayvdb, Gallaecio Cc: Aklapper, Gallaecio, XZise, jayvdb, pywikipedia-bugs
jayvdb added a comment.
fwiw, @xzise was the first to find the bug I created, and put up a working solution at https://gerrit.wikimedia.org/r/#/c/163462/ .
TASK DETAIL https://phabricator.wikimedia.org/T78777
REPLY HANDLER ACTIONS Reply to comment or attach files, or !close, !claim, !unsubscribe or !assign <username>.
EMAIL PREFERENCES https://phabricator.wikimedia.org/settings/panel/emailpreferences/
To: jayvdb Cc: Aklapper, Gallaecio, XZise, jayvdb, pywikipedia-bugs
valhallasw added a subscriber: valhallasw. valhallasw added a comment.
I think this should be possible without introspection. I think just
_uc['register_family_file'] = register_family_file
might work; if not, we can explicitly pass the environment to register_family_file:
def _register_family_file(environment, file): environment['...'] = ... etc
_uc['register_family_file'] = lambda f: register_family_file(_uc, f)
(or using functools.partial)
Using introspection sounds like a bad idea to me.
TASK DETAIL https://phabricator.wikimedia.org/T78777
REPLY HANDLER ACTIONS Reply to comment or attach files, or !close, !claim, !unsubscribe or !assign <username>.
EMAIL PREFERENCES https://phabricator.wikimedia.org/settings/panel/emailpreferences/
To: jayvdb, valhallasw Cc: Aklapper, Gallaecio, XZise, valhallasw, jayvdb, pywikipedia-bugs
XZise added a subscriber: jayvdb. XZise added a comment.
I'm not sure how the first one would work, because there is a `register_family_file` available but that modifies the original map and not the map "locally". The second one might work although it's not as generic as @jayvdb's solution (but better than mine).
TASK DETAIL https://phabricator.wikimedia.org/T78777
REPLY HANDLER ACTIONS Reply to comment or attach files, or !close, !claim, !unsubscribe or !assign <username>.
EMAIL PREFERENCES https://phabricator.wikimedia.org/settings/panel/emailpreferences/
To: jayvdb, XZise Cc: Aklapper, Gallaecio, XZise, valhallasw, jayvdb, pywikipedia-bugs
pywikipedia-bugs@lists.wikimedia.org