Skip to content

Commit

Permalink
Merge pull request #85 from DHI/fix_warnings_of_compatibility_with_ot…
Browse files Browse the repository at this point in the history
…her_packages

Fix warnings of compatibility with other packages
  • Loading branch information
ryan-kipawa authored Feb 13, 2025
2 parents 125b0d8 + 9a66115 commit 58acf9c
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 19 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

## [Unreleased]

## [2025.0.1] - 2025-02-12

### Added
- Better compatibility warnings for MIKE IO and MIKE IO 1D.
- Override of compatibiltiy warnings with environment variable "MIKEPLUSPY_DISABLE_CONFLICT_CHECKS"

### Added
- Support for MIKE+ 2025.

## [2025.0.0] - 2025-11-28

### Added
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ The version of MIKE+Py you install must match the version of MIKE+ installed on
## Examples
Please check out our [collection of jupyter notebooks] (https://github.com/DHI/mikepluspy/tree/main/notebooks) to get started with MIKE+Py.

## Known issues

There's currently a known issue of using MIKE+Py together with MIKE IO and MIKE IO 1D. We are working on fixing this and appreciate your patience.

Workarounds:
* Importing MIKE IO 1D *after* MIKE+Py will work.
* Using Python's multiprocessing library to split imports (and workflows) into separate processes.
* Split MIKE IO and MIKE+Py / MIKE IO 1D workflows into separate scripts.

## Where can I get help?
* Bugs - [GitHub Issues](https://github.com/DHI/mikepluspy/issues)
* Feature requests - [GitHub Issues](https://github.com/DHI/mikepluspy/issues)
Expand Down
8 changes: 6 additions & 2 deletions mikeplus/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import clr
__version__ = "2025.0.1"

__version__ = "2025.0.0"
from .conflicts import check_conflicts

check_conflicts()

import clr # noqa: E402

clr.AddReference(
"DHI.Mike.Install, Version=1.0.0.0, Culture=neutral, PublicKeyToken=c513450b5d0bf0bf"
Expand Down
36 changes: 36 additions & 0 deletions mikeplus/conflicts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""Provides useful warnings about conflicts related to usage alongside mikeio and mikeio1d."""

import sys
import os

MIKEIO1D_IMPORTED_BEFORE_MIKEPLUS = "mikeio1d" in sys.modules
DISABLE_CONFLICT_CHECKS = (
os.getenv("MIKEPLUSPY_DISABLE_CONFLICT_CHECKS", "false").lower() == "true"
)


def check_conflicts():
"""Check for conflicts with mikeio and mikeio1d.
This function checks if mikeio1d was imported before mikeplus. If so, it raises an error
that mikeio1d must be imported after mikeplus.
It also checks if mikeio is imported. If so, it raises an error that mikeio cannot currently
be used in same process as mikeplus.
"""

if DISABLE_CONFLICT_CHECKS:
return

if MIKEIO1D_IMPORTED_BEFORE_MIKEPLUS:
raise ImportError(
"mikeio1d must be imported after mikeplus to avoid conflicts. See docs for more info."
)

if "mikeio" in sys.modules:
raise ImportError(
"""mikeio cannot currently be used in same process as mikeplus.
Workarounds include splitting code into separate scripts or using
Python's multiprocessing library to import mikeio and mikeplus in
separate processes. See docs for more info."""
)
18 changes: 2 additions & 16 deletions mikeplus/datatableaccess.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from .dotnet import as_dotnet_list
from .dotnet import from_dotnet_datetime
from .dotnet import to_dotnet_datetime
from .conflicts import check_conflicts
from datetime import datetime
from warnings import warn

Expand Down Expand Up @@ -64,7 +65,7 @@ def __repr__(self):

def open_database(self):
"""Open database"""
self._check_conflict()
check_conflicts()
if self.is_database_open():
return
data_source = BaseDataSource.Create(self._file_path)
Expand Down Expand Up @@ -351,21 +352,6 @@ def is_database_open(self):
)
return is_open

def _check_conflict(self):
"""Check if there are conflicts with mikeio and mikeioid"""

mike1dio = sys.modules.get("mikeio1d")
if mike1dio is not None:
raise RuntimeError(
"mikeio1d module has been loaded. mikeio1d only can be loaded after mikeplus module."
)

mikeio = sys.modules.get("mikeio")
if mikeio is not None:
raise RuntimeError(
"mikeplus cannot currently be used with mikeio in the same script."
)

def _create_datatables(self):
datatables = DataTableContainer(True)
return datatables
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ exclude = ["notebooks", "tests"]

[project]
name = "mikeplus"
version = "2025.0.0"
version = "2025.0.1"
dependencies = [
"numpy",
'pythonnet>=3.0',
Expand Down

0 comments on commit 58acf9c

Please sign in to comment.