[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/maxstidbits/xtensor-python/master/setup.py [Back]  [Original]

#!/usr/bin/env python
"""
Minimal setup.py for backward compatibility.

This setup.py relies on pyproject.toml for the main configuration
following modern Python packaging standards (PEP 517/518/621).
"""

import os
import re
from pathlib import Path

from setuptools import setup


def get_version():
    """Extract version from C++ header file."""
    config_file = Path("include/xtensor-python/xtensor_python_config.hpp")
    
    if not config_file.exists():
        raise FileNotFoundError(f"Version config file not found: {config_file}")
    
    content = config_file.read_text(encoding="utf-8")
    
    # Extract version components from C++ defines
    major_match = re.search(r"#define\s+XTENSOR_PYTHON_VERSION_MAJOR\s+(\d+)", content)
    minor_match = re.search(r"#define\s+XTENSOR_PYTHON_VERSION_MINOR\s+(\d+)", content)
    patch_match = re.search(r"#define\s+XTENSOR_PYTHON_VERSION_PATCH\s+(\d+)", content)
    
    if not all([major_match, minor_match, patch_match]):
        raise ValueError("Could not extract version from xtensor_python_config.hpp")
    
    major = major_match.group(1)
    minor = minor_match.group(1)
    patch = patch_match.group(1)
    
    return f"{major}.{minor}.{patch}"


def create_version_file():
    """Create a Python version file for dynamic version extraction."""
    version = get_version()
    
    # Ensure src/xtensor_python directory exists
    version_dir = Path("src/xtensor_python")
    version_dir.mkdir(parents=True, exist_ok=True)
    
    # Create __init__.py if it doesn't exist
    init_file = version_dir / "__init__.py"
    if not init_file.exists():
        init_file.write_text('"""xtensor-python: Python bindings for xtensor."""\n\n')
    
    # Create _version.py
    version_file = version_dir / "_version.py"
    version_content = f'''"""Version information for xtensor-python."""

__version__ = "{version}"
'''
    version_file.write_text(version_content, encoding="utf-8")
    
    return version


if __name__ == "__main__":
    # Create version file before setup
    version = create_version_file()
    
    # Call setup with minimal configuration
    # Main configuration is in pyproject.toml
    setup(
        # Minimal setup for compatibility
        # All other configuration is in pyproject.toml
        version=version,
    )

Web Proxy Viewer  |  New URL  |  Original Page