Page MenuHomePhabricator

replace.py does not recognize replacements in user-fixes.py
Closed, ResolvedPublic

Description

Last time I've used replace.py was in march 2015 and all work correctly.
Now when I run this script I can't use replacements in user-fixes.py file.

The command is:

python pwb.py replace.py "-file:lista.txt" "-always" "-fix:carattericontrollo" "-summary:test"

That returns:

Available predefined fixes are: correct-ar, isbn, HTML, case-de, datum, syntax, grammar-de, syntax-safe, specialpages, fckeditor, vonbis, music, yu-tld

these are contained in the file fixes.py. The replacements contained in user-fixes.py are not listed.

My PyWikiBot version is:

Pywikibot: [https] r-pywikibot-core.git (47d2b86, g6404, 2015/09/10, 22:25:12, ok)
Release version: 2.0b3
requests version: 2.2.1
  cacerts: /etc/ssl/certs/ca-certificates.crt
    certificate test: ok
Python: 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2]
PYWIKIBOT2_DIR: Not set
PYWIKIBOT2_DIR_PWB:
PYWIKIBOT2_NO_USER_CONFIG: Not set
Config base dir: /data/project/betabot/core

Details

Related Gerrit Patches:

Event Timeline

Beta16 created this task.Sep 10 2015, 2:40 PM
Beta16 raised the priority of this task from to Needs Triage.
Beta16 updated the task description. (Show Details)
Beta16 added a project: Pywikibot-replace.py.
Beta16 added a subscriber: Beta16.
Restricted Application added subscribers: pywikibot-bugs-list, Aklapper. · View Herald TranscriptSep 10 2015, 2:40 PM
XZise claimed this task.Sep 10 2015, 2:44 PM
XZise added a project: Pywikibot.
XZise set Security to None.

Does it the list of fixes say:

The user fixes file could not be found: …

You're probably looking for argument -replacementfile instead of -file.
I also noticed that despite -file not being listed in the possible switches, there is an erroneous example using it.

XZise added a comment.Sep 10 2015, 2:49 PM

-file is defining a list of pages to work on. The user fixes file should be implicitly loaded without a parameter.

Sorry, I misread the issue and also -file exists at global level.

By what I could gather, it tries to locate the user-fixes.py file in the base directory (not in the 'scripts' directory). Is your file located there?

Beta16 added a comment.EditedSep 10 2015, 2:59 PM

"-file:lista.txt" contain the list of articles where the bot works on.

"-fix:carattericontrollo" is a set of replacements contents in user-fixes.py. This file exists in my core base directory.

The only output message is

Available predefined fixes are: ...

Not "The user fixes file could not be found: …" or other

I did a quick test with the latest version and it seems to be working.

This is a quick example I tried in user-fixes.py (excluding imports etc.):

fixes.update({
    'XXXX': {
        'regex': True,
        'msg': 'pywikibot-fixes-html',
        'replacements': [
            (r'(?i)([\r\n]) *<h6> *([^<]+?) *</h6> *([\r\n])',  r"\1====== \2 ======\3"),
        ],
        'exceptions': {
            'inside-tags': [
                'nowiki',
                'comment',
                'math',
                'pre'
            ],
        }
    }
}
)

When using an invalid fix name, I can see my fix listed:

Available predefined fixes are: correct-ar, isbn, HTML, case-de, datum, syntax, grammar-de, syntax-safe, specialpages, fckeditor, XXXX, vonbis, music, yu-tld

XZise added a comment.Sep 10 2015, 3:16 PM

Okay then your user fixes may be invalid. Can you it maybe paste it somewhere (phabricator has a builtin paste service)?

Beta16 closed this task as Resolved.Sep 11 2015, 9:15 AM

Following the example of Malafaya I edited my user-fixes.py file from:

fixes = { ... }

to

fixes.update({ ... })

Now it works.
Thanks to all! :)

Ah shoot. I might have an explanation why it stopped working for you. In 3ac1880 I moved loading the file into a function and so my guess is that when you define fixes like you did, that it becomes a function local variable. I guess adding global fixes above the try would fix this problem properly. (Unless we want to say that it shouldn't be allowed)

XZise reopened this task as Open.Sep 11 2015, 11:30 AM

Reopen it for now as this could be fixed.

Change 237999 had a related patch set uploaded (by XZise):
[FIX] fixes: Allow replacing the variable

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

Change 237999 merged by jenkins-bot:
[FIX] fixes: Allow replacing the variable

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

XZise closed this task as Resolved.Sep 14 2015, 8:52 PM