|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | +# All rights reserved. |
| 4 | +# |
| 5 | +# This source code is licensed under the BSD-style license found in the |
| 6 | +# LICENSE file in the root directory of this source tree. |
| 7 | + |
| 8 | +""" |
| 9 | +Cross-platform wheel smoke-test entry point. |
| 10 | +
|
| 11 | +The PyTorch Tokenizers wheel should already be installed in the active |
| 12 | +environment when this script runs. We execute the Python unit test suite |
| 13 | +to ensure the wheel exposes the expected bindings and core functionality. |
| 14 | +""" |
| 15 | + |
| 16 | +from __future__ import annotations |
| 17 | + |
| 18 | +import os |
| 19 | +import subprocess |
| 20 | +import sys |
| 21 | +from pathlib import Path |
| 22 | +from typing import Sequence |
| 23 | + |
| 24 | + |
| 25 | +def run_pytest(test_files: Sequence[Path], cwd: Path) -> int: |
| 26 | + """Execute pytest on the provided files and propagate the return code.""" |
| 27 | + env = os.environ.copy() |
| 28 | + pythonpath_entries = [str(cwd)] |
| 29 | + if existing_path := env.get("PYTHONPATH"): |
| 30 | + pythonpath_entries.append(existing_path) |
| 31 | + env["PYTHONPATH"] = os.pathsep.join(pythonpath_entries) |
| 32 | + |
| 33 | + cmd = [ |
| 34 | + sys.executable, |
| 35 | + "-m", |
| 36 | + "pytest", |
| 37 | + "-vv", |
| 38 | + *(str(test) for test in test_files), |
| 39 | + ] |
| 40 | + |
| 41 | + print(f"Running pytest with: {' '.join(cmd)}") |
| 42 | + result = subprocess.run(cmd, cwd=str(cwd), env=env, check=False) |
| 43 | + return result.returncode |
| 44 | + |
| 45 | + |
| 46 | +def main() -> int: |
| 47 | + repo_root = Path(__file__).resolve().parents[3] |
| 48 | + test_dir = repo_root / "test" |
| 49 | + |
| 50 | + if not test_dir.exists(): |
| 51 | + print(f"ERROR: Test directory not found: {test_dir}", file=sys.stderr) |
| 52 | + return 1 |
| 53 | + |
| 54 | + return run_pytest([test_dir], repo_root) |
| 55 | + |
| 56 | + |
| 57 | +if __name__ == "__main__": |
| 58 | + sys.exit(main()) |
0 commit comments