diff --git a/bindings/sysman/python/.flake8 b/bindings/sysman/python/.flake8 index a27b0070..44a0980d 100644 --- a/bindings/sysman/python/.flake8 +++ b/bindings/sysman/python/.flake8 @@ -11,4 +11,4 @@ extend-ignore = E266 per-file-ignores = # Allow module-level imports not at top of file in examples - source/examples/pyzes_example.py:E402 + source/pyzes/examples/pyzes_example.py:E402 diff --git a/bindings/sysman/python/README.md b/bindings/sysman/python/README.md index 8bafe655..6b5c36ba 100644 --- a/bindings/sysman/python/README.md +++ b/bindings/sysman/python/README.md @@ -46,6 +46,15 @@ USAGE ``` +EXAMPLES +-------- +Example scripts are installed with the package under `pyzes.examples`: +```bash +python3 -m pyzes.examples.pyzes_example +python3 -m pyzes.examples.pyzes_black_box_test -h +``` +See the [examples README](https://github.com/oneapi-src/level-zero/blob/master/bindings/sysman/python/source/pyzes/examples/README.md) for details. + ## C Structure and its python module class ## struct zes_process_state_t { @@ -198,6 +207,12 @@ SUPPORTED APIs RELEASE NOTES ------------- +Version 0.1.3 +- **Packaging:** + - `pyzes` is now a package (`pyzes/__init__.py`) instead of a single `pyzes.py` module. `import pyzes` and `from pyzes import *` are unchanged. + - Example scripts moved from the top-level `examples` package to `pyzes.examples`, so installing pyzes no longer puts an `examples` package in `site-packages` that conflicts with other projects. + - Run the examples with `python3 -m pyzes.examples.pyzes_example` and `python3 -m pyzes.examples.pyzes_black_box_test` (previously `python3 -m examples.`). + Version 0.1.2 - **New API Functions:** - `zesDevicePciGetProperties`, `zesDevicePciGetStats`, `zesDevicePciGetState` diff --git a/bindings/sysman/python/pyproject.toml b/bindings/sysman/python/pyproject.toml index d48f43b0..f6e5e266 100644 --- a/bindings/sysman/python/pyproject.toml +++ b/bindings/sysman/python/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "pyzes" -version = "0.1.2" +version = "0.1.3" description = "Python bindings for Intel Level-Zero Driver Library (Sysman API)" readme = "README.md" requires-python = ">=3.10" @@ -33,11 +33,10 @@ Issues = "https://github.com/oneapi-src/level-zero/issues" [tool.setuptools] package-dir = {"" = "source"} -py-modules = ["pyzes"] -packages = ["examples"] +packages = ["pyzes", "pyzes.examples"] [tool.coverage.run] omit = [ - "source/examples/*", + "source/pyzes/examples/*", "test/*", ] diff --git a/bindings/sysman/python/source/pyzes.py b/bindings/sysman/python/source/pyzes/__init__.py similarity index 100% rename from bindings/sysman/python/source/pyzes.py rename to bindings/sysman/python/source/pyzes/__init__.py diff --git a/bindings/sysman/python/source/examples/README.md b/bindings/sysman/python/source/pyzes/examples/README.md similarity index 59% rename from bindings/sysman/python/source/examples/README.md rename to bindings/sysman/python/source/pyzes/examples/README.md index 9f900ec7..56177a4e 100644 --- a/bindings/sysman/python/source/examples/README.md +++ b/bindings/sysman/python/source/pyzes/examples/README.md @@ -2,7 +2,7 @@ This directory contains example scripts demonstrating how to use the pyzes module. -**IMPORTANT:** The usage instructions below apply to pyzes installed via pip. If you've cloned this repository locally, you should run the examples directly from the `test/` directory in the repository root instead. +The examples are installed as the `pyzes.examples` subpackage, so they don't add a top-level `examples` package to `site-packages` that could conflict with other projects. ## Using Examples After Installation @@ -15,8 +15,8 @@ pip install pyzes You can run examples directly: ```bash -python3 -m examples.pyzes_example -python3 -m examples.pyzes_black_box_test -h +python3 -m pyzes.examples.pyzes_example +python3 -m pyzes.examples.pyzes_black_box_test -h ``` --- @@ -26,12 +26,12 @@ python3 -m examples.pyzes_black_box_test -h If you cloned the level-zero repository locally, run the examples directly from the repository: ```bash -cd bindings/sysman/python/source/examples +cd bindings/sysman/python/source/pyzes/examples python3 pyzes_example.py python3 pyzes_black_box_test.py -h ``` -The examples in this `source/examples/` directory are packaged for pip distribution only. +The scripts add `bindings/sysman/python/source` to `sys.path`, so they import the local `pyzes` without installing it. --- diff --git a/bindings/sysman/python/source/examples/__init__.py b/bindings/sysman/python/source/pyzes/examples/__init__.py similarity index 100% rename from bindings/sysman/python/source/examples/__init__.py rename to bindings/sysman/python/source/pyzes/examples/__init__.py diff --git a/bindings/sysman/python/source/examples/pyzes_black_box_test.py b/bindings/sysman/python/source/pyzes/examples/pyzes_black_box_test.py similarity index 99% rename from bindings/sysman/python/source/examples/pyzes_black_box_test.py rename to bindings/sysman/python/source/pyzes/examples/pyzes_black_box_test.py index 135191c3..471d182d 100755 --- a/bindings/sysman/python/source/examples/pyzes_black_box_test.py +++ b/bindings/sysman/python/source/pyzes/examples/pyzes_black_box_test.py @@ -7,7 +7,7 @@ ## ## -# Python Black Box Test for pyzes.py - Level Zero Sysman Python Bindings +# Python Black Box Test for the pyzes package - Level Zero Sysman Python Bindings ## import argparse @@ -16,9 +16,9 @@ import time from ctypes import * -# Add the source directory to Python path so we can import pyzes +# Add the source directory (two levels up: source/pyzes/examples) to Python path so we can import pyzes script_dir = os.path.dirname(os.path.abspath(__file__)) -source_dir = os.path.join(script_dir, "..") +source_dir = os.path.join(script_dir, "..", "..") source_dir = os.path.abspath(source_dir) if source_dir not in sys.path: sys.path.insert(0, source_dir) @@ -29,7 +29,7 @@ except ImportError as e: print("Error: Could not import pyzes module") print(f"Import error: {e}") - print(f"Make sure pyzes.py is in the source directory: {source_dir}") + print(f"Make sure the pyzes package is in the source directory: {source_dir}") print(f"Current working directory: {os.getcwd()}") print(f"Script directory: {script_dir}") print(f"Source directory: {source_dir}") diff --git a/bindings/sysman/python/source/examples/pyzes_example.py b/bindings/sysman/python/source/pyzes/examples/pyzes_example.py similarity index 99% rename from bindings/sysman/python/source/examples/pyzes_example.py rename to bindings/sysman/python/source/pyzes/examples/pyzes_example.py index 84f6cffa..23df6394 100755 --- a/bindings/sysman/python/source/examples/pyzes_example.py +++ b/bindings/sysman/python/source/pyzes/examples/pyzes_example.py @@ -22,9 +22,9 @@ import sys from ctypes import * -# Add the source directory to Python path so we can import pyzes +# Add the source directory (two levels up: source/pyzes/examples) to Python path so we can import pyzes script_dir = os.path.dirname(os.path.abspath(__file__)) -source_dir = os.path.join(script_dir, "..") +source_dir = os.path.join(script_dir, "..", "..") source_dir = os.path.abspath(source_dir) if source_dir not in sys.path: sys.path.insert(0, source_dir) diff --git a/bindings/sysman/python/test/validate_structures.py b/bindings/sysman/python/test/validate_structures.py index 0341c7a7..59537791 100644 --- a/bindings/sysman/python/test/validate_structures.py +++ b/bindings/sysman/python/test/validate_structures.py @@ -7,7 +7,7 @@ ## """ -Validates that Python ctypes structures in pyzes.py match the C structures +Validates that Python ctypes structures in pyzes/__init__.py match the C structures defined in the Level-Zero headers (include/zes_api.h, include/ze_api.h). """ @@ -86,7 +86,7 @@ def parse_python_structure( pyzes_content: str, struct_name: str ) -> Optional[List[Tuple[str, str]]]: """ - Parse a Python ctypes structure definition from pyzes.py. + Parse a Python ctypes structure definition from pyzes/__init__.py. Returns list of (field_name, field_type) tuples. """ # Find the class definition @@ -220,7 +220,7 @@ def compare_structures( def get_all_structures_from_pyzes(pyzes_content: str) -> List[str]: """ - Extract all structure names that inherit from _PrintableStructure in pyzes.py. + Extract all structure names that inherit from _PrintableStructure in pyzes/__init__.py. Returns list of structure names. """ structures = [] @@ -241,7 +241,7 @@ def main(): # Paths zes_header = repo_root / "include" / "zes_api.h" ze_header = repo_root / "include" / "ze_api.h" - pyzes_file = repo_root / "bindings" / "sysman" / "python" / "source" / "pyzes.py" + pyzes_file = script_dir.parent / "source" / "pyzes" / "__init__.py" # Check files exist for file_path in [zes_header, ze_header, pyzes_file]: @@ -254,14 +254,14 @@ def main(): ze_content = ze_header.read_text() pyzes_content = pyzes_file.read_text() - # Dynamically discover all structures from pyzes.py + # Dynamically discover all structures from pyzes/__init__.py structures_to_check = get_all_structures_from_pyzes(pyzes_content) if not structures_to_check: - print("❌ FAIL: No structures found in pyzes.py") + print("❌ FAIL: No structures found in pyzes/__init__.py") return 1 - print(f"Found {len(structures_to_check)} structures in pyzes.py") + print(f"Found {len(structures_to_check)} structures in pyzes/__init__.py") all_errors = {} structures_checked = 0 @@ -281,8 +281,8 @@ def main(): # Parse from Python py_fields = parse_python_structure(pyzes_content, struct_name) if py_fields is None: - print(f"❌ FAIL: Structure '{struct_name}' not found in pyzes.py") - all_errors[struct_name] = ["Structure not found in pyzes.py"] + print(f"❌ FAIL: Structure '{struct_name}' not found in pyzes/__init__.py") + all_errors[struct_name] = ["Structure not found in pyzes/__init__.py"] continue # Compare @@ -297,7 +297,7 @@ def main(): print("=" * 70) print("Structure Validation Summary") print("=" * 70) - print(f"Total structures found in pyzes.py: {len(structures_to_check)}") + print(f"Total structures found in pyzes/__init__.py: {len(structures_to_check)}") print(f"Structures validated successfully: {structures_checked}") if structures_not_in_headers: