From a70674337203d428442d96ff2f0277c3d98bba62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E5=B0=8F=E8=92=99?= Date: Tue, 5 Mar 2024 15:05:51 +0800 Subject: [PATCH] =?UTF-8?q?setup=E4=BB=8Etag=E4=B8=AD=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E7=89=88=E6=9C=AC=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/python-package.yml | 10 +++++++++- setup.py | 18 ++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 5851bc51..4da02771 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -20,21 +20,29 @@ jobs: python-version: ["3.10"] steps: - - uses: actions/checkout@v4 + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} + - name: Install dependencies run: | python -m pip install --upgrade pip if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Install wheel run: | python -m pip install wheel + - name: Build wheel run: | python setup.py bdist_wheel + - name: Upload artifact uses: actions/upload-artifact@v4 with: diff --git a/setup.py b/setup.py index ae607fb2..b5cce99f 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,5 @@ from setuptools import setup, find_packages - +import subprocess def parse_requirements(filename): with open(filename) as f: lines = f.read().splitlines() @@ -15,12 +15,26 @@ def parse_requirements(filename): return requires +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--released.") + except Exception as e: + print(e) + return "0.0.0" + requires = parse_requirements('requirements.txt') setup( name="magic_pdf", # 项目名 - version="0.1.3", # 版本号 + # version="0.1.3", # 版本号 + version=get_version(), # 自动从tag中获取版本号 packages=find_packages(), # 包含所有的包 install_requires=requires, # 项目依赖的第三方库 python_requires=">=3.9", # 项目依赖的 Python 版本