跳转到主要内容

为Python包提供可靠的基于git的版本控制

项目描述

katversion包为Python包提供符合其(git)源存储库要求的适当版本控制。生成的版本字符串被嵌入到已安装包的__init__.py文件中,以确保导入时的可追溯性(不依赖于pkg_resources的看法!)。

版本字符串格式

katversion 为您的SCM软件包生成符合 PEP 440 规范的版本字符串。它仅支持git仓库。

我们版本字符串的格式是

- for RELEASE builds:
    <major>.<minor>
    e.g.
    0.1
    2.4

- for DEVELOPMENT builds:
    <major>.<minor>.dev<num_commits>+<branch_name>.g<short_git_sha>[.dirty]
    e.g.
    0.2.dev34+new.shiny.feature.gfa973da
    2.5.dev7+master.gb91ffa6.dirty

- for UNKNOWN builds:
    0.0+unknown.[<scm_type>.]<timestamp>
    e.g.
    0.0+unknown.git.201402031023
    0.0+unknown.201602081715

where <major>.<minor> is derived from the latest version tag and
<num_commits> is the total number of commits on the development branch.

The <major>.<minor> substring for development builds will be that of the
NEXT (minor) release, in order to allow proper Python version ordering.

To add a version tag use the `git tag` command, e.g.

    $ git tag -a 1.2 -m 'Release version 1.2'

典型用法

将其添加到 setup.py 中(处理已安装的包)

from setuptools import setup

setup(
    ...,
    # version=1.0,  # remove the version parameter as it will be overridden
    setup_requires=['katversion'],
    use_katversion=True,
    ...
)

将其添加到 mypackage/__init__.py 中,包括注释行(处理本地包)

# BEGIN VERSION CHECK
# Get package version when locally imported from repo or via -e develop install
try:
    import katversion as _katversion
except ImportError:  # pragma: no cover
    import time as _time
    __version__ = "0.0+unknown.{}".format(_time.strftime('%Y%m%d%H%M'))
else:  # pragma: no cover
    __version__ = _katversion.get_version(__path__[0])
# END VERSION CHECK

此外,还有一个用于检查版本的命令行脚本

# From inside your SCM subdirectory, run the following command
# which will print the result to stdout:
$ kat-get-version.py

项目详情


下载文件

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

源代码发行版

katversion-1.2.tar.gz (12.0 kB 查看散列值)

上传时间 源代码

构建发行版

katversion-1.2-py2.py3-none-any.whl (13.2 kB 查看散列值)

上传时间 Python 2 Python 3

由以下支持

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