Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Pip升级/更新功能_Python_Python 2.7_Pip - Fatal编程技术网

Python Pip升级/更新功能

Python Pip升级/更新功能,python,python-2.7,pip,Python,Python 2.7,Pip,我已将一个包上载到PyPI,其中包含用户可以根据其特定配置编辑的文件1和文件2 现在,当我更改此软件包,用户决定使用pip install-U package更新其安装时,是否有办法让文件1和文件2保持原样,因为如果它得到升级,用户将不得不重新进行配置。 我可以在setup.py中引入一些代码来达到预期效果?下面是我的setup.py # Always prefer setuptools over distutils from setuptools import setup, find_pack

我已将一个包上载到PyPI,其中包含用户可以根据其特定配置编辑的文件1和文件2

现在,当我更改此软件包,用户决定使用
pip install-U package
更新其安装时,是否有办法让文件1和文件2保持原样,因为如果它得到升级,用户将不得不重新进行配置。 我可以在setup.py中引入一些代码来达到预期效果?下面是我的setup.py

# Always prefer setuptools over distutils
from setuptools import setup, find_packages
# To use a consistent encoding
from codecs import open
from os import path

pwd = path.abspath(path.dirname(__file__))

with open(path.join(pwd, 'LICENSE.txt'), encoding='utf-8') as f:
    long_description = f.read()


setup(
    name='mypackage',

    # Using version number from git tag
    # use_scm_version={"root": "..", "relative_to": __file__},
    use_scm_version=True,
    setup_requires=['setuptools_scm'],

    description='XYZ',
    long_description=long_description,

    # The project's main homepage.
    url='https://www.google.com/',

    # Author details
    author='XYZ',
    author_email='xyz@xyz.com',

    # Choose your license
    license='See package description',

    # See https://pypi.python.org/pypi?%3Aaction=list_classifiers
    classifiers=[
        # How mature is this project? Common values are
        #   3 - Alpha
        #   4 - Beta
        #   5 - Production/Stable
        'Development Status :: 3 - Alpha',

        # Keep updating supported frameworks here

        'Framework :: Django',

        # Indicate who your project is intended for
        'Intended Audience :: Developers',
        'Intended Audience :: System Administrators',
        'Intended Audience :: Information Technology',

        # Pick your license as you wish (should match "license" above)
        'License :: Other/Proprietary License',

        # Specify the Python versions you support here. In particular, ensure
        # that you indicate whether you support Python 2, Python 3 or both.
        'Programming Language :: Python :: 2.7',
    ],

    # Project associated keywords - space separated
    keywords='ca_apm_agent performance-monitoring development APM',

    # You can just specify the packages manually here if your project is
    # simple. Or you can use find_packages().
    packages=find_packages(exclude=['docs', 'tests']),

    # Alternatively, if you want to distribute just a my_module.py, uncomment
    # this:
    #   py_modules=["my_module"],

    # List run-time dependencies here.  These will be installed by pip when
    # your project is installed. For an analysis of "install_requires" vs pip's
    # requirements files see:
    # https://packaging.python.org/en/latest/requirements.html
    install_requires=[],

    # List additional groups of dependencies here (e.g. development
    # dependencies). You can install these using the following syntax,
    # for example:
    # $ pip install -e .[dev,test]
    extras_require={
        'dev': ['check-manifest'],
        'test': ['coverage'],
    },

    # If there are data files included in your packages that need to be
    # installed, specify them here.  If using Python 2.6 or less, then these
    # have to be included in MANIFEST.in as well.
    include_package_data=True,
    package_data={
        'mypackage': ['directives/file1, directives/file2'],
    },

    # Although 'package_data' is the preferred approach, in some case you may
    # need to place data files outside of your packages. See:
    # http://docs.python.org/3.4/distutils/setupscript.html#installing-additional-files # noqa
    # In this case, 'data_file' will be installed into '<sys.prefix>/my_data'
    # data_files=[('my_data', ['data/data_file'])],
    data_files=[],

    # To provide executable scripts, use entry points in preference to the
    # "scripts" keyword. Entry points provide cross-platform support and allow
    # pip to create the appropriate form of executable for the target platform.
    entry_points={
        'console_scripts': [
            'mypackage-run=mypackage:main',
        ],
    },
)
#总是更喜欢设置工具而不是distutils
从setuptools导入设置中,查找\u包
#使用一致的编码
从编解码器导入打开
从操作系统导入路径
pwd=path.abspath(path.dirname(_文件__))
使用open(path.join(pwd,'LICENSE.txt'),将='utf-8'编码为f:
long_description=f.read()
设置(
name='mypackage',
#使用git标记中的版本号
#使用scm_version={“根”:..,“相对”:uuuuuuu文件uuuu},
使用\u scm\u version=True,
setup\u requires=['setuptools\u scm'],
description='XYZ',
长描述=长描述,
#该项目的主要主页。
url='1〕https://www.google.com/',
#作者详细信息
作者='XYZ',
作者(电邮地址)xyz@xyz.com',
#选择您的许可证
license='See package description',
#看https://pypi.python.org/pypi?%3Aaction=list_classifiers
分类器=[
#这个项目有多成熟?共同的价值观是
#3-α
#4-β
#5-生产/稳定
“发展状况:3-阿尔法”,
#在这里不断更新受支持的框架
'框架::Django',
#指出您的项目的目标对象
'目标受众::开发者',
'目标受众::系统管理员',
“目标受众:信息技术”,
#根据需要选择您的许可证(应与上面的“许可证”匹配)
“许可证::其他/专有许可证”,
#在此处指定您支持的Python版本。尤其要确保
#指示是否支持Python 2、Python 3或两者。
'编程语言::Python::2.7',
],
#项目关联关键字-空间分隔
关键词=“ca\U apm\U代理性能监控开发apm”,
#如果您的项目不可用,您可以在此处手动指定包
#简单。也可以使用find_packages()。
packages=find_packages(排除=['docs','tests']),
#或者,如果只想分发my_module.py,请取消注释
#这:
#py_模块=[“我的_模块”],
#在此列出运行时依赖项。这些依赖项将由pip在
#您的项目已安装。有关“install_requires”与pip的分析
#要求文件见:
# https://packaging.python.org/en/latest/requirements.html
安装_需要=[],
#在此列出其他依赖项组(例如开发
#依赖项)。您可以使用以下语法安装它们,
#例如:
#$pip安装-e.[dev,test]
额外需要={
“开发人员”:[“检查清单”],
“测试”:[“覆盖率”],
},
#如果软件包中包含数据文件,则需要
#已安装,请在此处指定它们
#也必须包含在MANIFEST.in中。
include_package_data=True,
数据包={
“mypackage”:[“指令/file1,指令/file2'],
},
#虽然“数据包”是首选方法,但在某些情况下,您可能会
#需要将数据文件放在包之外。请参阅:
# http://docs.python.org/3.4/distutils/setupscript.html#installing-其他文件#noqa
#在这种情况下,“数据文件”将安装到“/my\u data”中
#数据文件=[(“我的数据”,“数据/数据文件])],
数据文件=[],
#要提供可执行脚本,请优先使用入口点而不是
#“脚本”关键字。入口点提供跨平台支持并允许
#pip为目标平台创建适当形式的可执行文件。
入境点={
“控制台脚本”:[
“mypackage运行=mypackage:main”,
],
},
)

用户不应编辑发行版中包含的文件,也不应在安装发行版的目录中创建任何新文件

一种常见的模式是使用homedir中的文件(例如,
~/.myapp.cfg
)进行任何自定义,然后在应用程序中分发一些合理的默认配置

您的应用程序将检查是否存在用户配置,但应用程序不应要求存在自定义配置才能运行。您可以决定是将用户配置“分层”到默认配置之上,还是只是优先使用默认配置


确保清楚地记录了用户配置的文件格式和预期位置

我担心我会收到关于编辑发行版中包含的文件的评论。无论如何,如果我假设,发行版是在主目录中安装myapp.cfg并由用户编辑的发行版,是否有办法保持此文件不变,而不替换为pip ugrade上的默认myapp.cfg?这将取决于您的
setup.py
,您没有将其包括在问题中(请添加它)。您使用的是
distutils
还是
setuptools
?哪个版本?我已经包括了setup.py。我从pypa的git中获取了该文件,他们建议使用我使用的安装工具。我不确定这个版本对它有什么影响,但它是36.6.0。我只是试了大约2个小时,现在我放弃了。我现在确信你不能做到这一点(至少在没有入侵黑客的情况下)。你可以考虑用A来代替使用<代码> PACKAGEDATA < /COD>。或者干脆放弃这个想法,该死。非常感谢您的尝试:)