python - 在 setup.py 期间创建临时文件
问题描述
我今天玩 python 打包很开心。我想__version__
在我的包中填充关键字,但只有当它是 pip install'd 时。如果我在本地使用它,那么我希望版本来自git describe
. 所以我所拥有的是:
def get_version():
"""
Get the version for the ground station. If the __version__.py exists, it uses the version in there. Otherwise
it uses the git describe version
"""
try:
from . import __version__
return __version__.__version__
except ImportError:
return get_git_tag()
def get_git_tag():
"""Return string of latest (annotated) git tag"""
version = subprocess.check_output(["git", "describe", "--dirty", "--long"]).decode()
version = version.rstrip()
return version
效果很好。但我想确保__version__.py
只存在于已发布的版本中,而不是存在于我的工作存储库中——而且我不想冒险__version__.py
泄露到我的开发工作区中。
所以在这一点上,我正在研究在 setup.py 中创建一个文件的方法,该文件只存在于我的包的分布式版本中。我这样做时有任何提示或警告吗?
解决方案
推荐阅读
- ruby-on-rails - Activeadmin:集合不适用于过滤器
- asp.net - 如何在 EXT.NET 中呈现静态 UI 组件
- reactjs - 如何使用 PptxGenJS 创建具有不同字体样式的图形标题
- sql - 我有 1800 个 teradata 视图,需要从中找到创建视图的表名
- c++ - 内存管理 - 删除一个对象向量,保留指向同一向量的前一个元素的指针
- javascript - 如果在 CRA 中配置了 service worker,则在 PWA 中提供静态 html 文件
- r - 如何计算一个数据框中多组行的平均值
- c# - 如何在 Orchestrator 的帮助下使用 multiturn qna kb 和 LUIS 关闭 Qnamker 对话框
- asp.net - Shopify 请求根据语言的用户更改部分
- scala - 在 Scala Native 中使用 Breeze 库或 Apache Commons