From 1bee928e5c0a23e7420f1950eba5b32b2aff3cd6 Mon Sep 17 00:00:00 2001
From: Ivan Shapovalov <intelfx@intelfx.name>
Date: Sun, 4 Feb 2024 17:46:06 +0100
Subject: [PATCH] setup.py: support PEP 517 isolated builds when sourcing
 version

---
 setup.py | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/setup.py b/setup.py
index b01c50a1..1944cd01 100644
--- a/setup.py
+++ b/setup.py
@@ -1,6 +1,12 @@
+import importlib.util
 import setuptools
+from pathlib import Path
 
-from mautrix import __version__
+# get mautrix.__version__ in a way that's compatible with PEP517 isolation
+spec = importlib.util.spec_from_file_location("mautrix", Path(__file__).parent / "mautrix/__init__.py")
+mautrix = importlib.util.module_from_spec(spec)
+spec.loader.exec_module(mautrix)
+__version__ = mautrix.__version__
 
 encryption_dependencies = ["python-olm", "unpaddedbase64", "pycryptodome"]
 test_dependencies = ["aiosqlite", "asyncpg", "ruamel.yaml", *encryption_dependencies]