Page MenuHomePhabricator

pywikibot.handle_args() shouldn't be used within private scripts
Closed, ResolvedPublic

Description

pywikibot.handle_args() can be used to handle global options within scripts like

options = {}
local_args = pywikibot.handle_args()
for arg in local_args;
    arg, _, value = arg.partition(':')
    if not arg.startswith('-'):
        continue
    option[arg] = value

but global options can changes and private options can be hidden by such implementation. Vice versa if the local optionas are handled first, the global options could be discarded.

Problen:
The problem is that global options can be changed or expanded at any time. There is no way to deprecate renamed options or warn for new ones.

Solution:

The prefered way is to use global options throught the pwb wrapper script as descibed there:https://doc.wikimedia.org/pywikibot/master/utilities/scripts_ref.html#module-pywikibot.scripts.wrapper

python pwb.py <global pwb options> <name_of_script> <local script options>

Using this proposal the pywikibot.handle_args is no longer necessary to be used within the script.

This mehtod should be more documented.

Event Timeline

Xqt renamed this task from bot.handle_args() shouldn't be use d within private scripts to pywikibot.handle_args() shouldn't be use d within private scripts.Mar 10 2024, 2:08 PM
Xqt triaged this task as Low priority.
Xqt updated the task description. (Show Details)
Xqt renamed this task from pywikibot.handle_args() shouldn't be use d within private scripts to pywikibot.handle_args() shouldn't be used within private scripts.Apr 3 2024, 8:04 AM

Change #1016793 had a related patch set uploaded (by Xqt; author: Xqt):

[pywikibot/core@master] [doc] Add admoniton and hint for pywikibot.handle_args() usage

https://gerrit.wikimedia.org/r/1016793

Change #1016793 merged by jenkins-bot:

[pywikibot/core@master] [doc] Add admoniton and hint for pywikibot.handle_args() usage

https://gerrit.wikimedia.org/r/1016793