Grampslocale: Fix PyLint complaints about import statements.

Or comment ones that can't be fixed because their placement is to
prevent circular imports.
This commit is contained in:
John Ralls 2023-07-14 13:18:27 -07:00 committed by Nick Hall
parent d5dd8d698c
commit a89faa85e0

View File

@ -29,13 +29,21 @@
import gettext import gettext
import sys import sys
import os import os
import codecs
import locale import locale
import collections
import logging import logging
import time
from binascii import hexlify from binascii import hexlify
from .grampstranslation import GrampsTranslations, GrampsNullTranslations from .grampstranslation import GrampsTranslations, GrampsNullTranslations
if sys.platform == 'darwin':
from . maclocale import mac_setup_localization
if sys.platform == 'win32':
from ctypes import cdll
LOG = logging.getLogger("." + __name__) LOG = logging.getLogger("." + __name__)
LOG.propagate = True LOG.propagate = True
HAVE_ICU = False HAVE_ICU = False
@ -172,7 +180,6 @@ def _check_gformat():
test for, make sure both the month and the day are double digits, test for, make sure both the month and the day are double digits,
preferably greater than 12 for human readablity preferably greater than 12 for human readablity
''' '''
import time
timestr = time.strftime('%x',(2005,10,25,1,1,1,1,1,1)) timestr = time.strftime('%x',(2005,10,25,1,1,1,1,1,1))
# Gramps treats dates with '-' as ISO format, so replace separator # Gramps treats dates with '-' as ISO format, so replace separator
@ -426,7 +433,6 @@ class GrampsLocale:
Help routine for loading and setting up libintl attributes Help routine for loading and setting up libintl attributes
Returns libintl Returns libintl
""" """
from ctypes import cdll
try: try:
libintl = cdll.LoadLibrary('libintl-8') libintl = cdll.LoadLibrary('libintl-8')
libintl.bindtextdomain(localedomain, localedir) libintl.bindtextdomain(localedomain, localedir)
@ -458,8 +464,7 @@ class GrampsLocale:
# expected behavior), do platform-specific setup: # expected behavior), do platform-specific setup:
if not (self.lang and self.language): if not (self.lang and self.language):
if sys.platform == 'darwin': if sys.platform == 'darwin':
from . import maclocale mac_setup_localization(self)
maclocale.mac_setup_localization(self)
elif sys.platform == 'win32': elif sys.platform == 'win32':
self._win_init_environment() self._win_init_environment()
else: else:
@ -720,14 +725,16 @@ class GrampsLocale:
""" """
if self._dd: if self._dd:
return self._dd return self._dd
# PyLint will whine about these not being at the top level but putting
# it there creates a circular import.
from ..config import config from ..config import config
from ..datehandler import LANG_TO_DISPLAY as displayers
try: try:
val = config.get('preferences.date-format') val = config.get('preferences.date-format')
except AttributeError: except AttributeError:
val = 0; val = 0;
from ..datehandler import LANG_TO_DISPLAY as displayers
_first = self._GrampsLocale__first_instance _first = self._GrampsLocale__first_instance
if self.calendar in displayers: if self.calendar in displayers:
self._dd = displayers[self.calendar](val) self._dd = displayers[self.calendar](val)
@ -754,8 +761,10 @@ class GrampsLocale:
""" """
if self._dp: if self._dp:
return self._dp return self._dp
# PyLint will whine about this not being at the top level but putting
# it there creates a circular import.
from ..datehandler import LANG_TO_PARSER as parsers from ..datehandler import LANG_TO_PARSER as parsers
_first = self._GrampsLocale__first_instance _first = self._GrampsLocale__first_instance
if self.calendar in parsers: if self.calendar in parsers:
self._dp = parsers[self.calendar]() self._dp = parsers[self.calendar]()
@ -982,6 +991,8 @@ class GrampsLocale:
:returns: The name as text in the proper language. :returns: The name as text in the proper language.
:rtype: unicode :rtype: unicode
""" """
# PyLint will complain about this not being at top level but putting it there
# creates a circular import.
from ..lib.grampstype import GrampsType from ..lib.grampstype import GrampsType
return GrampsType.xml_str(name) return GrampsType.xml_str(name)