import os
import setuptools
from pathlib import Path

readme = Path("README.md").read_bytes().decode()

classifiers = [
    "Development Status :: 5 - Production/Stable",
    "Environment :: Console",
    "Intended Audience :: Developers",
    "Programming Language :: Python :: 3",
    "Topic :: Utilities",
]

VERSION = "1.27.2.2"

# We build with, and run with, a particular PyMuPDF version usually, but not
# always, the same as our version.
#
pymupdf_version = VERSION

# We build with, and run with, a particular pymupdf_layout version usually, but
# not always, the same as our version.
#
pymupdf_layout_version = VERSION

VERSION_TUPLE = tuple(int(x) for x in VERSION.split("."))

PYMUPDF_SETUP_VERSION = os.environ.get('PYMUPDF_SETUP_VERSION')
if PYMUPDF_SETUP_VERSION:
    # Allow testing with non-matching pymupdf/layout versions.
    requires = ["tabulate"]
else:
    requires = [
            f"pymupdf=={pymupdf_version}",
            f"pymupdf_layout=={pymupdf_layout_version}",
            "tabulate",
            ]

text = f"# Generated file - do not edit.\n{VERSION=}\n{VERSION_TUPLE=}\n"
Path("pymupdf4llm/versions_file.py").write_text(text)

setuptools.setup(
    name="pymupdf4llm",
    version=VERSION,
    author="Artifex",
    author_email="support@artifex.com",
    description="PyMuPDF Utilities for LLM/RAG",
    packages=setuptools.find_packages(),
    long_description=readme,
    long_description_content_type="text/markdown",
    install_requires=requires,
    python_requires=">=3.10",
    license="Dual Licensed - GNU AFFERO GPL 3.0 or Artifex Commercial License",
    url="https://github.com/pymupdf/pymupdf4llm",
    classifiers=classifiers,
    package_data={
        "pymupdf4llm": ["helpers/*.py", "llama/*.py", "ocr/*.py"],
    },
    project_urls={
        "Documentation": "https://pymupdf.readthedocs.io/",
        "Source": "https://github.com/pymupdf/pymupdf4llm/tree/main/pymupdf4llm",
        "Tracker": "https://github.com/pymupdf/pymupdf4llm/issues",
        "Changelog": "https://github.com/pymupdf/pymupdf4llm/blob/main/CHANGES.md",
        "License": "https://github.com/pymupdf/pymupdf4llm/blob/main/LICENSE",
    },
)
