setup.py从bdist排除一些python文件 [英] setup.py exclude some python files from bdist
问题描述
我有一个具有这种架构的django项目:
- setup.py
- 项目/
- __ init __。py
- manage.py
- 设置/
- __ init __。py
- base.py
- dev.py
- urls /
- __ init __。py
- base.py >
- dev.py
我想在没有我的'dev.py'文件的.egg中部署它。我尝试了不同的方法:首先,使用
find_packages(exclude = ['*。dev','dev'])
,然后使用MANIFEST.in,其中包含:
global-exclude dev.py
第二个解决方案当我执行sdist时似乎可以正常工作-安装此警告时会出现此警告:
警告:没有以前包含的与' dev.py'可以在
发行版的任何位置找到,但不适用于bdist-egg。 / p>
这是我setup.py的一部分:
从setuptools导入安装程序,find_packages
项目导入版本
软件包= [
'项目',
'project.settings',
'项目。 urls',
]
setup(name ='project',
version = VERSION,
package_dir = {'project':'project'},
description =我的项目,
作者= Simon Urli,
授权or_email ='',
url ='',
包裹=包裹,#find_packages('project',exclude = ['*。dev','dev']),
)
请注意,我使用python 2.6.6,也许很重要。
任何想法如何正确创建排除dev文件的鸡蛋?
我最近遇到了同样的问题(尽管我必须用轮子代替鸡蛋),但解决方案的作用相同 bdist_egg
和 bdist_wheel
都可以。您必须覆盖 build_py
中的方法 find_package_modules
:
从setuptools导入fnmatch
导入find_packages,从setuptools.command.build_py设置
导入build_py作为build_py_orig
exclude = ['* .dev']
class build_py(build_py_orig):
def find_package_modules(self,package,package_dir):
modules = super ().find_package_modules(package,package_dir)
返回[(pkg,mod,file,)for(pkg,mod,file,)在模块
中,如果不存在(fnmatch.fnmatchcase(pkg +'。 '+ mod,pat = pattern)
用于排除模式)]
setup(
packages = find_packages(),
cmdclass = {' build_py':build_py},
)
在此示例中,名为<$ c $的模块所有软件包中的c> dev 都将从构建中排除。
如您所见,无需在其中玩排除项目 find_packages()
,因为您仍然需要包括所有软件包,但是您可以过滤每个软件包中找到的模块文件。 build_py
类非常通用,如果需要重用,可以在单独的库中进行重构。唯一与项目相关的东西是排除模式列表。
I have a django project with this kind of architecture :
- setup.py
- project/
- __init__.py
- manage.py
- settings/
- __init__.py
- base.py
- dev.py
- urls/
- __init__.py
- base.py
- dev.py
I wanted to deploy it in a .egg without my 'dev.py' files. I tried different ways : first, with a
find_packages(exclude=['*.dev','dev'])
, then with a MANIFEST.in which contains :
global-exclude dev.py
The second solution seems to work when I do a sdist - with this warning when I install it :
warning: no previously-included files matching 'dev.py' found anywhere in distribution
, but does'nt work with a bdist-egg.
Here a part of my setup.py :
from setuptools import setup, find_packages
project import VERSION
packages = [
'project',
'project.settings',
'project.urls',
]
setup(name='project',
version=VERSION,
package_dir = {'project' : 'project'},
description = 'My Project',
author = 'Simon Urli',
author_email = '',
url = '',
packages = packages, #find_packages('project',exclude=['*.dev', 'dev']),
)
Note that I use python 2.6.6, maybe it matters. Any idea how to create my egg excluding the dev files properly ?
I had the same issue recently (although I had to build a wheel instead of an egg), the solution works the same both for bdist_egg
and bdist_wheel
. You have to override the method find_package_modules
in build_py
:
import fnmatch
from setuptools import find_packages, setup
from setuptools.command.build_py import build_py as build_py_orig
exclude = ['*.dev']
class build_py(build_py_orig):
def find_package_modules(self, package, package_dir):
modules = super().find_package_modules(package, package_dir)
return [(pkg, mod, file, ) for (pkg, mod, file, ) in modules
if not any(fnmatch.fnmatchcase(pkg + '.' + mod, pat=pattern)
for pattern in exclude)]
setup(
packages=find_packages(),
cmdclass={'build_py': build_py},
)
In this example, modules named dev
in all packages will be excluded from the build.
As you can see, there's no need to play with exclusions in find_packages()
as you still need all packages to be included, but instead you filter the module files found in each package. The class build_py
is pretty much generic and could be refactored in a separate library if you need to reuse it; the only project-specific stuff is the list of exclude patterns.
这篇关于setup.py从bdist排除一些python文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!