使用 versioneer 和 GitHub 更新版本号

2024-05-10

我在用versioneer适用于多个 GitHub 托管的 Python 项目。看来 versioneer 已安装并且工作正常,我可以调用project.__version__.

但是我忘记了如何更新版本号的过程。如果有什么东西在setup.cfg or setup.py保持不变?

难道只有git tag控制版本号的命令?如果我使用 GitHub 的“草稿新版本”,Python/versioneer 版本号会自动更新吗? GitHub 的发布是最好的方式吗?或者我应该这样做,例如,git tag v0.2本地?我想这并不重要?


Yes, versioneer将从 git tag + 存储库状态获取版本号。无需修改您的安装文件(或version.py 对于此事)是必要的。(这就是版本控制者的美妙之处。)

Oleksandr 链接的文档包含了所有内容(https://github.com/python-versioneer/python-versioneer/blob/master/INSTALL.md https://github.com/python-versioneer/python-versioneer/blob/master/INSTALL.md)

例如,如果您刚刚将您的存储库标记为v1.0,您的代码版本(例如,import mylib; print(mylib.__version__), or python setup.py version从终端)将显示一个干净的v1.0.

如果您碰巧修改和/或提交了某些内容,版本将相应更新。下面是我的一个存储库的当前状态:一次提交,加上未提交的更改,位于“v1.1”标签之上,

$ python setup.py version

/opt/miniconda3/envs/osh_devel/lib/python3.10/site-packages/setuptools/dist.py:506: UserWarning: Normalizing 'v1.1+1.g106ac16.dirty' to '1.1+1.g106ac16.dirty'
  warnings.warn(tmpl.format(**locals()))
running version
keywords are unexpanded, not using
got version from VCS {'version': 'v1.1+1.g106ac16.dirty', 'full-revisionid': '106ac1638a9a789fa8bdb6df42a608985b18e88c', 'dirty': True, 'error': None, 'date': '2022-03-25T17:01:46+0100'}
Version: v1.1+1.g106ac16.dirty
 full-revisionid: 106ac1638a9a789fa8bdb6df42a608985b18e88c
 dirty: True
 date: 2022-03-25T17:01:46+0100

关于 PyPI 和的注意事项pyproject.toml

添加后pyproject.toml将文件添加到我的库后,版本控制程序停止工作,每当我尝试(开发)安装时都会显示以下错误消息:

$ pip install -e .

Obtaining file:///Users/chbrandt/Coisas/repos/stuff/osh
  Installing build dependencies ... done
  Checking if build backend supports build_editable ... done
  Getting requirements to build wheel ... error
  error: subprocess-exited-with-error
  
  × Getting requirements to build wheel did not run successfully.
  │ exit code: 1
  ╰─> [16 lines of output]
      Traceback (most recent call last):
        File "/opt/miniconda3/envs/osh_devel/lib/python3.10/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 363, in <module>
          main()
        File "/opt/miniconda3/envs/osh_devel/lib/python3.10/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 345, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
        File "/opt/miniconda3/envs/osh_devel/lib/python3.10/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 130, in get_requires_for_build_wheel
          return hook(config_settings)
        File "/private/var/folders/b1/frq3gywj3ljfqrf1yc7zk06r0000gn/T/pip-build-env-6kvnzo67/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 177, in get_requires_for_build_wheel
          return self._get_build_requires(
        File "/private/var/folders/b1/frq3gywj3ljfqrf1yc7zk06r0000gn/T/pip-build-env-6kvnzo67/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 159, in _get_build_requires
          self.run_setup()
        File "/private/var/folders/b1/frq3gywj3ljfqrf1yc7zk06r0000gn/T/pip-build-env-6kvnzo67/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 174, in run_setup
          exec(compile(code, __file__, 'exec'), locals())
        File "setup.py", line 2, in <module>
          import versioneer
      ModuleNotFoundError: No module named 'versioneer'
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.

Without pyproject.toml一切恢复正常,工作正常。

发生此问题的原因是 python/设置框架的演变,如该线程中所述:

  • https://github.com/python-versioneer/python-versioneer/issues/193#issue-408237852 https://github.com/python-versioneer/python-versioneer/issues/193#issue-408237852

,就在下面的同一线程中,您将看到解决方案。

只需添加"versioneer-518"到 pyproject 的requires. E.g.:

pyproject.toml:

[build-system]
requires = ["setuptools>=42", "versioneer-518"]
build-backend = "setuptools.build_meta"
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 versioneer 和 GitHub 更新版本号 的相关文章

随机推荐