Skip to content

Commit

Permalink
Merge pull request #759 from DHI/typed
Browse files Browse the repository at this point in the history
Indicate that MIKE IO uses type hints
  • Loading branch information
ecomodeller authored Nov 29, 2024
2 parents daf0dc3 + a885b6c commit 504d2ad
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 57 deletions.
39 changes: 16 additions & 23 deletions mikeio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,13 @@
from collections.abc import Sequence
from typing import Any

# PEP0440 compatible formatted version, see:
# https://www.python.org/dev/peps/pep-0440/
#
# Generic release markers:
# X.Y
# X.Y.Z # For bugfix releases
#
# Admissible pre-release markers:
# X.YaN # Alpha release
# X.YbN # Beta release
# X.YrcN # Release Candidate
# X.Y # Final release
#
# 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'
#

try:
# read version from installed package
__version__ = version("mikeio")
except PackageNotFoundError:
# package is not installed
__version__ = "dev"

# __version__ = "2.2.dev2" # TODO use git hash instead for dev version?
# __version__ = "1.5.0"
__dfs_version__: int = 220


Expand All @@ -39,16 +20,17 @@

from .dataset import DataArray, Dataset, from_pandas, from_polars
from .dfs import Dfs0, Dfs1, Dfs2, Dfs3
from .dfsu import Dfsu, Mesh
from .dfsu import Dfsu, Mesh, Dfsu2DH, Dfsu2DV, Dfsu3D, DfsuSpectral
from .eum import EUMType, EUMUnit, ItemInfo
from .pfs import PfsDocument, PfsSection, read_pfs

# Grid geometries are imported into the main module, since they are used to create dfs files
# Other geometries are available in the spatial module
from .spatial import (
Grid1D,
Grid2D,
Grid3D,
GeometryFM2D,
GeometryFM3D,
GeometryFMVerticalProfile,
)

from .xyz import read_xyz
Expand Down Expand Up @@ -142,11 +124,15 @@ def read(
raise ValueError("mikeio.read() is only supported for Dfs files")

dfs = open(filename)
if isinstance(dfs, Mesh):
raise ValueError("mikeio.read() is not supported for Mesh files")

return dfs.read(items=items, time=time, keepdims=keepdims, **kwargs)


def open(filename: str | Path, **kwargs: Any) -> Any:
def open(
filename: str | Path, **kwargs: Any
) -> Dfs0 | Dfs1 | Dfs2 | Dfs3 | Dfsu2DH | Dfsu2DV | Dfsu3D | DfsuSpectral | Mesh:
"""Open a dfs/mesh file (and read the header).
The typical workflow for small dfs files is to read all data
Expand Down Expand Up @@ -208,6 +194,10 @@ def open(filename: str | Path, **kwargs: Any) -> Any:
"Dfs2",
"Dfs3",
"Dfsu",
"Dfsu2DH",
"Dfsu2DV",
"Dfsu3D",
"DfsuSpectral",
"Mesh",
"EUMType",
"EUMUnit",
Expand All @@ -219,6 +209,9 @@ def open(filename: str | Path, **kwargs: Any) -> Any:
"Grid1D",
"Grid2D",
"Grid3D",
"GeometryFM2D",
"GeometryFM3D",
"GeometryFMVerticalProfile",
"read_xyz",
"read",
"open",
Expand Down
Empty file added mikeio/py.typed
Empty file.
100 changes: 66 additions & 34 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,25 @@
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.hatch.build]
license-files = { paths = ["License.txt"] }

[tool.hatch.build.targets.sdist]
exclude = ["notebooks", "tests", "images", ".github", "docs", ".devcontainer", "*.md", "*.txt", ".gitattributes"]
exclude = [
"notebooks",
"tests",
"images",
".github",
"docs",
".devcontainer",
"*.md",
"*.txt",
".gitattributes",
]

[project]
name="mikeio"
version="2.2.dev3"
name = "mikeio"
version = "2.2.dev3"
dependencies = [
"mikecore>=0.2.1",
"numpy>=1.22.0",
Expand All @@ -20,11 +33,11 @@ dependencies = [
]

authors = [
{ name="Henrik Andersson",email="[email protected]"},
{ name = "Jesper Sandvig Mariegaard", email="[email protected]" }
{ name = "Henrik Andersson", email = "[email protected]" },
{ name = "Jesper Sandvig Mariegaard", email = "[email protected]" },
]
description="A package that uses the DHI dfs libraries to create, write and read dfs and mesh files."
license="BSD-3-Clause"
description = "A package that uses the DHI dfs libraries to create, write and read dfs and mesh files."
license = "BSD-3-Clause"
readme = "README.md"
requires-python = ">=3.10"
classifiers = [
Expand All @@ -41,34 +54,43 @@ classifiers = [
]

[project.optional-dependencies]
dev = ["pytest",
"quarto-cli",
"quartodoc==0.9.1",
"shapely",
"pyproj",
"xarray",
"netcdf4",
"rasterio",
"polars",
"ruff==0.6.2",
"mypy==1.11.1",
]
dev = [
"pytest",
"quarto-cli",
"quartodoc==0.9.1",
"shapely",
"pyproj",
"xarray",
"netcdf4",
"rasterio",
"polars",
"ruff==0.6.2",
"mypy==1.11.1",
]

test = ["pytest", "pytest-cov", "xarray","mypy==1.11.1","shapely","pyproj", "polars"]
test = [
"pytest",
"pytest-cov",
"xarray",
"mypy==1.11.1",
"shapely",
"pyproj",
"polars",
]

notebooks= [
"nbformat",
"nbconvert",
"jupyter",
"xarray",
"netcdf4",
"rasterio",
"geopandas",
"scikit-learn",
"matplotlib",
"folium",
"mapclassify",
]
notebooks = [
"nbformat",
"nbconvert",
"jupyter",
"xarray",
"netcdf4",
"rasterio",
"geopandas",
"scikit-learn",
"matplotlib",
"folium",
"mapclassify",
]

[project.urls]
"Homepage" = "https://github.com/DHI/mikeio"
Expand All @@ -80,4 +102,14 @@ notebooks= [
# ignore long lines
ignore = ["E501", "E741"]

select = ["D100", "D101", "D102", "D103", "D202", "D212", "D413", "D415", "D417"]
select = [
"D100",
"D101",
"D102",
"D103",
"D202",
"D212",
"D413",
"D415",
"D417",
]

0 comments on commit 504d2ad

Please sign in to comment.