Custom build extension to build tiktoken library first.
| 29 | |
| 30 | |
| 31 | class CustomBuildExt(build_ext): |
| 32 | """Custom build extension to build tiktoken library first.""" |
| 33 | |
| 34 | def build_extensions(self): |
| 35 | # Build the tiktoken library first |
| 36 | tiktoken_lib_path = Path("src/tiktoken/libtiktoken.a") |
| 37 | |
| 38 | print("Building tiktoken library...") |
| 39 | try: |
| 40 | result = subprocess.run( |
| 41 | ["make", "-C", "src/tiktoken"], |
| 42 | check=True, |
| 43 | capture_output=True, |
| 44 | text=True |
| 45 | ) |
| 46 | print("✓ tiktoken library built successfully") |
| 47 | except subprocess.CalledProcessError as e: |
| 48 | print(f"Failed to build tiktoken library: {e}") |
| 49 | print(f"stdout: {e.stdout}") |
| 50 | print(f"stderr: {e.stderr}") |
| 51 | sys.exit(1) |
| 52 | except FileNotFoundError: |
| 53 | print("make command not found. Please install build tools.") |
| 54 | sys.exit(1) |
| 55 | |
| 56 | # Check if library was created |
| 57 | if not tiktoken_lib_path.exists(): |
| 58 | print(f"tiktoken library not found at {tiktoken_lib_path}") |
| 59 | sys.exit(1) |
| 60 | |
| 61 | # Then build the Python extension |
| 62 | super().build_extensions() |
| 63 | |
| 64 | |
| 65 | # Read the version from __init__.py |
nothing calls this directly
no outgoing calls
no test coverage detected