From 5d2ec68c5d6b37193c3d7ad1cca84226013f6cb1 Mon Sep 17 00:00:00 2001 From: dreamer Date: Mon, 4 Nov 2024 09:49:44 +0100 Subject: [PATCH] use importlib to get json absolute path --- hvcc/core/hv2ir/types/IR.py | 5 ++++- hvcc/core/hv2ir/types/Lang.py | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/hvcc/core/hv2ir/types/IR.py b/hvcc/core/hv2ir/types/IR.py index 06169a57..321b7b65 100644 --- a/hvcc/core/hv2ir/types/IR.py +++ b/hvcc/core/hv2ir/types/IR.py @@ -44,7 +44,10 @@ class HeavyIRType(RootModel): if __name__ == "__main__": import json - with open('../../json/heavy.ir.json') as f: + import importlib_resources + + heavy_ir_json = importlib_resources.files('hvcc') / 'core/json/heavy.ir.json' + with open(heavy_ir_json, "r") as f: data = json.load(f) heavy_ir = HeavyIRType(root=data) print(heavy_ir.root.keys()) diff --git a/hvcc/core/hv2ir/types/Lang.py b/hvcc/core/hv2ir/types/Lang.py index 2dd9c29f..1e4d92e4 100644 --- a/hvcc/core/hv2ir/types/Lang.py +++ b/hvcc/core/hv2ir/types/Lang.py @@ -40,7 +40,10 @@ class HeavyLangType(RootModel): if __name__ == "__main__": import json - with open('../../json/heavy.lang.json') as f: + import importlib_resources + + heavy_lang_json = importlib_resources.files('hvcc') / 'core/json/heavy.lang.json' + with open(heavy_lang_json, "r") as f: data = json.load(f) heavy_lang = HeavyLangType(root=data) print(heavy_lang.root.keys())