-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merge: pr #16 from joshua-auchincloss/v0.2.5
feat: add macro support
- Loading branch information
Showing
22 changed files
with
274 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# SPDX-FileCopyrightText: 2023-present joshua-auchincloss <[email protected]> | ||
# | ||
# SPDX-License-Identifier: MIT | ||
__version__ = "0.2.4" | ||
__version__ = "0.2.5" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from hatch_cython.config.autoimport import Autoimport, __packages__ | ||
from hatch_cython.constants import INCLUDE | ||
|
||
|
||
def parse_includes(kw: str, val: str): | ||
alias = kw.replace(INCLUDE, "") | ||
import_p = __packages__.get(alias) | ||
if import_p is None: | ||
if isinstance(val, str): | ||
import_p = Autoimport(pkg=alias, include=val) | ||
elif isinstance(val, dict): | ||
if "pkg" not in val: | ||
val["pkg"] = alias | ||
import_p = Autoimport(**val) | ||
else: | ||
msg = " ".join( | ||
( | ||
"%s (%s) is invalid, either provide a known package or", | ||
"a path in the format of module.get_xxx where get_xxx is", | ||
"the directory to be included", | ||
) | ||
).format(val, type(val)) | ||
raise ValueError(msg) | ||
return import_p |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from hatch_cython.types import ListT, TupleT, UnionT | ||
|
||
DefineMacros = ListT[TupleT[str, UnionT[str, None]]] | ||
|
||
|
||
def parse_macros(define: ListT[ListT[str]]) -> DefineMacros: | ||
"""Parses define_macros from list[list[str, ...]] -> list[tuple[str, str|None]] | ||
Args: | ||
define (ListT[ListT[str]]): list of listed strings of len 1 or 2. raises error if len > 2 | ||
Raises: | ||
ValueError: length > 2 or types are not valid | ||
Returns: | ||
DefineMacros: list[tuple[str,str|None]] | ||
""" | ||
for i, inst in enumerate(define): | ||
size = len(inst) | ||
if not (isinstance(inst, list) and size in (1, 2) and all(isinstance(v, str) or v is None for v in inst)): | ||
msg = "".join( | ||
f"define_macros[{i}]: macros must be defined as [name, <value>], " | ||
"where None value denotes #define FOO" | ||
) | ||
raise ValueError(msg, inst) | ||
inst: list | ||
if size == 1: | ||
define[i] = (inst[0], None) | ||
else: | ||
define[i] = (inst[0], inst[1]) | ||
return define |
Oops, something went wrong.