How to exclude a single file from package with setuptools and setup.py(如何使用 setuptools 和 setup.py 从包中排除单个文件)
问题描述
我正在研究 blowdrycss.存储库在这里.
I am working on blowdrycss. The repository is here.
我希望将 blowdrycss_settings.py 的设置文件从 pypi 的最终包中排除.目的是动态构建一个自定义设置文件,该文件将放置在用户 virtualenv/项目文件夹中.
I want the settings file for blowdrycss_settings.py to be excluded from the final package on pypi. The intention is to dynamically build a custom settings file that will be placed in the users virtualenv / project folder.
在 setup.py 中,我有以下内容:
In setup.py, I have the following:
packages=find_packages(exclude=['blowdrycss_settings.py', ]),
我也试过 exclude_package_data:
exclude_package_data={
'': ['blowdrycss_settings.py'],
'': ['blowdrycss/blowdrycss_settings.py'],
'blowdrycss': ['blowdrycss_settings.py'],
},
然后我运行 python setup.py sdist bdist.
但是,当我查看构建文件夹时,我仍然看到 blowdrycss_settings.py:
However, when I look in the build folder I still see blowdrycss_settings.py:
- build
- lib
- blowdrycss_settings.py
似乎只排除一个文件应该很简单.
It seems like it should be simple to just exclude a file.
如何从分布式包中排除blowdrycss_settings.py?
How do I exclude blowdrycss_settings.py from the distributed package?
推荐答案
这是我的解决方案.
在 blowdrycss 下,我创建了一个名为 settings 的新模块,因此目录结构现在如下所示:
Underneath of blowdrycss, I created a new module called settings so the directory structure now looks like this:
blowdrycss
blowdrycss
settings
blowdrycss_settings.py
基于此参考,在setup.py 我有以下内容:
Based on this reference, inside of setup.py I have the following:
packages=find_packages(exclude=['*.settings', ]),
构建发行版:
- 删除
build、dist和.egg-info文件夹. - 运行
python setup.py sdist bdist
- Delete the
build,dist, and.egg-infofolders. - Run
python setup.py sdist bdist
回想起来,我无法做我最初尝试的事情是件好事.新结构感觉更干净,更模块化.
In retrospect, it is good that I was unable to do what I was originally attempting. The new structure feels cleaner and is more modular.
这篇关于如何使用 setuptools 和 setup.py 从包中排除单个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用 setuptools 和 setup.py 从包中排除单个文件
基础教程推荐
- 由Python将MP3转换为MIDI(类型错误:无法加载插件:mtg-Melodia:Melodia) 2022-01-01
- 用 Python 编写 Fortran 无格式文件 2022-01-01
- 在 Celery 工作人员中捕获 Heroku SIGTERM 以优雅地关 2022-01-01
- 使用生成器和迭代器时 Python 多循环失败 2022-01-01
- 将 x 轴刻度更改为自定义字符串 2022-01-01
- pyserial - 可以从线程 a 写入串行端口,是否阻塞从线程 b 读取? 2022-01-01
- Discord.py 缺少必需的参数 2022-01-01
- 与常规 dict 相比,Python manager.dict() 非常慢 2022-01-01
- numpy float:比算术运算中内置的慢 10 倍? 2022-01-01
- 尝试制作WhatsApp机器人 2022-01-01
