Jump to content

Portal:Toolforge/Admin/Pywikibot image

From Wikitech

This page documents the custom Pywikibot build service image.

Updating the image

This needs to happen every time there is a new Pywikibot release.

  • Add the gerrit repo as gerrit remote, merge its stable branch into gitlab and then push:
    $ git remote add gerrit https://gerrit.wikimedia.org/r/pywikibot/core
    $ git fetch -v gerrit
    $ git merge --ff-only gerrit/stable
    $ git push origin stable
    
  • Checkout the toolforge branch, and merge the stable branch to the toolforge branch, this will create a merge commit
    $ git checkout toolforge
    $ git reset --hard origin/toolforge
    $ git merge stable
    
  • Push toolforge branch to gitlab
    $ git push origin toolforge
    
  • Start a build (note that the image name is not the default)
    $ ssh login.toolforge.org
    tools-bastion-15:~$ sudo become pywikibot
    tools.pywikibot@tools-bastion-15:~$ toolforge build start -i pywikibot-scripts-stable --ref toolforge https://gitlab.wikimedia.org/toolforge-repos/pywikibot-buildservice
    

Doing a test

To test pywikibot, you need OAuth credentials stored in PWB_ env vars. You can use the tool wikitech-double-redirect-bot, that is set up to authenticate on wikitech.

This command will authenticate to Wikitech and show the current version of pywikibot and its dependencies:

fnegri@tools-bastion-15:~$ sudo become wikitech-double-redirect-bot

tools.wikitech-double-redirect-bot@tools-bastion-15:~$ toolforge jobs run --image tool-pywikibot/pywikibot-scripts-stable:latest --command "pwb -family:wikitech -lang:en -version" test-pwb

tools.wikitech-double-redirect-bot@tools-bastion-15:~$ toolforge jobs logs test-pwb -f

[...]

2026-01-28T18:16:59Z [test-pwb-h75l5] [job] family and mylang are not set.
2026-01-28T18:16:59Z [test-pwb-h75l5] [job] Defaulting to family='wikipedia' and mylang='test'.
2026-01-28T18:17:00Z [test-pwb-h75l5] [job] Pywikibot: [https] toolforge-repos-pywikibot-buildservice (66fecaa, g1, 2026/01/28, 19:01:07, OUTDATED)
2026-01-28T18:17:00Z [test-pwb-h75l5] [job] Release version: 10.7.5
2026-01-28T18:17:00Z [test-pwb-h75l5] [job] packaging version: 26.0
2026-01-28T18:17:00Z [test-pwb-h75l5] [job] mwparserfromhell version: 0.7.2
2026-01-28T18:17:00Z [test-pwb-h75l5] [job] wikitextparser version: 0.56.4
2026-01-28T18:17:00Z [test-pwb-h75l5] [job] requests version: 2.32.5
2026-01-28T18:17:00Z [test-pwb-h75l5] [job]   cacerts: /layers/heroku_python/dependencies/lib/python3.9/site-packages/certifi/cacert.pem
2026-01-28T18:17:00Z [test-pwb-h75l5] [job]     certificate test: ok
2026-01-28T18:17:00Z [test-pwb-h75l5] [job] Python: 3.9.18 (main, Aug 24 2023, 22:36:08)
2026-01-28T18:17:00Z [test-pwb-h75l5] [job] [GCC 11.4.0]
2026-01-28T18:17:00Z [test-pwb-h75l5] [job] User-Agent: version (wikitech:en; User:Wikitech_double_redirect_bot) Pywikibot/10.7.5 (g1) requests/2.32.5 Python/3.9.18.final.0

[...]

Additionally, you can use this command to verify that pywikibot can correctly parse wiki pages:

fnegri@tools-bastion-15:~$ sudo become wikitech-double-redirect-bot

tools.wikitech-double-redirect-bot@tools-bastion-15:~$ toolforge jobs run --image tool-pywikibot/pywikibot-scripts-stable:latest --command "pwb -family:wikitech -lang:en redirect double -always" fix-double-redirects

tools.wikitech-double-redirect-bot@tools-bastion-15:~$ toolforge jobs logs fix-double-redirects -f
2026-01-28T18:05:29Z [fix-double-redirects-dqckk] [job] family and mylang are not set.
2026-01-28T18:05:29Z [fix-double-redirects-dqckk] [job] Defaulting to family='wikipedia' and mylang='test'.
2026-01-28T18:05:30Z [fix-double-redirects-dqckk] [job] Retrieving double redirect special page...
2026-01-28T18:05:31Z [fix-double-redirects-dqckk] [job] Working on 'K8saas'
2026-01-28T18:05:31Z [fix-double-redirects-dqckk] [job]    Links to: [[en:Help:Managed Kubernetes]].
2026-01-28T18:05:32Z [fix-double-redirects-dqckk] [job] Skipping: Redirect target [[en:Help:Managed Kubernetes]] is not a  redirect.

[...]

2026-01-28T18:33:11Z [fix-double-redirects-zjrbz] [job] 3 read operations
2026-01-28T18:33:11Z [fix-double-redirects-zjrbz] [job] Execution time: 1 seconds
2026-01-28T18:33:11Z [fix-double-redirects-zjrbz] [job] Read operation time: 0.3 seconds
2026-01-28T18:33:11Z [fix-double-redirects-zjrbz] [job] Script terminated successfully.

See also