简体   繁体   English

如何判断 setup() 是否正在读取 setup.cfg?

[英]How to tell whether setup() is reading the setup.cfg?

I got a Python project generated using pyscaffold and I see the two standard main project files at the root setup.py and setup.cfg .我得到了一个使用pyscaffold生成的 Python 项目,我在根setup.pysetup.cfg看到了两个标准的主项目文件。 I modified the setup.cfg file adding a line under the metadata section with version=1.0.0 .我修改了setup.cfg文件,在元数据部分下添加了一行version=1.0.0

However, running python setup.py develop or python setup.py sdist I see in the outputs that the artifact name doesn't have the version I specified in the setup.cfg .但是,运行python setup.py developpython setup.py sdist我在输出中看到工件名称没有我在setup.cfg指定的版本。 I see the following:我看到以下内容:

Installed c:\users\SkyWalker\code\my_project\src
Processing dependencies for my_project==0.0.post0.dev1+g8386a10.dirty
Finished processing dependencies for my_project==0.0.post0.dev1+g8386a10.dirty

The distribution artifact has this 0.0.post0.dev1+g8386a10.dirty version and I don't know where it's getting it from.分发工件有这个0.0.post0.dev1+g8386a10.dirty版本,我不知道它是从哪里得到的。 How to tell whether python.cfg is read at all?如何判断python.cfg是否被读取?

The pyscaffold generated setup.py looks like this: pyscaffold 生成的setup.py如下所示:

# -*- coding: utf-8 -*-
"""
    Setup file for aqm_database_api.
    Use setup.cfg to configure your project.

    This file was generated with PyScaffold 3.2.3.
    PyScaffold helps you to put up the scaffold of your new Python project.
    Learn more under: https://pyscaffold.org/
"""
import sys

from pkg_resources import VersionConflict, require
from setuptools import setup

try:
    require('setuptools>=37.0')
except VersionConflict:
    print("Error: version of setuptools is too old (<37.0)!")
    sys.exit(1)


if __name__ == "__main__":
    setup(use_pyscaffold=True)

so it's not loading setup.cfg explicitly, also the line require('setuptools>=37.0') fails every time, no matter what the version value there is.所以它没有显式加载setup.cfg ,无论版本值是什么, require('setuptools>=37.0')每次都会失败。

PyScaffold configures setuptools to use the version given by setuptools_scm . PyScaffold提供配置setuptools使用给出的版本setuptools_scm It means that, in order to change the version of your project you need to use git to tag your project .这意味着,为了更改项目的版本,您需要使用 git 来标记您的项目 This is briefly described in https://pyscaffold.org/en/v3.3.x/features.html#versioning-and-git-integration .这在https://pyscaffold.org/en/v3.3.x/features.html#versioning-and-git-integration 中有简要描述。

I suppose that is the reason why changing setup.cfg will not change the version of the distribution created.我想这就是为什么更改setup.cfg不会更改创建的分发版本的原因。 A priori setuptools should always read setup.cfg .先验设置setuptools应始终读取setup.cfg

To make sure setuptools is reading setup.cfg one experiment you can do is:为了确保setuptools正在读取setup.cfg您可以做的一项实验是:

  1. Make sure to remove any *.egg-info folder insude the root of your project or inside the src folder (to ensure you don't see a cached version).确保删除项目根目录或src文件夹内的任何*.egg-info文件夹(以确保您看不到缓存版本)。
  2. Change something easy like author in the setup.cfg filesetup.cfg文件中更改诸如 author 之类的setup.cfg内容
  3. Build your package as you would do normally ( python setup.py bdist_wheel for example)像往常一样构建你的包(例如python setup.py bdist_wheel
  4. Look for a new <your-project>.egg-info folder generated either in the root of your project or inside the src directory.查找在<your-project>.egg-info根目录或src目录中生成的新<your-project>.egg-info文件夹。 Read the PKG-INFO there.在那里阅读PKG-INFO You should be able to see your changes which proves setuptools is reading setup.cfg (otherwise the best option should be opening a ticket/issue with setuptools )您应该能够看到您的更改,这证明setuptools正在读取setup.cfg (否则最好的选择应该是使用setuptools开票/问题)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM