Fix: Windows DLL path lookup with Python >= 3.8
[babeltrace.git] / src / bindings / python / bt2 / bt2 / __init__.py
index 4310f4693ad1064288bb2083a3d6c2840d663ea0..73cc668831e9d33c15df0f23fe26a10e32c13e1b 100644 (file)
 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 # THE SOFTWARE.
 
+import os
 import sys
 
+# With Python ≥ 3.8 on Windows, the DLL lookup mechanism to load native
+# modules doesn't search the `PATH` environment variable like everything
+# else on this platform.
+#
+# See <https://docs.python.org/3/whatsnew/3.8.html#bpo-36085-whatsnew>.
+#
+# Restore this behaviour by doing it manually.
+if os.name == "nt" and sys.version_info >= (3, 8):
+    for path in os.getenv("PATH", "").split(os.pathsep):
+        if os.path.exists(path) and path != ".":
+            os.add_dll_directory(path)
+
+del os
+
 # import all public names
 from bt2.clock_class import ClockClassOffset
 from bt2.clock_snapshot import _ClockSnapshotConst
@@ -99,12 +114,13 @@ from bt2.field_class import _OptionWithUnsignedIntegerSelectorFieldClass
 from bt2.field_class import _OptionWithSignedIntegerSelectorFieldClass
 from bt2.field_class import _VariantFieldClass
 from bt2.field_class import _VariantFieldClassWithoutSelector
-from bt2.field_class import _VariantFieldClassWithSelector
-from bt2.field_class import _VariantFieldClassWithUnsignedSelector
-from bt2.field_class import _VariantFieldClassWithSignedSelector
+from bt2.field_class import _VariantFieldClassWithIntegerSelector
+from bt2.field_class import _VariantFieldClassWithUnsignedIntegerSelector
+from bt2.field_class import _VariantFieldClassWithSignedIntegerSelector
 from bt2.field_class import _ArrayFieldClass
 from bt2.field_class import _StaticArrayFieldClass
 from bt2.field_class import _DynamicArrayFieldClass
+from bt2.field_class import _DynamicArrayWithLengthFieldFieldClass
 from bt2.field_class import _BoolFieldClassConst
 from bt2.field_class import _BitArrayFieldClassConst
 from bt2.field_class import _IntegerFieldClassConst
@@ -124,12 +140,13 @@ from bt2.field_class import _OptionWithUnsignedIntegerSelectorFieldClassConst
 from bt2.field_class import _OptionWithSignedIntegerSelectorFieldClassConst
 from bt2.field_class import _VariantFieldClassConst
 from bt2.field_class import _VariantFieldClassWithoutSelectorConst
-from bt2.field_class import _VariantFieldClassWithSelectorConst
-from bt2.field_class import _VariantFieldClassWithUnsignedSelectorConst
-from bt2.field_class import _VariantFieldClassWithSignedSelectorConst
+from bt2.field_class import _VariantFieldClassWithIntegerSelectorConst
+from bt2.field_class import _VariantFieldClassWithUnsignedIntegerSelectorConst
+from bt2.field_class import _VariantFieldClassWithSignedIntegerSelectorConst
 from bt2.field_class import _ArrayFieldClassConst
 from bt2.field_class import _StaticArrayFieldClassConst
 from bt2.field_class import _DynamicArrayFieldClassConst
+from bt2.field_class import _DynamicArrayWithLengthFieldFieldClassConst
 from bt2.field_path import FieldPathScope
 from bt2.field_path import _IndexFieldPathItem
 from bt2.field_path import _CurrentArrayElementFieldPathItem
@@ -248,10 +265,10 @@ class _MemoryError(_Error):
 
 
 class UnknownObject(Exception):
-    '''
+    """
     Raised when a component class handles a query for an object it doesn't
     know about.
-    '''
+    """
 
     pass
 
This page took 0.024447 seconds and 4 git commands to generate.