from grafana_dashboard.grafana_dashboard import json_to_python, python_to_json
from pathlib import Path
python_to_json(python_base_dir=Path("."), python_base_package="input", json_dir=Path("output"))
This script does not work on windows as I am passing a WindowsPath object into python_base_dir, which propagates to
|
mod = importlib.import_module(python_package_name) |
where the path is implicitly converted into a string as it passes into importlib. Therefore inputlib ends up with name='input\\testout', when it should have been called with name=input.testout.
Changing the script to the following circumvents the issue (patch courtesy of ChatGPT 4o)
import importlib
_real_import_module = importlib.import_module
def patched_import_module(name, package=None):
# Fix backslashes to dots
fixed = name.replace("\\", ".")
return _real_import_module(fixed, package)
importlib.import_module = patched_import_module
from grafana_dashboard.grafana_dashboard import json_to_python, python_to_json
from pathlib import Path
import input.testout
python_to_json(python_base_dir=Path("."), python_base_package="input", json_dir=Path("output"))
This script does not work on windows as I am passing a WindowsPath object into python_base_dir, which propagates to
grafana_dashboard_python/grafana_dashboard/converter/python_to_json.py
Line 28 in f1415a4
where the path is implicitly converted into a string as it passes into importlib. Therefore inputlib ends up with
name='input\\testout', when it should have been called withname=input.testout.Changing the script to the following circumvents the issue (patch courtesy of ChatGPT 4o)