Skip to content

Commit

Permalink
....
Browse files Browse the repository at this point in the history
  • Loading branch information
dweindl committed Apr 16, 2024
1 parent eb4d7e7 commit 3ef331a
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 23 deletions.
28 changes: 21 additions & 7 deletions documentation/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,33 @@
import subprocess
import sys
from enum import EnumType

# need to import before setting typing.TYPE_CHECKING=True, fails otherwise
import amici
import exhale.deploy
import exhale_multiproject_monkeypatch
from unittest import mock
import pandas as pd
import sphinx
import sympy as sp
from exhale import configs as exhale_configs
from sphinx.transforms.post_transforms import ReferencesResolver

exhale_multiproject_monkeypatch, pd, sp # to avoid removal of unused import
try:
import exhale_multiproject_monkeypatch # noqa: F401
except ModuleNotFoundError:
# for unclear reasons, the import of exhale_multiproject_monkeypatch
# fails on some systems, because the the location of the editable install
# is not automatically added to sys.path ¯\_(ツ)_/¯
from importlib.metadata import Distribution
import json
from urllib.parse import unquote_plus, urlparse

dist = Distribution.from_name("sphinx-contrib-exhale-multiproject")
url = json.loads(dist.read_text("direct_url.json"))["url"]
package_dir = unquote_plus(urlparse(url).path)
sys.path.append(package_dir)
import exhale_multiproject_monkeypatch # noqa: F401

# need to import before setting typing.TYPE_CHECKING=True, fails otherwise
import amici
import pandas as pd # noqa: F401
import sympy as sp # noqa: F401


# BEGIN Monkeypatch exhale
from exhale.deploy import _generate_doxygen as exhale_generate_doxygen
Expand Down
2 changes: 1 addition & 1 deletion python/sdist/amici/swig.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def _annotation_from_docstring(self, node: ast.FunctionDef):
@staticmethod
def extract_type(line: str) -> tuple[str, str] | tuple[None, None]:
"""Extract argument name and type string from ``:type:`` docstring line."""
match = re.match(r"\s*:type\s+(\w+):\s+(.+)\s*$", line)
match = re.match(r"\s*:type\s+(\w+):\s+(.+)(?:, optional)?\s*$", line)
if not match:
return None, None

Expand Down
21 changes: 7 additions & 14 deletions python/sdist/amici/swig_wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@
import warnings
from contextlib import contextmanager, suppress
from typing import Any, Optional, Union
from collections.abc import Sequence

import amici
import amici.amici as amici_swig
from amici.amici import _get_ptr
from amici.amici import (
_get_ptr,
AmiciExpData,
AmiciExpDataVector,
AmiciModel,
AmiciSolver,
)
from . import numpy
from .logging import get_logger

Expand All @@ -22,20 +27,8 @@
"writeSolverSettingsToHDF5",
"set_model_settings",
"get_model_settings",
"AmiciModel",
"AmiciSolver",
"AmiciExpData",
"AmiciReturnData",
"AmiciExpDataVector",
]

AmiciModel = Union["amici.Model", "amici.ModelPtr"]
AmiciSolver = Union["amici.Solver", "amici.SolverPtr"]
AmiciExpData = Union["amici.ExpData", "amici.ExpDataPtr"]
AmiciReturnData = Union["amici.ReturnData", "amici.ReturnDataPtr"]
AmiciExpDataVector = Union["amici.ExpDataPtrVector", Sequence[AmiciExpData]]


try:
from wurlitzer import sys_pipes
except ModuleNotFoundError:
Expand Down
8 changes: 7 additions & 1 deletion swig/amici.i
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,8 @@ if sys.platform == 'win32' and (dll_dirs := os.environ.get('AMICI_DLL_DIRS')):
// import additional types for typehints
// also import np for use in __repr__ functions
%pythonbegin %{
from typing import TYPE_CHECKING, Iterable, Sequence
from typing import TYPE_CHECKING, Iterable
from collections.abc import Sequence
import numpy as np
if TYPE_CHECKING:
import numpy
Expand All @@ -371,6 +372,11 @@ __all__ = [
and x not in {"np", "sys", "os", "numpy", "IntEnum", "enum", "pi", "TYPE_CHECKING", "Iterable", "Sequence"}
]

AmiciModel = Model | ModelPtr
AmiciSolver = Solver | SolverPtr
AmiciExpData = ExpData | ExpDataPtr
AmiciReturnData = ReturnData | ReturnDataPtr
AmiciExpDataVector = ExpDataPtrVector | Sequence[AmiciExpData]

def _get_ptr(
obj: AmiciModel | AmiciExpData | AmiciSolver | AmiciReturnData,
Expand Down
2 changes: 2 additions & 0 deletions swig/misc.i
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
%ignore amici::regexErrorToString;
%ignore amici::writeSlice;
%ignore ContextManager;
%ignore amici::scaleParameters;
%ignore amici::unscaleParameters;

// Add necessary symbols to generated header
%{
Expand Down

0 comments on commit 3ef331a

Please sign in to comment.