プレリュード:cookiecutterによるプロジェクトのクイック起動(Prelude: Quick Project Startup with Cookiecutters)¶
プロジェクトを開始するプロセスを簡単にするためPylonsプロジェクトでは、プロジェクトテンプレートからサンプル Pyramid プロジェクトを生成する cookiecutter を提供しています。これらのcookiecuttersは Pyramid とその依存関係をインストールします。Pyramid を使用したWebアプリケーション開発の多くのトピックについてはまだ説明しますが、この機能について知っておくとよいでしょう。このプレリュードは「cookiecutter」を操作して、 Pyramid Webアプリケーションを取得する方法を示します。
目標(Objectives)¶
- 新しいプロジェクトを作成するにはcookiecutterを使用します。
- Pyramid アプリケーションを起動してWebブラウザで参照してください
手順(Steps)¶
仮想環境にcookiecutterをインストールします。
$VENV/bin/pip install cookiecutter
「cookiecutter pyramid-cookiecutter-starter」を使用して現在のディレクトリに Pyramid プロジェクトを作成してから次のコマンドのためにプロンプトに値を入力してみましょう。
$ $VENV/bin/cookiecutter gh:Pylons/pyramid-cookiecutter-starter --checkout 1.9-branch
最初の項目の入力を求められたら、「yesre」と入力して「return」 キーを押してデフォルト設定を指定してください。
You've cloned ~/.cookiecutters/pyramid-cookiecutter-starter before. Is it okay to delete and re-clone it? [yes]: yes project_name [Pyramid Scaffold]: cc_starter repo_name [cc_starter]: cc_starter Select template_language: 1 - jinja2 2 - chameleon 3 - mako Choose from 1, 2, 3 [1]: 1
に以下のコマンドを実行します。"
# Change directory into your newly created project. $ cd cc_starter # Create a new virtual environment... $ python3 -m venv env # ...where we upgrade packaging tools... $ env/bin/pip install --upgrade pip setuptools # ...and into which we install our project. $ env/bin/pip install -e .
Pyramidのpserveコマンドをプロジェクトの(生成された)設定ファイルで指定して、アプリケーションを起動します:
$ env/bin/pserve development.ini --reload
起動時に、「pserve」にいくつかのログが出力されます。
Starting subprocess with file monitor Starting server in PID 73732. Serving on http://localhost:6543 Serving on http://localhost:6543
ブラウザでhttp:// localhost:6543 /を開きます。
分析(Analysis)¶
CookieCutterを使用すると最初から作業を始めるのではなく作業中の Pyramid アプリケーションを含むPythonプロジェクトを簡単に取得できます。Pylonsプロジェクトは いくつかのcookiecutters を提供しています。
「pserve」は Pyramid はコードから動作の詳細を分離するアプリケーションランナーです。 Pyramid をインストールすると、「pserve」とよばれる小さなコマンド・プログラム が「bin」ディレクトリに書き込まれます。このプログラムは実行可能なPythonモジュールです。これには設定ファイル(この場合はdevelopment.ini)が渡されます。