diff --git a/CHANGELOG.md b/CHANGELOG.md index ab377b2b69c..60728d8c8dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added * Added C API functions for `dpnp.tensor.usm_ndarray` setters and getters to avoid ABI breakage if `dpnp.tensor.usm_ndarray` is modified [gh-2866](https://github.com/IntelPython/dpnp/pull/2866) +* Added `--includes` and `--include-dir` options to the `dpnp` CLI [#2916](https://github.com/IntelPython/dpnp/pull/2916) + ### Changed * Changed `dpnp.meshgrid` and `dpnp.tensor.meshgrid` to return a tuple instead of a list, aligning with NumPy 2.5+ behavior and 2025.12 version of the Python array API standard [#2854](https://github.com/IntelPython/dpnp/pull/2854) diff --git a/dpnp/__main__.py b/dpnp/__main__.py index 1c9c652109e..349ffcd472f 100644 --- a/dpnp/__main__.py +++ b/dpnp/__main__.py @@ -39,10 +39,19 @@ def _dpnp_dir() -> str: return abs_dpnp_dir +def get_include_dir() -> str: + """Returns path to dpnp include directory containing dpnp4pybind11.hpp""" + return os.path.join(_dpnp_dir(), "backend", "include") + + +def print_include_flags() -> None: + """Prints include flags for dpnp headers""" + print("-I " + get_include_dir()) + + def get_tensor_include_dir() -> str: """Prints path to dpnp libtensor include directory""" - dpnp_dir = _dpnp_dir() - libtensor_dir = os.path.join(dpnp_dir, "tensor", "libtensor", "include") + libtensor_dir = os.path.join(_dpnp_dir(), "tensor", "libtensor", "include") return libtensor_dir @@ -55,6 +64,16 @@ def print_tensor_include_flags() -> None: def main() -> None: """Main entry-point.""" parser = argparse.ArgumentParser() + parser.add_argument( + "--includes", + action="store_true", + help="Include flags for dpnp headers.", + ) + parser.add_argument( + "--include-dir", + action="store_true", + help="Path to dpnp include directory.", + ) parser.add_argument( "--tensor-includes", action="store_true", @@ -68,6 +87,10 @@ def main() -> None: args = parser.parse_args() if not sys.argv[1:]: parser.print_help() + if args.includes: + print_include_flags() + if args.include_dir: + print(get_include_dir()) if args.tensor_includes: print_tensor_include_flags() if args.tensor_include_dir: diff --git a/dpnp/tests/test_cli_options.py b/dpnp/tests/test_cli_options.py index 0caca95f397..1d353e9fddf 100644 --- a/dpnp/tests/test_cli_options.py +++ b/dpnp/tests/test_cli_options.py @@ -2,6 +2,24 @@ import sys +def test_includes(): + res = subprocess.run( + [sys.executable, "-m", "dpnp", "--includes"], + capture_output=True, + ) + assert res.returncode == 0 + assert res.stdout + flags = res.stdout.decode("utf-8") + res = subprocess.run( + [sys.executable, "-m", "dpnp", "--include-dir"], + capture_output=True, + ) + assert res.returncode == 0 + assert res.stdout + include_dir = res.stdout.decode("utf-8") + assert flags == "-I " + include_dir + + def test_tensor_includes(): res = subprocess.run( [sys.executable, "-m", "dpnp", "--tensor-includes"],