|
|
@@ -2,6 +2,7 @@ import os
|
|
|
import subprocess
|
|
|
|
|
|
from setuptools import setup, find_packages
|
|
|
+from magic_pdf.libs.version import __version__
|
|
|
|
|
|
|
|
|
def parse_requirements(filename):
|
|
|
@@ -20,32 +21,10 @@ 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-<version>-released.")
|
|
|
- except Exception as e:
|
|
|
- print(e)
|
|
|
- return "0.0.0"
|
|
|
-
|
|
|
-
|
|
|
-def write_version_to_commons(version):
|
|
|
- commons_path = os.path.join(os.path.dirname(__file__), 'magic_pdf', 'libs', 'version.py')
|
|
|
- with open(commons_path, 'w') as f:
|
|
|
- f.write(f'__version__ = "{version}"\n')
|
|
|
-
|
|
|
-
|
|
|
if __name__ == '__main__':
|
|
|
- version_name = get_version()
|
|
|
- write_version_to_commons(version_name)
|
|
|
setup(
|
|
|
name="magic_pdf", # 项目名
|
|
|
- version=version_name, # 自动从tag中获取版本号
|
|
|
+ version=__version__, # 自动从tag中获取版本号
|
|
|
packages=find_packages(), # 包含所有的包
|
|
|
install_requires=parse_requirements('requirements.txt'), # 项目依赖的第三方库
|
|
|
python_requires=">=3.9", # 项目依赖的 Python 版本
|