Skip to content

Commit

Permalink
rfcnt-0.4.6
Browse files Browse the repository at this point in the history
- Added function signature
  • Loading branch information
a-ma72 committed Jan 3, 2023
1 parent 54aa609 commit 089f6c2
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 30 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# CMakeLists for rainflow
# 2022, Andreas Martin
# 2023, Andreas Martin

# First set Matlab_ROOT_DIR environment variable to your installed matlab path,
# such as 'export Matlab_ROOT_DIR=/usr/local/MATLAB/R2017b'!
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BSD 2-Clause License

Copyright (c) 2022, Andreas Martin
Copyright (c) 2023, Andreas Martin
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
2 changes: 1 addition & 1 deletion python/LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BSD 2-Clause License

Copyright (c) 2022, Andreas Martin
Copyright (c) 2023, Andreas Martin
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
2 changes: 1 addition & 1 deletion python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ predefined functions.
pip install {packagename}.tar.gz --no-build-isolation --no-deps
where _{packagename}_ is the current package release, for example:

pip install rfcnt-0.4.5.tar.gz --no-build-isolation --no-deps
pip install rfcnt-0.4.6.tar.gz --no-build-isolation --no-deps

### Test
_rfcnt_ packages include some unit tests, which can be run:
Expand Down
38 changes: 22 additions & 16 deletions python/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import os
import sys
from enum import IntEnum
from importlib.util import module_from_spec, spec_from_file_location
from typing import Union


class ResidualMethod(IntEnum):
Expand Down Expand Up @@ -36,16 +32,25 @@ class LCMethod(IntEnum):
SLOPES_ALL = 3


def _load_spec_extension_module():
"""Select and load a suitable extension build"""
from numpy import __version__ as np__version__
from numpy import ndarray
def _npy_version():
"""Query numpy version.
(See <https://numpy.org/doc/stable/reference/generated/numpy.lib.NumpyVersion.html>)
"""
from numpy import __version__ as version
from numpy.lib import NumpyVersion

return NumpyVersion(version)


def _load_spec_extension_module():
"""Select and load a suitable extension build"""
import os, sys
from importlib.util import module_from_spec, spec_from_file_location
EXT_DIR = "_ext"

# see `numpy/numpy/core/include/numpy/numpyconfig.h`
npy_version = NumpyVersion(np__version__)
assert sys.version_info >= (3, 9)

npy_version = _npy_version()
if npy_version < '1.20.0':
# API version 0x8
infix = "npy_1_19_5"
Expand All @@ -59,11 +64,6 @@ def _load_spec_extension_module():
# API version 0x10
infix = "npy_1_23_5"

if npy_version >= "1.20.0":
from numpy.typing import ArrayLike
else:
ArrayLike = Union[list, ndarray] # noqa F841

modulename = [file for file in os.listdir(os.path.join(__path__[0], EXT_DIR)) if infix in file]

if len(modulename) == 1:
Expand All @@ -74,7 +74,13 @@ def _load_spec_extension_module():
del spec, module, npy_version, infix
else:
raise ImportError("No suitable build found for numpy %s!",
np__version__)
npy_version.vstring)


if _npy_version() >= "1.20.0":
from numpy.typing import ArrayLike
else:
from typing import Any as ArrayLike


# Try to import the extension module, compiled from sources.
Expand Down
11 changes: 6 additions & 5 deletions python/setup.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from os import path
from setuptools import setup, Extension

version = (0, 4, 5, ".post2")
version = (0, 4, 6)

try:
from numpy import __version__ as np_version
from numpy import get_include as get_numpy_include
from numpy import get_include as np_get_include
except ImportError:
def get_numpy_include():
np_version = "NUMPY_NOTFOUND"
def np_get_include():
return "NUMPY_NOTFOUND"

def main():
Expand Down Expand Up @@ -38,7 +39,7 @@ def main():

setup(
name="rfcnt",
version="%d.%d.%d%s" % version,
version="%d.%d.%d" % version,
description="Python interface for rainflow counting",
long_description=long_description,
long_description_content_type='text/markdown',
Expand All @@ -61,7 +62,7 @@ def main():
Extension(
"rfcnt.rfcnt", ["src/rfcnt.cpp"],
define_macros=define_macros,
include_dirs=['src', get_numpy_include()],
include_dirs=['src', np_get_include()],
extra_compile_args=['-std=c++11'],
)
],
Expand Down
2 changes: 1 addition & 1 deletion python/src/rainflow.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
*================================================================================
* BSD 2-Clause License
*
* Copyright (c) 2022, Andras Martin
* Copyright (c) 2023, Andras Martin
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down
2 changes: 1 addition & 1 deletion python/src/rainflow.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
*================================================================================
* BSD 2-Clause License
*
* Copyright (c) 2022, Andras Martin
* Copyright (c) 2023, Andras Martin
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down
2 changes: 1 addition & 1 deletion src/rainflow.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
*================================================================================
* BSD 2-Clause License
*
* Copyright (c) 2022, Andras Martin
* Copyright (c) 2023, Andras Martin
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down
2 changes: 1 addition & 1 deletion src/rainflow.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
*================================================================================
* BSD 2-Clause License
*
* Copyright (c) 2022, Andras Martin
* Copyright (c) 2023, Andras Martin
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down
2 changes: 1 addition & 1 deletion test/rfc_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*================================================================================
* BSD 2-Clause License
*
* Copyright (c) 2022, Andras Martin
* Copyright (c) 2023, Andras Martin
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down

0 comments on commit 089f6c2

Please sign in to comment.