# pollination-dsl
A Python Domain Specific Language (DSL) to create Pollination Plugins and Recipes.
Pollination uses [Queenbee](https://github.com/pollination/queenbee) as its workflow
language. Pollination-dsl makes it easy to create Queenbee object without the need to
learn Queenbee.
![pollination-dsl](https://user-images.githubusercontent.com/2915573/106669142-36d04880-6579-11eb-9763-a718aec27166.jpg)
# API docs
[Pollination-DSL API docs](https://pollination.github.io/pollination-dsl/docs/pollination_dsl.html#subpackages)
# Requirements
Python >=3.7
# Installation
Using pip:
`pip install pollination-dsl`
For local development:
1. Clone this repository.
2. Change directory to root folder of the repository.
3. `pip install -e .`
# Quick Start
If you are interested to start writing your own plugins and recipe see the
[introduction post](https://github.com/pollination/pollination-dsl/wiki/Introduction).
## Function
```python
from dataclasses import dataclass
from pollination_dsl.function import Function, command, Inputs, Outputs
@dataclass
class CreateOctreeWithSky(Function):
"""Generate an octree from a Radiance folder and sky!"""
# inputs
include_aperture = Inputs.str(
default='include',
description='A value to indicate if the static aperture should be included in '
'octree. Valid values are include and exclude. Default is include.',
spec={'type': 'string', 'enum': ['include', 'exclude']}
)
black_out = Inputs.str(
default='default',
description='A value to indicate if the black material should be used. Valid '
'values are default and black. Default value is default.',
spec={'type': 'string', 'enum': ['black', 'default']}
)
model = Inputs.folder(description='Path to Radiance model folder.', path='model')
sky = Inputs.file(description='Path to sky file.', path='sky.sky')
@command
def create_octree(self):
return 'honeybee-radiance octree from-folder model --output scene.oct ' \
'--{{self.include_aperture}}-aperture --{{self.black_out}} ' \
'--add-before sky.sky'
# outputs
scene_file = Outputs.file(description='Output octree file.', path='scene.oct')
```
If you want to access the `Queenbee` objects you can use `queenbee` property. For example
try `print(CreateOctreeWithSky().queenbee.yaml())` and you should see the full Queenbee
definition:
```yaml
type: Function
annotations: {}
inputs:
- type: FunctionStringInput
annotations: {}
name: black-out
description: A value to indicate if the black material should be used. Valid values
are default and black. Default value is default.
default: default
alias: []
required: false
spec:
type: string
enum:
- black
- default
- type: FunctionStringInput
annotations: {}
name: include-aperture
description: A value to indicate if the static aperture should be included in octree.
Valid values are include and exclude. Default is include.
default: include
alias: []
required: false
spec:
type: string
enum:
- include
- exclude
- type: FunctionFolderInput
annotations: {}
name: model
description: Path to Radiance model folder.
default: null
alias: []
required: true
spec: null
path: model
- type: FunctionFileInput
annotations: {}
name: sky
description: Path to sky file.
default: null
alias: []
required: true
spec: null
path: sky.sky
extensions: null
outputs:
- type: FunctionFileOutput
annotations: {}
name: scene-file
description: Output octree file.
path: scene.oct
name: create-octree-with-sky
description: Generate an octree from a Radiance folder and sky!
command: honeybee-radiance octree from-folder model --output scene.oct --{{inputs.include-aperture}}-aperture
--{{inputs.black-out}} --add-before sky.sky
```
Since the functions are standard Python classes you can also subclass them from one
another as long as you use the same name for the `@command` method. Otherwise it will
create an invalid function with two commands.
## Plugin
To create a Pollination plugin use the functions to create a standard Python module.
The only change is that you need to provide the information for Pollination plugin in
the `__init__.py` file as dictionary assigned to `__pollination__` variable.
Follow the standard way to install a Python package. Once the package is installed you
can use `pollination-dsl` to load the package or write it to a folder.
```python
from pollination_dsl.package import load, write
# name of the pollination package
python_package = 'pollination_honeybee_radiance'
# load this package as Pollination Plugin
plugin = load(python_package)
# or write the package as a Pollination plugin to a folder directly
write(python_package, './pollination-honeybee-radiance')
```
See [`pollination-honeybee-radiance` plugin](https://github.com/pollination/pollination-honeybee-radiance) for a full project example.
## Recipe
`Recipe` is a collection of `DAG`s. Each `DAG` is a collection of interrelated `task`s.
You can use pollination-dsl to create complex recipes with minimum code by reusing the
`functions` as templates for each task.
Packaging a plugin is exactly the same as packaging a plugin.
```python
from pollination_dsl.package import load, translate
# name of the pollination package
python_package = 'daylight-factor'
# load this package as Pollination Recipe
recipe = load(python_package, baked=True)
# or translate and write the package as a Pollination plugin to a folder directly
translate(python_package, './daylight-factor')
```
See [`daylight factor` recipe](https://github.com/pollination/ladybug-tools-recipes/tree/master/recipes/daylight-factor) for a full project example.
# How to create a pollination-dsl package
Pollination-dsl uses Python's standard packaging to package pollination plugins and recipes.
It parses most of the data from inputs in `setup.py` file and some Pollination specific
information from `__init__.py` file. Below is an example of how these file should look
like.
By taking advantage of [Python's native namespace packaging](https://packaging.python.org/guides/packaging-namespace-packages/#native-namespace-packages)
we keep all the packages under the `pollination` namespace.
## setup.py
```python
#!/usr/bin/env python
import setuptools
# These two class extends setup.py to install the packages as pollination packages
from pollination_dsl.package import PostInstall, PostDevelop
# Read me will be mapped to readme strings
with open("README.md", "r") as fh:
long_description = fh.read()
setuptools.setup(
cmdclass={'develop': PostDevelop, 'install': PostInstall}, # required - include this for pollination packaging
name='pollination-honeybee-radiance', # required - will be used for package name
packages=setuptools.find_namespace_packages(include=['pollination.*']), # required - that's how pollination find the package
author='ladybug-tools', # required - author must match the owner account name on Pollination
version='0.1.0', # required - will be used as package tag. you can also use semantic versioning
zip_safe=False, # required - set to False to ensure the packaging will always work
project_urls={
'icon': 'https://ladybug.tools/assets/icon.png', # optional but strongly encouraged - link to package icon
},
url='https://github.com/pollination/pollination-honeybee-radiance', # optional - will be translated to home
description='Honeybee Radiance plugin for Pollination.', # optional - will be used as package description
long_description=long_description, # optional - will be translated to Read
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
资源分类:Python库 所属语言:Python 资源全名:pollination-dsl-0.8.2.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源推荐
资源详情
资源评论
收起资源包目录
pollination-dsl-0.8.2.tar.gz (40个子文件)
pollination-dsl-0.8.2
PKG-INFO 12KB
.releaserc.json 294B
docs
conf.py 6KB
modules.rst 84B
_build
.nojekyll 1B
docs
README.md 16B
README.md 16B
README.md 375B
index.rst 252B
.github
workflows
ci.yaml 3KB
pollination_dsl.egg-info
PKG-INFO 12KB
requires.txt 110B
SOURCES.txt 997B
entry_points.txt 58B
top_level.txt 16B
dependency_links.txt 1B
LICENSE 11KB
dev-requirements.txt 191B
deploy.sh 165B
setup.cfg 102B
requirements.txt 110B
pollination_dsl
common.py 3KB
cli.py 6KB
function
inputs.py 5KB
__init__.py 224B
outputs.py 5KB
base.py 6KB
__init__.py 30B
dag
task.py 11KB
inputs.py 7KB
__init__.py 127B
outputs.py 7KB
base.py 4KB
package.py 13KB
alias
inputs.py 10KB
__init__.py 85B
outputs.py 9KB
setup.py 1003B
.gitignore 156B
README.md 9KB
共 40 条
- 1
资源评论
挣扎的蓝藻
- 粉丝: 14w+
- 资源: 15万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功