Skip to content

Commit

Permalink
merge: pr #14 from joshua-auchincloss/v0.2.3
Browse files Browse the repository at this point in the history
v0.2.3
  • Loading branch information
joshua-auchincloss authored Aug 28, 2023
2 parents ebf084e + 527b879 commit 51427d4
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 16 deletions.
6 changes: 3 additions & 3 deletions COVERAGE.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
| Name | Stmts | Miss | Branch | BrPart | Cover |
|---------------------------------- | -------: | -------: | -------: | -------: | ------: |
| src/hatch\_cython/\_\_init\_\_.py | 2 | 0 | 0 | 0 | 100% |
| src/hatch\_cython/config.py | 276 | 19 | 120 | 12 | 92% |
| 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 | 191 | 9 | 100 | 8 | 94% |
| 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** | **508** | **34** | **226** | **21** | **92%** |
| **TOTAL** | **517** | **34** | **232** | **21** | **92%** |
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,25 @@ 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 in the type of `callable() -> list[str] \| str` \| `list[str] \| 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` |
| \*\* kwargs | keyword = value pair arguments to pass to the extension module when building |

### Files

```toml
[build.targets.wheel.hooks.cython.options.files]
exclude = [
# anything matching no_compile is ignored by cython
"*/no_compile/*"
]
```



## License

`hatch-cython` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.
5 changes: 5 additions & 0 deletions example/hatch.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ env = [

cythonize_kwargs = { annotate = true, nthreads = 4 }

[build.targets.wheel.hooks.custom.options.files]
exclude = [
"*/no_compile/*"
]

[[envs.all.matrix]]
python = ["3.8", "3.9", "3.10", "3.11"]

Expand Down
2 changes: 2 additions & 0 deletions example/src/example_lib/no_compile/abc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def test_nocompile():
return 41
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.2"
__version__ = "0.2.3"
10 changes: 9 additions & 1 deletion src/hatch_cython/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
}
LTPY311 = "python_version < '3.11'"
MUST_UNIQUE = ["-O", "-arch", "-march"]

POSIX_CORE: list_t[CorePlatforms] = ["darwin", "linux"]


Expand All @@ -41,6 +40,7 @@ def aarch():
__known__ = (
"src",
"env",
"files",
"includes",
"libraries",
"library_dirs",
Expand Down Expand Up @@ -215,6 +215,11 @@ def get_from_custom(self, attr):
"""


@dataclass
class FileArgs:
exclude: ListStr = field(default_factory=list)


def get_default_link():
return [
PlatformArgs(arg="-L/opt/homebrew/lib", platforms=POSIX_CORE, depends_path=True),
Expand Down Expand Up @@ -271,6 +276,8 @@ def parse_from_dict(cls: BuildHookInterface):
kwargs = {}
for kw, val in given.items():
if kw in __known__:
if kw == "files":
val = FileArgs(**val) # noqa: PLW2901
kwargs[kw] = val
passed.pop(kw)
continue
Expand Down Expand Up @@ -341,6 +348,7 @@ def parse_from_dict(cls: BuildHookInterface):
@dataclass
class Config:
src: Optional[str] = field(default=None) # noqa: UP007
files: FileArgs = field(default_factory=FileArgs)
includes: ListStr = field(default_factory=list)
libraries: ListStr = field(default_factory=list)
library_dirs: ListStr = field(default_factory=list)
Expand Down
15 changes: 14 additions & 1 deletion src/hatch_cython/plugin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import re
import subprocess
import sys
from contextlib import contextmanager
Expand Down Expand Up @@ -150,7 +151,19 @@ def included_files(self):
if self._included is None:
self._included = []
for patt in self.precompiled_globs:
self._included.extend(glob(patt))
globbed = glob(patt)
matched = list(
filter(
lambda s: not any(
re.match(
self.normalize_glob(e).replace("*", r"([^\s]*)"), self.normalize_glob(s), re.IGNORECASE
)
for e in self.options.files.exclude
),
globbed,
)
)
self._included.extend(matched)
return self._included

@property
Expand Down
23 changes: 14 additions & 9 deletions tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,20 @@ def test_build_hook(new_proj):
]
)

assert sorted([sorted(ls) for ls in hook.grouped_included_files]) == sorted([sorted(ls) for ls in [
["./src/example_lib/normal.py"],
["./src/example_lib/__init__.py"],
["./src/example_lib/__about__.py"],
["./src/example_lib/mod_a/__init__.py"],
["./src/example_lib/mod_a/some_defn.py", "./src/example_lib/mod_a/some_defn.py"],
["./src/example_lib/test.pyx"],
["./src/example_lib/mod_a/adds.pyx"],
]])
assert sorted([sorted(ls) for ls in hook.grouped_included_files]) == sorted(
[
sorted(ls)
for ls in [
["./src/example_lib/normal.py"],
["./src/example_lib/__init__.py"],
["./src/example_lib/__about__.py"],
["./src/example_lib/mod_a/__init__.py"],
["./src/example_lib/mod_a/some_defn.py", "./src/example_lib/mod_a/some_defn.py"],
["./src/example_lib/test.pyx"],
["./src/example_lib/mod_a/adds.pyx"],
]
]
)

rf = sorted(
[
Expand Down

0 comments on commit 51427d4

Please sign in to comment.