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

    requires = []

    for line in lines:
        if "http" in line:
            pkg_name_with_version = line.split('/')[-1].split('-')[0]
            requires.append(pkg_name_with_version)
        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
32
33

requires = parse_requirements('requirements.txt')

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