跳转到主要内容

Python项目的基于日期的版本管理

项目描述

buildsys-dateversion

Python项目的基于日期的版本管理。

PyPI

概述

buildsys-dateversion 是一个Python构建系统扩展,可以在项目构建时自动设置基于当前日期/时间的版本字符串。一旦启用,您的项目在构建源分发或wheel时,版本号将自动生成。

至少,版本字符串将包含当前年份和月份。如果生成的版本与已发布到PyPI的版本冲突,则将添加额外的日期/时间部分到字符串中(例如,日、小时、分钟),直到解决冲突。

buildsys-dateversion 是一个符合 PEP 517 的构建系统,并且可以使用其他PEP 517实现,例如 setuptoolsflit

以下是一个使用 buildsys-dateversion 为项目生成版本字符串的序列示例

发布是在... 版本字符串
2025-03-25 12:00 2025.3
2025-03-31 12:00 2025.3.31
2025-03-31 13:00 2025.3.31.13
2025-03-31 14:00 2025.3.31.14
2025-03-31 14:30 2025.3.31.14.30
2025-03-31 17:30 2025.3.31.17
2025-04-02 12:00 2025.4

用法

先决条件

您的项目必须使用 pyproject.toml

您的项目源必须包含一个 .py 文件,其中包含一行类似如下格式的代码:

__version__ = "0"

(对于 __version__ 的具体值不重要,因为在构建过程中将被覆盖,但推荐使用 "0"。)

安装(setuptools)

您的 pyproject.toml 应该如下所示:

[project]
name = "myproject"
dynamic = ["version"]

[tool.setuptools.dynamic]
version = {attr = "myproject.__version__"}

[build-system]
requires = ["buildsys-dateversion"]
build-backend = "buildsys_dateversion"

(注意,buildsys-dateversion 使用与 pip 兼容的构建系统默认值;这就是为什么在下面的 flit 示例中不需要显式配置 setuptools 作为构建后端或在 requires 中列出它。)

安装(flit)

您的 pyproject.toml 应该如下所示:

[project]
name = "myproject"
dynamic = ["version", "description"]

[build-system]
requires = ["buildsys-dateversion", "flit_core >=3.2,<4"]
build-backend = "buildsys_dateversion"

[tool.buildsys-dateversion]
# buildsys-dateversion only handles generating the version number.
# This tells it which build backend should be used for all the
# other build steps.
build-backend = "flit_core.buildapi"

安装(其他)

buildsys-dateversion 从理论上讲与 PEP 517 的其他构建后端兼容(尽管只有 setuptools 和 flit 被测试过)。主要要求是构建后端必须支持基于项目中的 __version__ 属性的动态 version,就像 setuptools 和 flit 一样。

[project]
name = "myproject"

# The chosen PEP 517 backend must support a dynamic version.
dynamic = ["version"]

[build-system]
# Require buildsys-dateversion + the build backend.
requires = ["buildsys-dateversion", "some_build_backend"]
build-backend = "buildsys_dateversion"

[tool.buildsys-dateversion]
# This should be a module implementing the PEP 517 hooks.
build-backend = "some_build_backend.hooks"

配置参考

以下值可以在 pyproject.toml 中的 tool.buildsys-dateversion 表中设置。

[tool.buildsys-dateversion]
# Should point at a module implementing PEP 517 hooks.
# If omitted, default is "setuptools.build_meta:__legacy__"
build-backend = "some_build_backend.hooks"

# A comment added on patched __version__ lines.
version-marker = "generated by buildsys-dateversion"

# Path to the file containing __version__.
# If omitted, the file is located automatically.
version-path = "src/mymodule/__init__.py"

注意事项

在开始使用此项目之前请注意以下事项

  • 目前,__version__ 属性的设置依赖于临时修补源树中的文件,这有一些影响
    • 构建过程中的源树必须不是只读的。
    • 如果构建过程被中断,定义 __version__ 的文件可能无法恢复到其原始状态。
  • buildsys-dateversion 实现为 PEP 517 构建后端,它包装另一个 PEP 517 构建后端。然而,这种包装并不完美,可能会导致与底层后端有细微的行为差异。

许可

本程序是免费软件:您可以根据自由软件基金会发布的 GNU 通用公共许可证的条款重新分发和/或修改它,许可证版本 3 或(根据您的选择)任何较新版本。

项目详细信息


下载文件

下载适用于您的平台的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。

源分发

buildsys_dateversion-2024.10.tar.gz (46.4 kB 查看哈希值)

上传时间

构建分发

buildsys_dateversion-2024.10-py3-none-any.whl (32.0 kB 查看哈希值)

上传时间 Python 3

由以下支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面