From d7fa4e57efddf87e6d15fe52c6b141c66c874e19 Mon Sep 17 00:00:00 2001 From: Jens Diemer Date: Mon, 3 Apr 2023 09:41:32 +0200 Subject: [PATCH] Try to use tomllib and fallback to tomli --- package_linter.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/package_linter.py b/package_linter.py index 9b83ec8..e6796fa 100755 --- a/package_linter.py +++ b/package_linter.py @@ -13,10 +13,13 @@ import statistics from datetime import datetime try: - import toml -except: - os.system('pip3 install toml') - import toml + import tomllib # New in Python 3.11 +except ImportError: + try: + import tomli as tomllib + except ImportError: + os.system('pip3 install tomli') + import tomli as tomllib # ############################################################################ # Helper list @@ -1536,7 +1539,7 @@ class Manifest(TestSuite): self.raw_manifest, object_pairs_hook=check_for_duplicate_keys ) else: - self.manifest = toml.loads(self.raw_manifest) + self.manifest = tomllib.loads(self.raw_manifest) except Exception as e: print( c.FAIL @@ -1966,7 +1969,7 @@ class AppCatalog(TestSuite): self._fetch_app_repo() try: - self.app_list = toml.loads(open("./.apps/apps.toml").read()) + self.app_list = tomllib.loads(open("./.apps/apps.toml").read()) except Exception: _print("Failed to read apps.toml :/") sys.exit(-1) @@ -2128,7 +2131,7 @@ class AppCatalog(TestSuite): elif os.system(f"git -C ./.apps cat-file -e {commit}:apps.toml") == 0: raw_catalog_at_this_date = git(["show", f"{commit}:apps.toml"]) - loader = toml + loader = tomllib else: raise Exception("No apps.json/toml at this point in history?")