Skip to content

Commit

Permalink
merge: pr #15 from joshua-auchincloss/v0.2.4
Browse files Browse the repository at this point in the history
v0.2.4
  • Loading branch information
joshua-auchincloss authored Aug 29, 2023
2 parents 51427d4 + bb12667 commit 1fcf9aa
Show file tree
Hide file tree
Showing 24 changed files with 622 additions and 477 deletions.
28 changes: 18 additions & 10 deletions COVERAGE.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
| Name | Stmts | Miss | Branch | BrPart | Cover |
|---------------------------------- | -------: | -------: | -------: | -------: | ------: |
| src/hatch\_cython/\_\_init\_\_.py | 2 | 0 | 0 | 0 | 100% |
| src/hatch\_cython/config.py | 282 | 19 | 124 | 12 | 92% |
| src/hatch\_cython/devel.py | 5 | 0 | 0 | 0 | 100% |
| src/hatch\_cython/hooks.py | 5 | 1 | 2 | 0 | 86% |
| src/hatch\_cython/plugin.py | 194 | 9 | 102 | 8 | 94% |
| src/hatch\_cython/types.py | 19 | 5 | 2 | 1 | 71% |
| src/hatch\_cython/utils.py | 10 | 0 | 2 | 0 | 100% |
| **TOTAL** | **517** | **34** | **232** | **21** | **92%** |
| Name | Stmts | Miss | Branch | BrPart | Cover |
|----------------------------------------- | -------: | -------: | -------: | -------: | ------: |
| src/hatch\_cython/\_\_init\_\_.py | 2 | 0 | 0 | 0 | 100% |
| src/hatch\_cython/config/\_\_init\_\_.py | 2 | 0 | 0 | 0 | 100% |
| src/hatch\_cython/config/autoimport.py | 9 | 0 | 4 | 0 | 100% |
| src/hatch\_cython/config/config.py | 145 | 16 | 70 | 10 | 87% |
| src/hatch\_cython/config/defaults.py | 6 | 0 | 0 | 0 | 100% |
| src/hatch\_cython/config/files.py | 22 | 1 | 12 | 2 | 91% |
| src/hatch\_cython/config/flags.py | 53 | 1 | 16 | 0 | 99% |
| src/hatch\_cython/config/platform.py | 71 | 2 | 28 | 2 | 96% |
| src/hatch\_cython/constants.py | 11 | 0 | 0 | 0 | 100% |
| src/hatch\_cython/devel.py | 5 | 0 | 0 | 0 | 100% |
| src/hatch\_cython/hooks.py | 5 | 1 | 2 | 0 | 86% |
| src/hatch\_cython/plugin.py | 189 | 9 | 142 | 8 | 95% |
| src/hatch\_cython/temp.py | 12 | 0 | 2 | 0 | 100% |
| src/hatch\_cython/types.py | 19 | 4 | 2 | 1 | 76% |
| src/hatch\_cython/utils.py | 22 | 0 | 8 | 0 | 100% |
| **TOTAL** | **573** | **34** | **286** | **23** | **93%** |
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,12 @@ include_somelib = { pkg = "pyarrow", include="get_include", libraries="get_libra
| extra_link_args | str or `{ platforms = ["*"] \| "*", arg = str }` |
| env | `{ env = "VAR1", arg = "VALUE", platforms = ["*"], arch = ["*"] }`<br/> if flag is one of:<br/> - ARFLAGS<br/> - LDSHARED <br/> - LDFLAGS<br/> - CPPFLAGS <br/> - CFLAGS <br/> - CCSHARED<br/>the current env vars will be merged with the value (provided platform & arch applies), separated by a space. This can be enabled by adding `{ env = "MYVAR" ... , merges = true }` to the definition. |
| includes | list str |
| includes\_{package} | `{ pkg = str, include = str, libraries = str\| None, library_dirs = str \| None , required_call = str \| None }` <br/> where all fields, but `pkg`, are attributes of `pkg` in the type of `callable() -> list[str] \| str` \| `list[str] \| str`. `pkg` is a module, or loadable module object, which may be imported through `import x.y.z`. |
| includes_numpy \| includes_pyarrow | bool<br/> 3rd party named imports. must have the respective opt in `dependencies` |
| retain_intermediate_artifacts | bool = False <br/> whether to keep `.c` \| `.cpp` files |
| parallel | bool = False <br/>if parallel, add openmp headers<br/> important: if using macos, you need the *homebrew* llvm vs _apple's_ llvm in order to pass `-fopenmp` to clang compiler |
| compiler | compiler used at build-time. if `msvc` (Microsoft Visual Studio), `/openmp` is used as argument to compile instead of `-fopenmp`  when `parallel = true` |
| includes\_{package} | `{ pkg = str, include = str, libraries = str\| None, library_dirs = str \| None , required_call = str \| None }` <br/>where all fields, but `pkg`, are attributes of `pkg` in the type of `callable() -> list[str] \| str` \| `list[str] \| str`. `pkg` is a module, or loadable module object, which may be imported through `import x.y.z`. |
| includes_numpy \| includes_pyarrow | bool<br/>3rd party named imports. must have the respective opt in `dependencies` |
| retain_intermediate_artifacts | bool = False <br/>whether to keep `.c` \| `.cpp` files |
| parallel | bool = False <br/>if parallel, add openmp headers<br/>important: if using macos, you need the *homebrew* llvm vs _apple's_ llvm in order to pass `-fopenmp` to clang compiler |
| compiler | compiler used at build-time. if `msvc` (Microsoft Visual Studio), `/openmp` is used as argument to compile instead of `-fopenmp`  when `parallel = true`. `default = false` |
| compile_py | whether to include `.py` files when building cython exts. note, this can be enabled & you can do per file / matched file ignores as below. `default = true` |
| \*\* kwargs | keyword = value pair arguments to pass to the extension module when building |

### Files
Expand All @@ -100,12 +101,15 @@ include_somelib = { pkg = "pyarrow", include="get_include", libraries="get_libra
[build.targets.wheel.hooks.cython.options.files]
exclude = [
# anything matching no_compile is ignored by cython
"*/no_compile/*"
"*/no_compile/*",
# note - anything "*" is escaped to "([^\s]*)" (non whitespace).
# if you need an actual * for python regex, use as below:
# this excludes all pyd or pytempl extensions
"([^.]\\*).(pyd$|pytempl$)"
]
aliases = {"abclib._filewithoutsuffix" = "abclib.importalias"}
```



## License

`hatch-cython` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.
2 changes: 1 addition & 1 deletion example/hatch.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ src = "example_lib"
parallel = true
include_numpy = true
retain_intermediate_artifacts = true

directives = { language_level = 3, boundscheck = false }
compile_args = [
{ arg = "-v" },
Expand All @@ -51,6 +50,7 @@ cythonize_kwargs = { annotate = true, nthreads = 4 }
exclude = [
"*/no_compile/*"
]
aliases = {"example_lib._alias" = "example_lib.aliased"}

[[envs.all.matrix]]
python = ["3.8", "3.9", "3.10", "3.11"]
Expand Down
4 changes: 4 additions & 0 deletions example/src/example_lib/_alias.pyx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# distutils: language=c++

cpdef str some_aliased(str name):
return name
9 changes: 9 additions & 0 deletions example/src/example_lib/mod_a/deep_nest/creates.pyx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cdef class MyClass:
def __cinit__(self):
pass

cpdef str do(self):
return "abc"

cpdef MyClass fast_create():
return MyClass.__new__(MyClass)
4 changes: 4 additions & 0 deletions example/tests/test_aliased.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
def test_aliased():
from example_lib.aliased import some_aliased

assert some_aliased("abc") == "abc"
15 changes: 11 additions & 4 deletions example/tests/test_submodule.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
from example_lib.mod_a.adds import fmul, imul
from example_lib.mod_a.some_defn import ValueDefn


def test_muls():
from example_lib.mod_a.adds import fmul, imul

assert fmul(5.5, 5.5) == 30.25
assert imul(21, 2) == 42


def test_vals():
from example_lib.mod_a.some_defn import ValueDefn

v = ValueDefn(10)
assert v.value == 10
v.set(5)
assert v.value == 5


def test_deep_nesting():
from example_lib.mod_a.deep_nest.creates import fast_create

o = fast_create()
assert o.do() == "abc"
2 changes: 1 addition & 1 deletion src/hatch_cython/__about__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2023-present joshua-auchincloss <joshua.auchincloss@proton.me>
#
# SPDX-License-Identifier: MIT
__version__ = "0.2.3"
__version__ = "0.2.4"
2 changes: 2 additions & 0 deletions src/hatch_cython/config/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from hatch_cython.config.config import Config, parse_from_dict
from hatch_cython.config.platform import PlatformArgs
26 changes: 26 additions & 0 deletions src/hatch_cython/config/autoimport.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from dataclasses import dataclass, field


@dataclass
class Autoimport:
pkg: str

include: str
libraries: str = field(default=None)
library_dirs: str = field(default=None)
required_call: str = field(default=None)


__packages__ = {
a.pkg: a
for a in (
Autoimport("numpy", "get_include"),
Autoimport(
"pyarrow",
include="get_include",
libraries="get_libraries",
library_dirs="get_library_dirs",
required_call="create_library_symlinks",
),
)
}
Loading

0 comments on commit 1fcf9aa

Please sign in to comment.