如何使用setuptools和setup.py从软件包中排除单个文件 [英] How to exclude a single file from package with setuptools and setup.py

查看:119
本文介绍了如何使用setuptools和setup.py从软件包中排除单个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究blowdrycss.该存储库位于此处.

I am working on blowdrycss. The repository is here.

我希望将blowdrycss_settings.py的设置文件从pypi的最终软件包中排除.目的是动态构建自定义设置文件,该文件将放置在用户virtualenv/project文件夹中.

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中,我有以下内容:

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', ]),   

要建立发行版:

  1. 删除builddist.egg-info文件夹.
  2. 运行python setup.py sdist bdist
  1. Delete the build, dist, and .egg-info folders.
  2. 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从软件包中排除单个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆