Skip to content

Commit bb27d97

Browse files
committed
Python AdjustAnnotations class improvements
- Improve correspondence with eponymous C++ class. - Make Python class available outside a test context.
1 parent 66e5cec commit bb27d97

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed

plugins/python/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,8 @@ target_link_libraries(pymodule PRIVATE phlex::module Python::Python Python::NumP
2121
target_compile_definitions(pymodule PRIVATE NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION)
2222

2323
install(TARGETS pymodule LIBRARY DESTINATION lib)
24+
25+
install(
26+
DIRECTORY python/phlex
27+
DESTINATION lib/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}/site-packages
28+
)
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
"""Annotation helper for C++ typing variants.
1+
"""Phlex Python Utilities.
22
3-
Python algorithms are generic, like C++ templates, but the Phlex registration
4-
process requires a single unique signature. These helpers generate annotated
5-
functions for registration with the proper C++ types.
3+
Call helpers and type annotation tools for the Phlex framework.
64
"""
75

86
import copy
@@ -63,6 +61,12 @@ def __init__(
6361
self.__name__ = name
6462
self._allow_call = allow_call
6563

64+
# Expose __code__ from the underlying callable if available, to aid
65+
# introspection (e.g. by C++ modulewrap).
66+
self.__code__ = getattr(self.phlex_callable, "__code__", None)
67+
self.__defaults__ = getattr(self.phlex_callable, "__defaults__", None)
68+
self.__kwdefaults__ = getattr(self.phlex_callable, "__kwdefaults__", None)
69+
6670
def __call__(self, *args, **kwargs):
6771
"""Raises an error if called directly.
6872
@@ -77,6 +81,3 @@ def __call__(self, *args, **kwargs):
7781
f"The framework should extract phlex_callable instead."
7882
)
7983
return self.phlex_callable(*args, **kwargs) # type: ignore
80-
81-
82-
Variant = AdjustAnnotations

test/python/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@ set_tests_properties(
194194
list(APPEND ACTIVE_PY_CPHLEX_TESTS py:failure)
195195

196196
set(TEST_PYTHONPATH ${CMAKE_CURRENT_SOURCE_DIR})
197+
# Add the python plugin source directory to PYTHONPATH so tests can use phlex package
198+
set(TEST_PYTHONPATH ${TEST_PYTHONPATH}:${PROJECT_SOURCE_DIR}/plugins/python/python)
199+
197200
# Always add site-packages to PYTHONPATH for tests, as embedded python might
198201
# not find them especially in spack environments where they are in
199202
# non-standard locations

test/python/adder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from typing import Protocol, TypeVar
88

9-
from variant import AdjustAnnotations
9+
from phlex import AdjustAnnotations
1010

1111

1212
class AddableProtocol[T](Protocol):

0 commit comments

Comments
 (0)