setup.py 1.51 KB
Newer Older
赵小蒙's avatar
赵小蒙 committed
1
from setuptools import setup, find_packages
2
import subprocess
3
4
5
6
7
8
9
10
def parse_requirements(filename):
    with open(filename) as f:
        lines = f.read().splitlines()

    requires = []

    for line in lines:
        if "http" in line:
赵小蒙's avatar
赵小蒙 committed
11
12
            pkg_name_without_url = line.split('@')[0].strip()
            requires.append(pkg_name_without_url)
13
14
15
16
17
        else:
            requires.append(line)

    return requires

18
19
20
21
22
23
24
25
26
27
28
29
30
def get_version():
    command = ["git", "describe", "--tags"]
    try:
        version = subprocess.check_output(command).decode().strip()
        version_parts = version.split("-")
        if len(version_parts) > 1 and version_parts[0].startswith("magic_pdf"):
            return version_parts[1]
        else:
            raise ValueError(f"Invalid version tag {version}. Expected format is magic_pdf-<version>-released.")
    except Exception as e:
        print(e)
        return "0.0.0"

31

赵小蒙's avatar
赵小蒙 committed
32
setup(
赵小蒙's avatar
赵小蒙 committed
33
    name="magic_pdf",  # 项目名
34
35
    # version="0.1.3",  # 版本号
    version=get_version(),  # 自动从tag中获取版本号
36
    packages=find_packages(),  # 包含所有的包
赵小蒙's avatar
赵小蒙 committed
37
    install_requires=parse_requirements('requirements.txt'),  # 项目依赖的第三方库
38
    python_requires=">=3.9",  # 项目依赖的 Python 版本
赵小蒙's avatar
赵小蒙 committed
39
    # entry_points={"console_scripts": ["my_command=my_project.main:run"]}, # 项目提供的可执行命令
40
41
    include_package_data=True,  # 是否包含非代码文件,如数据文件、配置文件等
    zip_safe=False,  # 是否使用 zip 文件格式打包,一般设为 False
赵小蒙's avatar
赵小蒙 committed
42
)