Skip to content

Make package init cross-platform: fix Windows-only APIs and add configurable bin path suffix - #114

Draft
ryan-kipawa with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-cross-platform-init
Draft

Make package init cross-platform: fix Windows-only APIs and add configurable bin path suffix#114
ryan-kipawa with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-cross-platform-init

Conversation

Copilot AI commented Feb 24, 2026

Copy link
Copy Markdown
Contributor

The package init in utils.py used os.add_dll_directory (Windows-only) unconditionally and hardcoded ";" as the PATH separator, breaking on Linux/macOS. The bin folder suffix (bin/x64) was also hardcoded with no env var override, unlike the install root.

Changes

  • os.add_dll_directory: Guarded all call sites with sys.platform == "win32"; returns None on other platforms
  • PATH separator: Replaced hardcoded ";" with os.pathsep in _update_python_env_path and _try_mike_install_bin_setup
  • Configurable bin path suffix: The MIKEPLUSPY_INSTALL_BIN environment variable is resolved at the call site in __init__.py and passed directly as bin_path, mirroring how MIKEPLUSPY_INSTALL_ROOT works for the install root
# Override the bin folder suffix (relative path, e.g. for a different architecture)
os.environ["MIKEPLUSPY_INSTALL_BIN"] = "bin/arm64"
import mikeplus
  • Warning messages: Added helpful warnings for all possible outcomes in setup_bin_path:
    • When a custom install root env var is set, warns with the resolved path and bin directory being used
    • When DHI.Mike.Install auto-detection fails, warns with the exception detail before falling back
    • When the default fallback path is used, the existing warning is retained
    • When the custom bin path does not exist, the FileNotFoundError includes the env var name, its value, and a hint to unset it for auto-detection
Original prompt

The package init sets up both the Python and .NET environments to find assemblies and native libraries. Fix it to be cross platform (e.g. os.add_dll_directory is windows only), and make the bin folder suffix configurable the same way as the MIKE+ install root is.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

…os.pathsep, add MIKEPLUSPY_INSTALL_BIN env var

Co-authored-by: ryan-kipawa <74630349+ryan-kipawa@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix package init for cross-platform compatibility Make package init cross-platform: fix Windows-only APIs and add configurable bin path suffix Feb 24, 2026
Copilot AI requested a review from ryan-kipawa February 24, 2026 07:45
Comment thread mikeplus/__init__.py Outdated
fallback_mikeplus_install_root=Path("C:/Program Files (x86)/DHI/MIKE+/2026"),
env_var_name_install_root="MIKEPLUSPY_INSTALL_ROOT", # set this environment variable to use custom install path
bin_path=Path("bin/x64"),
env_var_name_bin_path="MIKEPLUSPY_INSTALL_BIN", # set this environment variable to use a custom bin path suffix (e.g. 'bin/x64')

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Combine this with the line above to just check that environment variable, and if not, pass the default. No need to pass the env variable name.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 8dd2f5a. The MIKEPLUSPY_INSTALL_BIN env var is now resolved at the call site via os.getenv("MIKEPLUSPY_INSTALL_BIN", "bin/x64"), and the env_var_name_bin_path parameter has been removed from setup_bin_path.

Comment thread mikeplus/utils.py
_setup_called = False


def setup_bin_path(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review this entire method to ensure it's functioning as intended. There should be helpful warning messages to the user to all possible outcomes that let them take corrective action.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 8dd2f5a. Added warning messages for all outcomes:

  • Custom install root used: warns with the resolved path so the user can verify it's correct.
  • DHI.Mike.Install auto-detection fails: warns with the exception message so the user knows why, and that it's falling back.
  • Falling back to default path: existing warning already in place, kept as-is.
  • Custom path not found: FileNotFoundError now includes the env var name, its value, and a hint to unset it for auto-detection.

…r all setup_bin_path outcomes

Co-authored-by: ryan-kipawa <74630349+ryan-kipawa@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants