Basic custom check python module failing to load

53 views Asked by At

I'm trying to add a basic check as a module (not a package), but the weblate_celery fails to load. The file is named ApostropheCheck.py and is saved in the same directory as the main settings.py file.

I'm including it with:
import ApostropheCheck
And adding it to the list of active checks:

CHECK_LIST += (
    "ApostropheCheck.ApostropheCheck",
)

The code for the check is:

"""Check for consistent apostrophe usage."""

from django.utils.translation import gettext_lazy as _
from weblate.checks.base import TargetCheck


class ApostropheCheck(TargetCheck):

    # Used as identifier for check, should be unique
    # Has to be shorter than 50 characters
    check_id = "apos"

    # Short name used to display failing check
    name = _("Apostrophe check")

    # Description for failing check
    description = _("Apostophe counts not consistent with source")

    # Real check code
    def check_single(self, source, target, unit):
        if source.count('`') != target.count('`'): return True
        if source.count('"') != target.count('"'): return True
        if source.count("'") != target.count("'"): return True
        return False

1

There are 1 answers

0
Michal Čihař On

You need to provide fully qualified path to your class, including Python module. See https://docs.weblate.org/en/latest/admin/customize.html#custom-check-modules for examples.