import setuptools
import re
import os
def get_version():
    # 找到 __init__.py 的路径
    init_path = os.path.join(
        os.path.dirname(__file__), 
        "csst_ifs_sim", 
        "__init__.py"
    )
    # 读取文件内容，使用正则找出版本号
    with open(init_path, "r", encoding="utf-8") as f:
        content = f.read()
        version_match = re.search(r'^__version__ ?= ?["\']([^"\']*)["\']', content, re.M)
        if version_match:
            return version_match.group(1)
        raise RuntimeError("无法在 __init__.py 中找到 __version__ 定义")



# 读取README.md作为长描述
with open("README.md", "r") as f:
    long_description = f.read()

# 读取依赖列表requirements.txt
# 忽略#开头或者版本号不明确指定的条目
with open("requirements.txt", "r") as f:
    requirements = [
        req.strip()
        for req in f.readlines()
        if not req.startswith("#") and req.__contains__("==")
    ]
    
setuptools.setup(
    
    name='csst_ifs_sim',  # 包名
    version=get_version(),  # 版本号
    author="Zhaojun Yan",  # 作者
    author_email="zhaojunyan@shao.ac.cn",  # 邮箱
    description="The CSST IFS simulation - prototype",  # 短描述
    long_description=long_description,  # 长描述
    long_description_content_type="text/markdown",  # 长描述类型
    url="https://csst-tb.bao.ac.cn/code/csst-sims/csst_ifs_sim/",  # 主页
    packages=setuptools.find_packages(where="."),  # 用setuptools工具自动发现带有__init__.py的包
    license="MIT",  # 证书类型
    classifiers=[  # 程序分类, 参考 https://pypi.org/classifiers/
        # How mature is this project?
        #   3 - Alpha
        #   4 - Beta
        #   5 - Production/Stable
        "Development Status :: 3 - Alpha",
        "Intended Audience :: Science/Research",
        "License :: OSI Approved :: MIT License",
        "Operating System :: OS Independent",
        "Programming Language :: Python :: 3",
        "Topic :: Scientific/Engineering :: Physics",
        "Topic :: Scientific/Engineering :: Astronomy",
    ],
    
    include_package_data=True,  # 设置包含随包数据
    package_data={"": ["LICENSE", "README.md"],
                  "csst_ifs_sim": ["ifs_so/*", "ifs_data/*"]},

    # 请注意检查，防止临时文件或其他不必要的文件被提交到仓库，否则会一同安装
    python_requires=">=3.8",  # Python版本要求
    install_requires=requirements,

)
