运行时提取PythonWheel的版本

2024-06-25 06:46:08 发布

您现在位置:Python中文网/ 问答频道 /正文

我目前正在从事一个项目,在该项目中,我们使用AzureDevOps管道将轮子文件发布到azure工件中。 在管道中,我将设置一个版本标记,该标记将写入一个名为“deploymentversion”的文件中

此文件的内容将从my setup.py读取,并在构建控制盘文件时设置版本

在我的机器上安装了轮子之后,我想有一个像这样的help()函数

import myWhlPackage
myWhlPackage.help()

代码中的这个help()-函数应该只打印出一些常量文本和当前安装的控制盘版本。因此,如果我做另一个版本,这个版本标签也应该根据轮子的安装版本增加

我尝试将deploymentversion文件与whl文件一起提供,但安装后无法读取该文件

有什么建议哪种工作流程最好?没有发现任何类似的用例

AzureDevOps的部署将被修复

提前谢谢


Tags: 文件项目函数标记版本内容管道my
1条回答
网友
1楼 · 发布于 2024-06-25 06:46:08

您可以尝试在运行时使用getversion来提取PythonWheel的版本。有关详细信息,请单击this document

根据该文件:

At runtime (when you need that version number), packages and modules can be

  • already imported or not
  • built and pip-installed (in debug mode or not), or simply added to the PYTHON PATH (sys.path)
  • non-built and added to the PYTHON PATH (sys.path)

This variety of settings makes it very difficult for existing solutions to tackle all aspects of this problem. pkg_resources is probably the best way to get it as of today (like this), but does not work for example when a package is an unzipped wheel added to the PYTHON PATH. It also does not support built-in modules.

相关问题 更多 >