Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix loading of MIKE IO 1D when MIKE+Py is present. #90

Merged
merged 2 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@

### Added


### Fixed


### Changed

## [0.6.1] - 2024-02-024

### Fixed

- Loading MIKE IO 1D together with MIKE+Py

## [0.6] - 2024-02-08

Expand Down Expand Up @@ -121,7 +124,8 @@
- Reading of res1d and xns11 files into pandas data frames


[unreleased]: https://github.com/DHI/mikeio1d/compare/v0.6...HEAD
[unreleased]: https://github.com/DHI/mikeio1d/compare/v0.6.1...HEAD
[0.6.1]: https://github.com/DHI/mikeio1d/releases/tag/v0.6.1
[0.6]: https://github.com/DHI/mikeio1d/releases/tag/v0.6
[0.5]: https://github.com/DHI/mikeio1d/releases/tag/v0.5
[0.4.1]: https://github.com/DHI/mikeio1d/releases/tag/v0.4.1
Expand Down
2 changes: 1 addition & 1 deletion mikeio1d/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# Dev branch marker is: 'X.Y.dev' or 'X.Y.devN' where N is an integer.
# 'X.Y.dev0' is the canonical version of 'X.Y.dev'
#
__version__ = "0.6.0"
__version__ = "0.6.1"

if "64" not in platform.architecture()[0]:
raise Exception("This library has not been tested for a 32 bit system.")
Expand Down
26 changes: 24 additions & 2 deletions mikeio1d/mikepath.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import sys
import platform
import pythonnet

Expand All @@ -25,6 +26,8 @@ class MikePath:

mikeio1d_bin_path = os.path.join(os.path.dirname(__file__), "bin")

mikeio1d_bin_extra_path = os.path.join(os.path.dirname(__file__), "bin/DHI.Mike1D.MikeIO")

mike_install_path = os.environ.get("MIKE_INSTALL_PATH", None)

skip_bin_x64 = os.environ.get("MIKE_SKIP_BIN_X64", None)
Expand All @@ -49,7 +52,10 @@ def setup_mike_installation(syspath):
syspath: list of str
List of strings defining PATH variable.
"""
MikePath.update_mike_bin_to_mikepluspy_bin_if_used()

syspath.append(MikePath.mike_bin_path)
syspath.append(MikePath.mikeio1d_bin_extra_path)

if MikePath.is_linux:
MikePath.setup_mike_installation_linux()
Expand All @@ -58,9 +64,25 @@ def setup_mike_installation(syspath):
MikePath.setup_mike_installation_custom(syspath)

@staticmethod
def setup_mike_installation_custom(syspath):
syspath.append(MikePath.mikeio1d_bin_path)
def update_mike_bin_to_mikepluspy_bin_if_used():
"""
Updates the path for MIKE assemblies to the ones used by MIKE+Py package.
This requires that the MIKE+Py package was already loaded.
"""
mikepluspy = sys.modules.get("mikeplus")
if mikepluspy == None:
return

import mikeplus

mikeplus_bin_path = str(mikeplus.MikeImport.ActiveProduct().InstallRoot)
mikeplus_bin_path = os.path.join(mikeplus_bin_path, MikePath.bin_x64)

MikePath.mikeio1d_bin_path = mikeplus_bin_path
MikePath.mike_bin_path = mikeplus_bin_path

@staticmethod
def setup_mike_installation_custom(syspath):
# Some of the MIKE libraries will need to be resolved by DHI.Mike.Install,
# so set it up here.
import clr
Expand Down
3 changes: 2 additions & 1 deletion scripts/util_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class UtilBuilder:
build_dir_name = os.path.join("bin", "Release", "netstandard2.0")

# Directory where libraries will be installed
bin_dir_name = os.path.join("mikeio1d", "bin")
bin_dir_name = os.path.join("mikeio1d", "bin", "DHI.Mike1D.MikeIO")

# Utility libraries to build and install
library_names = ["DHI.Mike1D.MikeIO"]
Expand Down Expand Up @@ -57,6 +57,7 @@ def copy_libraries_to_bin(self):
print(f" Copying file: {source_file_path_stripped}")
_, file_name = os.path.split(source_file)
destination_file = os.path.join(destination, file_name)
os.makedirs(destination, exist_ok=True)
shutil.copy2(source_file, destination_file)

def strip_source_file_path(self, file_path):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

setuptools.setup(
name="mikeio1d",
version="0.6.0",
version="0.6.1",
install_requires=[
"pythonnet>=3.0.0",
"numpy",
Expand Down
Loading