From f9c931842744f98bfd69140f0288c5b4b8d19b4a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 11 Feb 2026 14:35:55 +0000 Subject: [PATCH 1/4] Initial plan From 28c48db9aa8f08540684bd11b7ec44a5c0d40578 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 11 Feb 2026 14:38:47 +0000 Subject: [PATCH 2/4] Add Windows DLL loading fix for Python 3.8+ Co-authored-by: sbillinge <4254545+sbillinge@users.noreply.github.com> --- src/diffpy/srreal/__init__.py | 14 ++++++++++++++ tests/test_dll_loading.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 tests/test_dll_loading.py diff --git a/src/diffpy/srreal/__init__.py b/src/diffpy/srreal/__init__.py index 2beff97..ce99d60 100644 --- a/src/diffpy/srreal/__init__.py +++ b/src/diffpy/srreal/__init__.py @@ -14,6 +14,20 @@ ############################################################################## """Tools for real space structure analysis.""" +# Windows DLL loading fix for Python 3.8+ +# On Windows, add the conda library bin directory to DLL search path +# before importing extension modules that depend on DLLs +import os +import sys + +if sys.platform == "win32" and sys.version_info >= (3, 8): + # Try to add conda library bin directory to DLL search path + conda_prefix = os.environ.get("CONDA_PREFIX") + if conda_prefix: + lib_bin_dir = os.path.join(conda_prefix, "Library", "bin") + if os.path.isdir(lib_bin_dir): + os.add_dll_directory(lib_bin_dir) + # package version from diffpy.srreal.version import __version__ diff --git a/tests/test_dll_loading.py b/tests/test_dll_loading.py new file mode 100644 index 0000000..e3a37ad --- /dev/null +++ b/tests/test_dll_loading.py @@ -0,0 +1,33 @@ +"""Unit tests for Windows DLL loading initialization.""" + +import os +import sys + + +def test_import_succeeds(): + """Ensure diffpy.srreal can be imported successfully on all platforms.""" + import diffpy.srreal + + assert hasattr(diffpy.srreal, "__version__") + + +def test_windows_dll_directory_handling(): + """Verify Windows DLL directory handling doesn't raise errors.""" + # This test verifies that the Windows-specific DLL directory initialization + # in __init__.py doesn't cause issues on any platform. + + # The actual DLL directory logic is executed during module import, + # so if we got this far, it succeeded. + + # On Windows with Python 3.8+, verify the logic would have run + if sys.platform == "win32" and sys.version_info >= (3, 8): + # Check that CONDA_PREFIX environment variable handling works + conda_prefix = os.environ.get("CONDA_PREFIX") + if conda_prefix: + lib_bin_dir = os.path.join(conda_prefix, "Library", "bin") + # The directory should exist in a proper conda environment + # but we don't assert this as it may not exist in all test environments + assert isinstance(lib_bin_dir, str) + + # Test passes if no exceptions are raised + assert True From 2fc8be6bacf63635d6abcfd1760a1f666f97ab70 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 11 Feb 2026 14:39:28 +0000 Subject: [PATCH 3/4] Fix formatting issues in test_dll_loading.py Co-authored-by: sbillinge <4254545+sbillinge@users.noreply.github.com> --- tests/test_dll_loading.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tests/test_dll_loading.py b/tests/test_dll_loading.py index e3a37ad..b591c7a 100644 --- a/tests/test_dll_loading.py +++ b/tests/test_dll_loading.py @@ -13,12 +13,12 @@ def test_import_succeeds(): def test_windows_dll_directory_handling(): """Verify Windows DLL directory handling doesn't raise errors.""" - # This test verifies that the Windows-specific DLL directory initialization - # in __init__.py doesn't cause issues on any platform. - + # This test verifies that the Windows-specific DLL directory + # initialization in __init__.py doesn't cause issues on any platform. + # The actual DLL directory logic is executed during module import, # so if we got this far, it succeeded. - + # On Windows with Python 3.8+, verify the logic would have run if sys.platform == "win32" and sys.version_info >= (3, 8): # Check that CONDA_PREFIX environment variable handling works @@ -26,8 +26,9 @@ def test_windows_dll_directory_handling(): if conda_prefix: lib_bin_dir = os.path.join(conda_prefix, "Library", "bin") # The directory should exist in a proper conda environment - # but we don't assert this as it may not exist in all test environments + # but we don't assert this as it may not exist in all test + # environments assert isinstance(lib_bin_dir, str) - + # Test passes if no exceptions are raised assert True From 3cbbb9baf4835f7ecba2ad63dd7d36bf08f23503 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 11 Feb 2026 14:40:08 +0000 Subject: [PATCH 4/4] Remove redundant assertion in test_dll_loading.py Co-authored-by: sbillinge <4254545+sbillinge@users.noreply.github.com> --- tests/test_dll_loading.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/test_dll_loading.py b/tests/test_dll_loading.py index b591c7a..eefbc12 100644 --- a/tests/test_dll_loading.py +++ b/tests/test_dll_loading.py @@ -29,6 +29,3 @@ def test_windows_dll_directory_handling(): # but we don't assert this as it may not exist in all test # environments assert isinstance(lib_bin_dir, str) - - # Test passes if no exceptions are raised - assert True