1
0
mirror of https://github.com/janeczku/calibre-web synced 2024-12-18 06:00:32 +00:00

Fix import pycountry on python 3.12 without warning

Fix shadowed "babel" name
This commit is contained in:
Ozzie Isaacs 2024-09-16 17:21:39 +02:00
parent 2617fa8af4
commit d0e166140f
6 changed files with 11 additions and 19 deletions

View File

@ -34,7 +34,7 @@ from .cli import CliParameter
from .reverseproxy import ReverseProxied
from .server import WebServer
from .dep_check import dependency_check
from .babel import babel, get_locale
# from .babel import babel, get_locale
from .updater import Updater
from . import config_sql
from . import cache_buster
@ -182,6 +182,7 @@ def create_app():
app.secret_key = os.getenv('SECRET_KEY', config_sql.get_flask_session_key(ub.session))
web_server.init_app(app, config)
from .cw_babel import babel, get_locale
if hasattr(babel, "localeselector"):
babel.init_app(app)
babel.localeselector(get_locale)

View File

@ -42,10 +42,8 @@ opt = dep_check.load_dependencies(True)
for i in (req + opt):
modules[i[1]] = i[0]
modules['Jinja2'] = importlib.metadata.version("jinja2")
try:
if sys.version_info < (3, 12):
modules['pySqlite'] = sqlite3.version
except Exception:
pass
modules['SQLite'] = sqlite3.sqlite_version
sorted_modules = OrderedDict((sorted(modules.items(), key=lambda x: x[0].casefold())))

View File

@ -52,7 +52,7 @@ from .gdriveutils import is_gdrive_ready, gdrive_support
from .render_template import render_title_template, get_sidebar_config
from .services.worker import WorkerThread
from .usermanagement import user_login_required
from .babel import get_available_translations, get_available_locale, get_user_locale_language
from .cw_babel import get_available_translations, get_available_locale, get_user_locale_language
from . import debug_info
from .string_helper import strip_whitespaces

View File

@ -25,26 +25,14 @@ log = logger.create()
try:
from iso639 import languages
# iso_version = importlib.metadata.version("iso639")
get = languages.get
try:
if sys.version_info >= (3, 12):
import pkg_resources
except ImportError:
print("Python 3.12 isn't compatible with iso-639. Please install pycountry.")
except ImportError as ex:
from pycountry import languages as pyc_languages
#try:
# iso_version = importlib.metadata.version("pycountry") + ' (PyCountry)'
#except (ImportError, Exception):
# iso_version = "?" + ' (PyCountry)'
def _copy_fields(l):
l.part1 = getattr(l, 'alpha_2', None)
l.part3 = getattr(l, 'alpha_3', None)
return l
def get(name=None, part1=None, part3=None):
if part3 is not None:
return _copy_fields(pyc_languages.get(alpha_3=part3))
@ -52,6 +40,11 @@ except ImportError as ex:
return _copy_fields(pyc_languages.get(alpha_2=part1))
if name is not None:
return _copy_fields(pyc_languages.get(name=name))
except ImportError as ex:
if sys.version_info >= (3, 12):
print("Python 3.12 isn't compatible with iso-639. Please install pycountry.")
from iso639 import languages
get = languages.get
def get_language_names(locale):

View File

@ -52,7 +52,7 @@ from .helper import check_valid_domain, check_email, check_username, \
edit_book_read_status, valid_password
from .pagination import Pagination
from .redirect import get_redirect_location
from .babel import get_available_locale
from .cw_babel import get_available_locale
from .usermanagement import login_required_if_no_ano
from .kobo_sync_status import remove_synced_book
from .render_template import render_title_template