From a7b6d3617b434eac9ea15e9027c7db4edef94e80 Mon Sep 17 00:00:00 2001 From: Sekhar03 <125454858+Sekhar03@users.noreply.github.com> Date: Thu, 13 Aug 2026 14:12:04 +0530 Subject: [PATCH] Fix issue #190: check Python version and locale encoding at startup before importing naomi package --- Naomi.py | 21 ++++++++++++++++----- Populate.py | 21 ++++++++++++++++----- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/Naomi.py b/Naomi.py index 83010ecb..bef000a0 100755 --- a/Naomi.py +++ b/Naomi.py @@ -1,9 +1,20 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -import naomi import sys -if(sys.version_info.major < 3): - raise SystemError("This version of Naomi requires Python 3.5 or greater") +if (sys.version_info.major < 3): + sys.stderr.write("Error: This version of Naomi requires Python 3.5 or greater\n") + sys.exit(1) + +import locale +try: + encoding = locale.getpreferredencoding() + if encoding and encoding.lower() not in ('utf-8', 'utf8'): + sys.stderr.write("WARNING: Your system locale is configured to use a non-UTF-8 character encoding ({}).\n".format(encoding)) + sys.stderr.write("This may cause Naomi to crash when reading files or configuration containing international characters.\n") + sys.stderr.write("Please consider setting your system locale to UTF-8 (e.g. by setting LC_ALL=en_US.UTF-8 in Linux).\n") +except Exception: + pass + +import naomi naomi.main() + diff --git a/Populate.py b/Populate.py index 85d83d8c..4d8ee7a2 100755 --- a/Populate.py +++ b/Populate.py @@ -1,9 +1,20 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -import naomi import sys -if(sys.version_info.major < 3): - raise SystemError("This version of Naomi requires Python 3.5 or greater") +if (sys.version_info.major < 3): + sys.stderr.write("Error: This version of Naomi requires Python 3.5 or greater\n") + sys.exit(1) + +import locale +try: + encoding = locale.getpreferredencoding() + if encoding and encoding.lower() not in ('utf-8', 'utf8'): + sys.stderr.write("WARNING: Your system locale is configured to use a non-UTF-8 character encoding ({}).\n".format(encoding)) + sys.stderr.write("This may cause Naomi to crash when reading files or configuration containing international characters.\n") + sys.stderr.write("Please consider setting your system locale to UTF-8 (e.g. by setting LC_ALL=en_US.UTF-8 in Linux).\n") +except Exception: + pass + +import naomi naomi.main(args=["--repopulate"]) +