Skip to content

Commit

Permalink
Add typehints; build Python 3.12 (#17)
Browse files Browse the repository at this point in the history
* add type hints

* finalize typehints:

* clean up PYBIN

* Python 3.8 typing compatiblity

* skip python 3.12 for win nt plotting
  • Loading branch information
akaszynski authored Oct 31, 2023
1 parent ff383e4 commit 5169198
Show file tree
Hide file tree
Showing 15 changed files with 366 additions and 204 deletions.
18 changes: 1 addition & 17 deletions .ci/build_wheels.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,7 @@ set -e -x

# build based on python version from args
PYTHON_VERSION="$1"
case $PYTHON_VERSION in
3.7)
PYBIN="/opt/python/cp37-cp37m/bin"
;;
3.8)
PYBIN="/opt/python/cp38-cp38/bin"
;;
3.9)
PYBIN="/opt/python/cp39-cp39/bin"
;;
3.10)
PYBIN="/opt/python/cp310-cp310/bin"
;;
3.11)
PYBIN="/opt/python/cp311-cp311/bin"
;;
esac
PYBIN="/opt/python/cp${PYTHON_VERSION//.}-cp${PYTHON_VERSION//.}/bin"

# build, don't install
cd io
Expand Down
8 changes: 0 additions & 8 deletions .flake8

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/testing-and-deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11']
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
os: [ubuntu-latest, windows-latest]

steps:
Expand Down
31 changes: 23 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ ci:

repos:

- repo: https://github.com/psf/black
rev: 23.9.1
hooks:
- id: black

- repo: https://github.com/keewis/blackdoc
rev: v0.3.8
hooks:
Expand All @@ -25,10 +20,19 @@ repos:
"--skip-glob", "*__init__.py",
]

- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.3
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
exclude: ^(doc/|tests)
- id: ruff-format

- repo: https://github.com/keewis/blackdoc
rev: v0.3.8
hooks:
- id: flake8
- id: blackdoc
files: '\.py$'

- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
Expand All @@ -53,6 +57,17 @@ repos:
mapdl_archive/cython/[^_].*\.c.*
)$
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.6.1
hooks:
- id: mypy
exclude: ^(doc/|tests)
additional_dependencies: [
"mypy-extensions==1.0.0",
"toml==0.10.2",
"numpy",
]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
Expand Down
12 changes: 8 additions & 4 deletions mapdl_archive/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
"""MAPDL archive reader."""

from mapdl_archive import examples
from mapdl_archive._version import __version__
from mapdl_archive.archive import Archive, save_as_archive, write_cmblock, write_nblock
from mapdl_archive import examples # noqa: F401
from mapdl_archive._version import __version__ # noqa: F401
from mapdl_archive.archive import ( # noqa: F401
Archive,
save_as_archive,
write_cmblock,
write_nblock,
)
36 changes: 36 additions & 0 deletions mapdl_archive/_archive.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import numpy as np
import numpy.typing as npt

def py_write_nblock(
filename: str,
node_id: npt.NDArray[np.int32],
max_node_id: int,
pos: npt.NDArray[np.float64],
angles: npt.NDArray[np.float64],
mode: str = "w",
sig_digits: int = 13,
) -> None: ...
def py_write_nblock_float(
filename: str,
node_id: npt.NDArray[np.int32],
max_node_id: int,
pos: npt.NDArray[np.float32],
angles: npt.NDArray[np.float32],
mode: str = "w",
sig_digits: int = 13,
) -> None: ...
def py_write_eblock(
filename: str,
elem_id: npt.NDArray[np.int32],
etype: npt.NDArray[np.int32],
mtype: npt.NDArray[np.int32],
rcon: npt.NDArray[np.int32],
elem_nnodes: npt.NDArray[np.int32],
cells: npt.NDArray[np.int32],
offset: npt.NDArray[np.int32],
celltypes: npt.NDArray[np.uint8],
typenum: npt.NDArray[np.int32],
nodenum: npt.NDArray[np.int32],
mode: str = "w",
) -> None: ...
def cmblock_items_from_array(array: npt.NDArray[np.int32]) -> npt.NDArray[np.int32]: ...
40 changes: 40 additions & 0 deletions mapdl_archive/_reader.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from typing import Dict, List, Tuple, TypedDict, Union

import numpy as np
import numpy.typing as npt

class ReadReturnDict(TypedDict):
rnum: npt.NDArray[np.int64]
rdat: List[List[float]]
ekey: npt.NDArray[np.int32]
nnum: npt.NDArray[np.int32]
nodes: npt.NDArray[np.float64]
elem: npt.NDArray[np.int32]
elem_off: npt.NDArray[np.int32]
node_comps: Dict[str, npt.NDArray[np.int32]]
elem_comps: Dict[str, npt.NDArray[np.int32]]
keyopt: Dict[int, List[List[int]]]
parameters: Dict[str, np.ndarray]
nblock_start: int
nblock_end: int

def read(
filename: str,
read_parameters: bool = False,
debug: bool = False,
read_eblock: bool = True,
) -> ReadReturnDict: ...
def node_block_format(
string: Union[bytes, str]
) -> Tuple[npt.NDArray[np.int32], int, int, int]: ...
def ans_vtk_convert(
elem: npt.NDArray[np.int32],
elem_off: npt.NDArray[np.int32],
type_ref: npt.NDArray[np.int32],
nnum: npt.NDArray[np.int32],
build_offset: int,
) -> Tuple[npt.NDArray[np.int64], npt.NDArray[np.uint8], npt.NDArray[np.int64]]: ...
def read_from_nwrite(
filename: str, nnodes: int
) -> Tuple[npt.NDArray[np.int32], npt.NDArray[np.float64]]: ...
def write_array(filename: str, arr: npt.NDArray[np.float64]) -> None: ...
9 changes: 9 additions & 0 deletions mapdl_archive/_relaxmidside.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import numpy as np
import numpy.typing as npt

def reset_midside(
cellarr: npt.NDArray[np.int64],
celltypes: npt.NDArray[np.uint8],
offset: npt.NDArray[np.int64],
pts: npt.NDArray[np.float64],
) -> None: ...
Loading

0 comments on commit 5169198

Please sign in to comment.