概要
cookiecutter(クッキーカッター)を使いpythonの自分専用のプロジェクトのひな型をつくり、そこからプロジェクトを作成する。
インストール
pip install cookiecutter
利用
プロジェクトを作りたいフォルダで以下を実行する。
プロジェクト名などの質問が来るので答えていく
- フル版
python -m cookiecutter gh:audreyfeldroy/cookiecutter-pypackage
- 簡易版
python -m cookiecutter gh:asweigart/cookiecutter-basicpythonproject
自分専用のテンプレートを作りgithubにアップして使う
-
githubに自分のアカウントがあることが前提とします。(hirayama-yuuichiの所はご自分のgithubの値で読み替えてください)
-
まず、元となるテンプレートをforkする。
asweigart/cookiecutter-basicpythonprojectを開き右上の「fork」をクリック「+Create a new fork」よりforkを作成する。 -
先ほどforkしたcookiecutter-basicpythonprojectのcloneを作る。
localにてgit clone https://github.com/hirayama-yuuichi/cookiecutter-basicpythonproject.git
-
修正の必要な部分を修正する(今回は例としてauthor_nameを固定の名前にする)
- cookiecutter.json から
"author_name": "Susie Softwaredeveloper" の行をさがし、入力例「"Susie Softwaredeveloper"」の部分を「hirayama yuuichi」(自分の環境にあった名前にしてください)に変更する - 他の部分も同様に置き換える。
- cookiecutter.json から
-
commitする
cd cookiecutter-basicpythonproject/
git commit -am "Changed the parameters of name"
応答メッセージ
[master de37b0d] Changed the parameters of name
7 files changed, 11 insertions(+), 15 deletions(-)
- githubにpushする
git push
応答メッセージ
Enumerating objects: 24, done.
Counting objects: 100% (24/24), done.
Delta compression using up to 12 threads
Compressing objects: 100% (13/13), done.
Writing objects: 100% (13/13), 1.42 KiB | 161.00 KiB/s, done.
Total 13 (delta 7), reused 0 (delta 0)
remote: Resolving deltas: 100% (7/7), completed with 7 local objects.
To https://github.com/hirayama-yuuichi/cookiecutter-basicpythonproject.git
c29a556..de37b0d master -> master
- 使ってみる
python -m cookiecutter gh:hirayama-yuuichi/cookiecutter-basicpythonproject
応答メッセージ(例として「XYZ Loder」というプロジェクトを作る)
project_name [Basic Python Project]: XYZ Loder
module_name [basicpythonproject]: xyzloder
project_version [0.1.0]:
project_short_description [A basic Python project.]: load xyz tool
参考
きれいなPythonプログラミング クリーンなコードを書くための最適な方法
ORGANIZING YOUR CODE PROJECTS WITH GIT
audreyfeldroy/cookiecutter-pypackage
cookiecutter