Python车轮套餐 - 如何将时间戳添加到轮子名称中?

发布于 2025-02-13 03:43:16 字数 3480 浏览 2 评论 0原文

我正在使用Jenkins为Python创建新的构建软件包。 我的setup.py文件如下:

setup(
    name = "my-package",
    version = "1.0.0",
    author = "Bob Bob",
    description = "test",
    packages=['my-package'],
    install_requires=['sample1001']
)

我们运行: python setup.py bdist_wheel 结果文件如下: my_package-1.0.0.0-py3-none-any.whl

我知道,通过简单版本更改我可以影响我的车轮软件包名称。但是大多数情况下,如果设置了一些小更改,我们不想更改版本字段,但是我们想将timestamp添加到轮子的现有名称中软件包,以便我们可以拥有不同的构建文件(不要覆盖上一个文件),

您能告诉我 - 如何将时间戳添加到车轮名称中?我在任何地方都找不到这些信息...

非常感谢!

更新: 我尝试了Keith建议的解决方案:

import os
from setuptools import setup, find_packages
from os.path import dirname,abspath
with open('Bundle/requirements.txt') as f:
    requirements = f.read().splitlines()

def read(fname):
    return open(os.path.join(dirname(dirname(abspath(__file__))), 'Readme.Md')).read()

setup(
    name='fa-bundle',
    version='1.0.0',
    install_requires=requirements,
    description='Bundle is a project that will replace old Package Manager',
    long_description=read('Readme.Md'),
    use_scm_version=True,
    setup_requires=['setuptools_scm'],
    long_description_content_type='text/markdown',
    author='FCS',
    python_requires=">=3.9, <4",
    packages=find_packages()
)

错误:

Traceback (most recent call last):
  File "/data/jenkins/pypi/fabundle/fa-bundle/base/setup.py", line 18, in <module>
    setup(
  File "/data/jenkins/pypi/fabundle/lib64/python3.9/site-packages/setuptools/__init__.py",
line 87, in setup
    return distutils.core.setup(**attrs)
  File "/data/jenkins/pypi/fabundle/lib64/python3.9/site-packages/setuptools/_distutils/core.py",
line 139, in setup
    _setup_distribution = dist = klass(attrs)
  File "/data/jenkins/pypi/fabundle/lib64/python3.9/site-packages/setuptools/dist.py",
line 476, in __init__
    _Distribution.__init__(
  File "/data/jenkins/pypi/fabundle/lib64/python3.9/site-packages/setuptools/_distutils/dist.py",
line 275, in __init__
    self.finalize_options()
  File "/data/jenkins/pypi/fabundle/lib64/python3.9/site-packages/setuptools/dist.py",
line 900, in finalize_options
    ep(self)
  File "/data/jenkins/pypi/fabundle/lib64/python3.9/site-packages/setuptools/dist.py",
line 920, in _finalize_setup_keywords
    ep.load()(self, ep.name, value)
  File "/data/jenkins/pypi/fabundle/fa-bundle/base/.eggs/setuptools_scm-7.0.4-py3.9.egg/setuptools_scm/integration.py",
line 90, in version_keyword
    _assign_version(dist, config)
  File "/data/jenkins/pypi/fabundle/fa-bundle/base/.eggs/setuptools_scm-7.0.4-py3.9.egg/setuptools_scm/integration.py",
line 62, in _assign_version
    _version_missing(config)
  File "/data/jenkins/pypi/fabundle/fa-bundle/base/.eggs/setuptools_scm-7.0.4-py3.9.egg/setuptools_scm/__init__.py",
line 109, in _version_missing
    raise LookupError( LookupError: setuptools-scm was unable to detect version for /data/jenkins/pypi/fabundle/fa-bundle/base.

Make sure you're either building from a fully intact git repository or
PyPI tarballs. Most other sources (such as GitHub's tarballs, a git
checkout without the .git folder) don't contain the necessary metadata
and will not work.

For example, if you're using pip, instead of
https://github.com/user/proj/archive/master.zip use
git+https://github.com/user/proj.git#egg=proj

I am using Jenkins to create a new build packages for Python.
My setup.py file is the following:

setup(
    name = "my-package",
    version = "1.0.0",
    author = "Bob Bob",
    description = "test",
    packages=['my-package'],
    install_requires=['sample1001']
)

We run:
python setup.py bdist_wheel
The resulting file is the following:
my_package-1.0.0-py3-none-any.whl

I know that by simple version change I can impact my wheel package name. But most of the time if some small change is being set we do not want to change the version field, but we would like to add timestamp to the existing name of the wheel package, so that we can have different build file (not to overwrite the previous one),

Can you please tell me - how I can add timestamp to wheel name? I cannot find that info anywhere...

Thanks a lot!

UPDATE:
I tried solution suggested by Keith:

import os
from setuptools import setup, find_packages
from os.path import dirname,abspath
with open('Bundle/requirements.txt') as f:
    requirements = f.read().splitlines()

def read(fname):
    return open(os.path.join(dirname(dirname(abspath(__file__))), 'Readme.Md')).read()

setup(
    name='fa-bundle',
    version='1.0.0',
    install_requires=requirements,
    description='Bundle is a project that will replace old Package Manager',
    long_description=read('Readme.Md'),
    use_scm_version=True,
    setup_requires=['setuptools_scm'],
    long_description_content_type='text/markdown',
    author='FCS',
    python_requires=">=3.9, <4",
    packages=find_packages()
)

Error:

Traceback (most recent call last):
  File "/data/jenkins/pypi/fabundle/fa-bundle/base/setup.py", line 18, in <module>
    setup(
  File "/data/jenkins/pypi/fabundle/lib64/python3.9/site-packages/setuptools/__init__.py",
line 87, in setup
    return distutils.core.setup(**attrs)
  File "/data/jenkins/pypi/fabundle/lib64/python3.9/site-packages/setuptools/_distutils/core.py",
line 139, in setup
    _setup_distribution = dist = klass(attrs)
  File "/data/jenkins/pypi/fabundle/lib64/python3.9/site-packages/setuptools/dist.py",
line 476, in __init__
    _Distribution.__init__(
  File "/data/jenkins/pypi/fabundle/lib64/python3.9/site-packages/setuptools/_distutils/dist.py",
line 275, in __init__
    self.finalize_options()
  File "/data/jenkins/pypi/fabundle/lib64/python3.9/site-packages/setuptools/dist.py",
line 900, in finalize_options
    ep(self)
  File "/data/jenkins/pypi/fabundle/lib64/python3.9/site-packages/setuptools/dist.py",
line 920, in _finalize_setup_keywords
    ep.load()(self, ep.name, value)
  File "/data/jenkins/pypi/fabundle/fa-bundle/base/.eggs/setuptools_scm-7.0.4-py3.9.egg/setuptools_scm/integration.py",
line 90, in version_keyword
    _assign_version(dist, config)
  File "/data/jenkins/pypi/fabundle/fa-bundle/base/.eggs/setuptools_scm-7.0.4-py3.9.egg/setuptools_scm/integration.py",
line 62, in _assign_version
    _version_missing(config)
  File "/data/jenkins/pypi/fabundle/fa-bundle/base/.eggs/setuptools_scm-7.0.4-py3.9.egg/setuptools_scm/__init__.py",
line 109, in _version_missing
    raise LookupError( LookupError: setuptools-scm was unable to detect version for /data/jenkins/pypi/fabundle/fa-bundle/base.

Make sure you're either building from a fully intact git repository or
PyPI tarballs. Most other sources (such as GitHub's tarballs, a git
checkout without the .git folder) don't contain the necessary metadata
and will not work.

For example, if you're using pip, instead of
https://github.com/user/proj/archive/master.zip use
git+https://github.com/user/proj.git#egg=proj

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

就此别过 2025-02-20 03:43:16

如果将项目放在git scm下,然后使用 setUptoopools_scm 从git标签管理版本。这包括在建造时标记“脏”。构建版本会自动调整。

If you put your project under git SCM, and then use setuptools_scm it will manage the version for you from git tags. that includes marking it "dirty" when building. The built version is automatically adjusted.

羁拥 2025-02-20 03:43:16

如果您想保留先前的构建,而不是试图通过Python软件包版本使用来强制它,我宁愿尝试正确设置Jenkins,这并不是针对此用法的。

I would rather try to set Jenkins correctly if you want to preserve the previous builds rather than trying to force it by python package versioning, which is not meant for this usage.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文