Page MenuHomePhabricator

generate_family_file.py creates dodgy syntax for semantic-mediawiki.org
Closed, ResolvedPublic

Description

The family file generator believes there is a language 'sw', but the writes a family class with two 'en' langs, which is invalid dict syntax.

$ python ./generate_family_file.py https://www.semantic-mediawiki.org/wiki/ semantic-mw
Generating family file from https://www.semantic-mediawiki.org/wiki/

==================================
api url: https://semantic-mediawiki.org/w/api.php
MediaWiki version: 1.22.3
==================================

Determining other languages...sw

There are 2 languages available.
Do you want to generate interwiki links? This might take a long time. ([y]es/[N]o/[e]dit)y
Loading wikis... 
  * sw... downloaded
  * en... in cache
Writing pywikibot/families/semantic-mw_family.py... 


$ cat pywikibot/families/semantic-mw_family.py 
# -*- coding: utf-8 -*-
"""
This family file was auto-generated by $Id: 185033971c163ea46b2b1904773b8c407069a4d0 $
Configuration parameters:
  url = https://www.semantic-mediawiki.org/wiki/
  name = semantic-mw

Please do not commit this to the Git repository!
"""

from pywikibot import family

class Family(family.Family):
    def __init__(self):
        family.Family.__init__(self)
        self.name = 'semantic-mw'
        self.langs = {
            'en': 'semanticweb.org',
            'en': 'semantic-mediawiki.org',
        }



    def scriptpath(self, code):
        return {
            'en': '',
            'en': '/w',
        }[code]

    def version(self, code):
        return {
            'en': u'1.20.2',
            'en': u'1.22.3',
        }[code]

It isnt quite invalid syntax, but it is dodgy.
The family file 'works' because semantic-mediawiki.org is second in that list, and all supported version of python return the second entry with the same key.

$ python2.6 pwb.py shell
Welcome to the Pywikibot interactive shell!
>>> import pywikibot
>>> s = pywikibot.Site('en', 'semantic-mw')
>>> s.family.langs
{'en': 'semantic-mediawiki.org'}
>>> {
...             'en': u'1.20.2',
...             'en': u'1.22.3',
...         }
{'en': u'1.22.3'}

Version: core-(2.0)
Severity: normal

Details

Reference
bz72896

Event Timeline

bzimport raised the priority of this task from to Needs Triage.Nov 22 2014, 3:58 AM
bzimport set Reference to bz72896.
bzimport added a subscriber: Unknown Object (????).

While dodgy, it works correctly.

Okay I don't 100 % understand why in T104267 it used community.wikia.com as an entry on the IWM, but the main issue is just that it doesn't check if multiple entries have the same prefix. But you misunderstood generate_family_files as it shows the prefix and not language so it's not the language but interwiki prefix sw as seen from the other site. But then it's using that site's language for the mapping and not the language code as seen from the original site.

It is somewhat better now:

$ cat pywikibot/families/semantic_family.py 
# -*- coding: utf-8 -*-
"""
This family file was auto-generated by generate_family_file.py script.

Configuration parameters:
  url = https://www.semantic-mediawiki.org/wiki/Semantic_MediaWiki
  name = semantic

Please do not commit this to the Git repository!
"""
from __future__ import absolute_import, division, unicode_literals

from pywikibot import family
from pywikibot.tools import deprecated


class Family(family.Family):  # noqa: D101

    name = 'semantic'
    langs = {
        'en': 'www.semantic-mediawiki.org',
    }

    def scriptpath(self, code):
        return {
            'en': '/w',
        }[code]

    @deprecated('APISite.version()')
    def version(self, code):
        return {
            'en': '1.31.1',
        }[code]

    def protocol(self, code):
        return {
            'en': 'https',
        }[code]

Currently throwing a warning about sw language

Xqt claimed this task.
Xqt subscribed.

No longer valid