搅拌机蒸馏器插件
blender.distutils的Python项目详细描述
这个python模块将一个新命令添加到 distutils生成Blender加载项:bdist_blender_addon。它还提供了一个简单的机制来打包插件中blender的python发行版中没有包含的额外模块。
示例
请参阅info_example_distutils加载项以了解如何使用该distutils模块。
安装
安装blender.distutils模块
该模块在pipy上可用,可使用pip安装。
$ pip install blender.distutils
建议添加 requirements.txt文件到列出模块依赖项的Blender插件。
# This is requirements.txt # This module adds the setup.py bdist_blender_addon command blender.distutils # This module is required by the addon, but not distributed with blender # bdist_blender_addon will ship it if with the addon # Dependencies to be included are listed in setup.cfg dateutils
添加一个简单的setup.py到blender插件
bdist_blender_addon是一个distutils命令。因此,需要一个setup.py文件。加载项名称和版本由此文件定义。我建议使用bumpversion来保持setup.py、bl_info和git标记的同步。
搅拌机插件的setup.py实际上非常简单。参数install_requires只应列出加载项所需的第一级依赖项:这些依赖项可能需要自己的依赖项。加载项附带的实际模块是在setup.cfg中精心挑选的。
fromsetuptoolsimportsetup,find_packagessetup(name='info_example_distutils',version='1.0.0',description='Blender example distutils',long_description=open('README.md').read(),url='https://github.com/charlesfleche/blender.distutils/io_example_distutils',author='Charles Flèche',author_email='charles.fleche@free.fr',license='MIT',classifiers=['Development Status :: 5 - Production/Stable','Intended Audience :: End Users/Desktop','Topic :: Multimedia :: Graphics :: 3D Modeling','Topic :: Multimedia :: Graphics :: 3D Rendering','License :: OSI Approved :: MIT License','Programming Language :: Python :: 3 :: Only'],packages=find_packages(),keywords='blender',# Here are listed first level dependencies needed by the module. Themselves# may require dependencies. The actual modules to be shipped with the addon# are cherry picked in setup.cfginstall_requires=['dateutils'])
包括未与搅拌机一起装运的第三方模块
bdist_blender_addon命令允许包含其他python 未与搅拌机一起装运的模块。这些模块将 包含在加载项的根文件夹中。当前的显式列表 需要配置模块,包括它们的依赖项。
Cherry选择要与搅拌机附件一起装运的模块
要包含在Blender插件中的模块作为选项列出 在setup.cfg中的[bdist_blender_addon]部分。此列表 包括所有模块及其依赖项。
# This is in setup.cfg [bdist_blender_addon] # Here are listed the modules (and their dependencies) to be shipped # with the blender module. In this example the addon requires `dateutils`, # which in turns requires `dateutil`, `pytz` and `six`. addon_require = dateutil,dateutils,pytz,six
在附加代码中包括附加模块文件夹
加载项需要显式注册到第三方模块的路径。 在开发过程中,这些模块将处于虚拟环境中。什么时候? 插件已安装在生产环境中,这些模块将位于根目录下 加载项文件夹的。
importpathlibimportosimportsiteimportsysdefthird_party_modules_sitedir():# If we are in a VIRTUAL_ENV, while developing for example, we want the# addon to hit the modules installed in the virtual environmentif'VIRTUAL_ENV'inos.environ:env=pathlib.Path(os.environ['VIRTUAL_ENV'])v=sys.version_infopath=env/'lib/python{}.{}/site-packages'.format(v.major,v.minor)# However outside of a virtual environment, the additionnal modules not# shipped with Blender are expected to be found in the root folder of# the addonelse:path=pathlib.Path(__file__).parentreturnstr(path.resolve())# The additionnal modules location (virtual env or addon folder) is# appended heresite.addsitedir(third_party_modules_sitedir())# This module is not part of the standard blender distribution# It is shipped alongside the plugin when `python setup.py bdist_blender_addon`importdateutils
构建模块
bdist_blender_addon命令将复制加载项代码,复制 附加模块,清除不需要的文件(如*.pyc 字节码文件)并将它们打包到 dist文件夹。
$ python setup.py bdist_blender_addon running bdist_blender_addon running build running build_py creating build/lib/info_example_distutils copying info_example_distutils/__init__.py -> build/lib/info_example_distutils creating build/lib/info_example_distutils/dateutil [long list of files being copied or added to the addon zip archive] $ ls dist/ info_example_distutils-v1.0.0.zip