Skip to content

Commit

Permalink
ci: fix mypy imports (#25)
Browse files Browse the repository at this point in the history
* ci: fix mypy imports

* ci: add mypy stubs path config and update github actions versions

* remove empty test file to fix coverage

* ci: try to fix coverage

* ci: fix coverage

* ci: fixing coverage by turning off numba during tests

* improve coverage

* ci: maybe this time?
  • Loading branch information
dgarnier authored Jul 2, 2023
1 parent cdfd250 commit ed594bf
Show file tree
Hide file tree
Showing 13 changed files with 364 additions and 87 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/constraints.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pip==23.0.1
nox==2022.11.21
pip==23.1.2
nox==2023.4.22
nox-poetry==1.0.2
poetry==1.3.2
virtualenv==20.15.0
poetry==1.5.1
poetry-dynamic-versioning==0.24.0
virtualenv==20.23.1
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
/src/*.egg-info/
__pycache__/
src/inductance/_version.py
tests/test_new_dipole.py
new_dipole.py
114 changes: 113 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 19 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ python = "^3.8"
numpy = "^1.24"
numba = "^0.57"

[tool.poetry.dev-dependencies]
[tool.poetry.group.dev.dependencies]
poetry = "^1.5.1"
poetry_dynamic_versioning = "^0.24.0"
nox = "^2023.4.22"
nox-poetry = "^1.0.0"
dunamai = "^1.17.0"
mpmath = "^1.0.0"

[tool.poetry-dynamic-versioning]
enable = true
Expand All @@ -36,5 +38,21 @@ build-backend = "poetry_dynamic_versioning.backend"
extend-exclude = '''
( src/elliptics.py )
'''

[tool.isort]
profile = "black"

[tool.mypy]
mypy_path = "stubs"

[tool.coverage.paths]
source = ["src", "*/site-packages"]
tests = ["tests", "*/tests"]

[tool.coverage.run]
branch = true
source = ["inductance"]

[tool.coverage.report]
show_missing = true
fail_under = 50
20 changes: 12 additions & 8 deletions src/inductance/elliptics.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,20 @@
"""

from math import log
from typing import Tuple

# use numba if its installed
try:
from numba import jit_module
from numba import njit

except ImportError:
from warnings import warn_explicit

warning = "Couldn't import Numba. Elliptic integrals will run slower than expected."
warn_explicit(warning, RuntimeWarning, "elliptics.py", 0)
except ImportError: # pragma: no cover
from warnings import warn

WARNING = "Couldn't import Numba. Elliptic integrals will run slower than expected."
warn(WARNING, RuntimeWarning)

# fmt: off
@njit("UniTuple(float64, 2)(float64)")
def celbd(mc):
"""Complete elliptic integrals of second kind, B(m) and D(m).
Expand Down Expand Up @@ -504,6 +505,7 @@ def celbd(mc):
# fmt: on


@njit("UniTuple(f8, 2)(f8)")
def ellipke(k2):
"""Complete elliptic integrals of first and second kind.
Expand All @@ -513,11 +515,12 @@ def ellipke(k2):
Returns:
(float, float): Elliptic integrals K(k^2) and E(k^2).
"""
mc = 1.0 - k2
mc = 1.0e0 - k2
elb, eld = celbd(mc)
return (elb + eld, elb + mc * eld)


@njit(["f8(f8)"])
def ellipk(k2):
"""Complete elliptic integral of the first kind.
Expand All @@ -531,6 +534,7 @@ def ellipk(k2):
return k


@njit(["f8(f8)"])
def ellipe(k2):
"""Complete elliptic integral of the second kind.
Expand All @@ -544,4 +548,4 @@ def ellipe(k2):
return e


jit_module(nopython=True, fastmath=True, error_model="numpy")
# jit_module(nopython=True, fastmath=True, error_model="numpy")
Loading

0 comments on commit ed594bf

Please sign in to comment.