Python の setup.py を書いてみる | CUBE SUGAR STORAGE | entry_points の書き方 |
fabricとbuildoutで環境構築 第3章 (1) buildoutでレシピを書く - 今川館 | buildout |
tarek / flake8 / source / setup.py — Bitbucket | entry_points には辞書が使える。 |
buildout/src/zc/buildout at master · buildout/buildout · GitHub | buildout は bin/buildout した時、Recipe の install を何となく叩きそうだ。 |
djangorecipe 1.5 : Python Package Index | コードを参考にした。 |
Jinja2 利用ノート | Template と render() |
Last active
December 15, 2015 01:49
-
-
Save tomoh1r/5182646 to your computer and use it in GitHub Desktop.
Buildout 用の hogerecipe。 src/hoge.py というファイルを書き出す。
djangorecipe が簡潔にまとまっていたので参考にした。
template (boilerplate ?) に Jinja2 を利用するとどうかと思い書いた。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[buildout] | |
parts = hoge | |
[hoge] | |
# message には日本語も利用可能 | |
message = こんにちは、 | |
recipe = hogerecipe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
def say(name): | |
return '{{message}} {0}'.format(name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import os | |
from contextlib import nested | |
from jinja2 import Template | |
class Recipe(object): | |
'''hogerecipe's recipe''' | |
def __init__(self, buildout, name, options): | |
'''Buildout initial script.''' | |
self.buildout, self.name, self.options = buildout, name, options | |
def install(self): | |
'''construct hoge script.''' | |
# mkdir src/ | |
base_dir = self.buildout['buildout']['directory'] | |
os.mkdir(os.path.join(base_dir, 'src')) | |
# output hoge.py | |
template_path = os.path.join( | |
os.path.dirname(__file__), 'templates', 'hoge.jinja2') | |
output_path = os.path.join(base_dir, 'src', 'hoge.py') | |
script_paths = [output_path] | |
with nested( | |
open(os.path.join(template_path), 'rb'), | |
open(os.path.join(output_path), 'wb'), | |
) as (template_fp, output_fp): | |
message = self.options['message'].decode('utf-8') | |
hoge_py = Template(template_fp.read()).render(message=message) | |
output_fp.write(hoge_py.encode('utf-8')) | |
return script_paths |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from setuptools import setup, find_packages | |
setup( | |
name='hogerecipe', | |
version='0.0.1', | |
description="Buildout recipe for study", | |
long_description='hoge fuga piyo', | |
classifiers=[ | |
'Framework :: Buildout', | |
'Topic :: Software Development :: Build Tools', | |
'Development Status :: 5 - Production/Stable', | |
'License :: OSI Approved :: BSD License', | |
'Programming Language :: Python :: 2.7', | |
], | |
package_dir={'': 'src'}, | |
packages=find_packages('src'), | |
keywords='', | |
author='Tomohiro Nakamura', | |
author_email='tomo@example.com', | |
license='BSD', | |
zip_safe=False, | |
install_requires=[ | |
'zc.buildout', | |
'zc.recipe.egg', | |
'jinja2', | |
], | |
entry_points={ | |
'zc.buildout': ['default = hogerecipe.recipe:Recipe'], | |
}, | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ tree | |
. | |
├── setup.py | |
└── src | |
└── hogerecipe | |
├── __init__.py # 空のファイル | |
├── recipe.py | |
└── templates | |
└── hoge.jinja2 | |
3 directories, 4 files |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment