diff --git a/src/faebryk/core/cpp/__init__.py b/src/faebryk/core/cpp/__init__.py index 92650796..5879f152 100644 --- a/src/faebryk/core/cpp/__init__.py +++ b/src/faebryk/core/cpp/__init__.py @@ -1,10 +1,11 @@ # This file is part of the faebryk project # SPDX-License-Identifier: MIT +import json import logging import pathlib import shutil -import site +from importlib.metadata import Distribution from typing import Callable logger = logging.getLogger(__name__) @@ -12,8 +13,12 @@ # Check if installed as editable def is_editable_install(): - site_packages = site.getsitepackages() - return not any((pathlib.Path(sp) / "faebryk").exists() for sp in site_packages) + distro = Distribution.from_name(__name__.split(".")[0]) + return ( + json.loads(distro.read_text("direct_url.json")) + .get("dir_info", {}) + .get("editable", False) + ) def compile_and_load(): @@ -43,7 +48,7 @@ def _do(*args, **kwargs): "cmake not found, needed for compiling c++ code in editable mode" ) - pybind11_dir = _do(["python", "-m", "pybind11", "--cmakedir"]).strip() + pybind11_dir = _do([sys.executable, "-m", "pybind11", "--cmakedir"]).strip() # Force recompile # subprocess.run(["rm", "-rf", str(build_dir)], check=True)