File: tips.html

package info (click to toggle)
virtualenvwrapper 3.4-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 4,140 kB
  • sloc: sh: 3,801; python: 991; makefile: 27
file content (212 lines) | stat: -rw-r--r-- 13,030 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Tips とトリック &mdash; virtualenvwrapper v3.4 documentation</title>
    <link rel="stylesheet" href="_static/nature.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '',
        VERSION:     '3.4',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/underscore.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <link rel="top" title="virtualenvwrapper v3.4 documentation" href="index.html" />
    <link rel="next" title="開発者向け" href="developers.html" />
    <link rel="prev" title="プロジェクト管理" href="projects.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="developers.html" title="開発者向け"
             accesskey="N">next</a></li>
        <li class="right" >
          <a href="projects.html" title="プロジェクト管理"
             accesskey="P">previous</a> |</li>
        <li><a href="index.html">virtualenvwrapper v3.4 documentation</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="tips">
<span id="tips-and-tricks"></span><h1>Tips とトリック<a class="headerlink" href="#tips" title="Permalink to this headline">¶</a></h1>
<p>これは virtualenv と virtualenvwrapper をさらに使い易くするためにユーザが教えてくれた tips です。あなたが共有したい tip を持っているなら、私にメールを送ってもらうか、 <a class="reference external" href="http://blog.doughellmann.com/2010/01/virtualenvwrapper-tips-and-tricks.html">このブログ</a> にコメントをください。私はこのページにその tip を追加します。</p>
<div class="section" id="zsh">
<h2>zsh プロンプト<a class="headerlink" href="#zsh" title="Permalink to this headline">¶</a></h2>
<p><a class="reference external" href="http://www.blogger.com/profile/16779944428406910187">Nat</a> からです。</p>
<p>zsh を使用して、アクティブな仮想環境をスクリーンの右側に表示するために <tt class="docutils literal"><span class="pre">$WORKON_HOME/post(de)activate</span></tt> に少し追加しました。</p>
<p><tt class="docutils literal"><span class="pre">postactivate</span></tt> は次になります。</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">PS1</span><span class="o">=</span><span class="s">&quot;$_OLD_VIRTUAL_PS1&quot;</span>
<span class="n">_OLD_RPROMPT</span><span class="o">=</span><span class="s">&quot;$RPROMPT&quot;</span>
<span class="n">RPROMPT</span><span class="o">=</span><span class="s">&quot;%{${fg_bold[white]}%}(env: %{${fg[green]}%}`basename </span><span class="se">\&quot;</span><span class="s">$VIRTUAL_ENV</span><span class="se">\&quot;</span><span class="s">`%{${fg_bold[white]}%})%{${reset_color}%} $RPROMPT&quot;</span>
</pre></div>
</div>
<p>そして <tt class="docutils literal"><span class="pre">postdeactivate</span></tt> は次になります。</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">RPROMPT</span><span class="o">=</span><span class="s">&quot;$_OLD_RPROMPT&quot;</span>
</pre></div>
</div>
<p>個人的な趣向や環境に応じて色を調整してください。</p>
</div>
<div class="section" id="path">
<h2>キャッシュされた <tt class="docutils literal"><span class="pre">$PATH</span></tt> エントリを更新する<a class="headerlink" href="#path" title="Permalink to this headline">¶</a></h2>
<p><a class="reference external" href="http://www.blogger.com/profile/16779944428406910187">Nat</a> からです。</p>
<p>さらに zsh は新たなパスをすぐに取得しない問題があったので <tt class="docutils literal"><span class="pre">$WORKON_HOME/postactivate</span></tt> と <tt class="docutils literal"><span class="pre">$WORKON_HOME/postdeactivate</span></tt> へコマンド &#8216;rehash&#8217; も追加しました。</p>
</div>
<div class="section" id="pip-virtualenv">
<h2>pip の virtualenv サポート<a class="headerlink" href="#pip-virtualenv" title="Permalink to this headline">¶</a></h2>
<p><a class="reference external" href="http://becomingguru.com/">http://becomingguru.com/</a> からです。</p>
<p>virtualenvwrapper として virtualenvs のために pip が同じディレクトリを使用するようにログインシェルに次の内容を追加してください。</p>
<div class="highlight-python"><pre>export PIP_VIRTUALENV_BASE=$WORKON_HOME</pre>
</div>
<p>さらに Nat からです。</p>
<p>becomingguru が指摘したことに加えて次の行がキーになります。</p>
<div class="highlight-python"><pre>export PIP_RESPECT_VIRTUALENV=true</pre>
</div>
<p>それは -E パラメータを pip へ渡さずに pip がアクティブな仮想環境を検出してインストールします。</p>
</div>
<div class="section" id="id2">
<h2>プロジェクトのワークディレクトリを作成する<a class="headerlink" href="#id2" title="Permalink to this headline">¶</a></h2>
<p><a class="reference external" href="http://www.blogger.com/profile/02618224969192901883">James</a> からです。</p>
<p>私は <tt class="docutils literal"><span class="pre">postmkvirtualenv</span></tt> スクリプトでプロジェクト名に基づいてディレクトリを作成して、
Python パスへそのディレクトリを追加してからそこへ移動します。</p>
<div class="highlight-python"><pre>proj_name=$(echo $VIRTUAL_ENV|awk -F'/' '{print $NF}')
mkdir $HOME/projects/$proj_name
add2virtualenv $HOME/projects/$proj_name
cd $HOME/projects/$proj_name</pre>
</div>
<p>私は <tt class="docutils literal"><span class="pre">postactivate</span></tt> スクリプトで workon コマンドを使用するときに自動的にプロジェクトディレクトリへ移動するようにセットします。</p>
<div class="highlight-python"><pre>proj_name=$(echo $VIRTUAL_ENV|awk -F'/' '{print $NF}')
cd ~/projects/$proj_name</pre>
</div>
</div>
<div class="section" id="workon">
<h2>ディレクトリへ移動したときに自動的に workon を実行する<a class="headerlink" href="#workon" title="Permalink to this headline">¶</a></h2>
<p><tt class="docutils literal"><span class="pre">cd</span></tt> を実行する毎にそのディレクトリでシェル環境を調べるように追加したコードを <a class="reference external" href="http://justinlilly.com/python/virtualenv_wrapper_helper.html">Justin Lily が投稿しました</a> 。 <tt class="docutils literal"><span class="pre">.venv</span></tt> ファイルを見つけたら、そのファイルに含まれる環境の名前でアクティブ化します。そのディレクトリから移動すると、カレントの仮想環境は自動的に非アクティブ化します。</p>
<p><a class="reference external" href="http://www.blogger.com/profile/17141199633387157732">Harry Marr</a> は <a class="reference external" href="http://hmarr.com/2010/jan/19/making-virtualenv-play-nice-with-git/">git リポジトリ</a> で動作するよく似た機能を書きました。</p>
</div>
<div class="section" id="id3">
<h2>新しい環境に共通ツールを自動的にインストールする<a class="headerlink" href="#id3" title="Permalink to this headline">¶</a></h2>
<p><a class="reference external" href="http://rizumu.myopenid.com/">rizumu</a> からです。</p>
<p>私はこの <tt class="docutils literal"><span class="pre">postmkvirtualenv</span></tt> を基本的なセットアップを行うインストールに使用します。</p>
<div class="highlight-python"><pre>$ cat postmkvirtualenv
#!/usr/bin/env bash
curl -O http://python-distribute.org/distribute_setup.p... /&gt;python distribute_setup.py
rm distribute_setup.py
easy_install pip==dev
pip install Mercurial</pre>
</div>
<p>それから、私の開発ツールと共に pip の要求ファイルを持ちます。</p>
<div class="highlight-python"><pre>$ cat developer_requirements.txt
ipdb
ipython
pastescript
nose
http://douglatornell.ca/software/python/Nosy-1.0.tar.gz
coverage
sphinx
grin
pyflakes
pep8</pre>
</div>
<p>それぞれのプロジェクトは PIL, psycopg2, django-apps, numpy といったその独自の pip 要求ファイルを持ちます。</p>
</div>
<div class="section" id="cd">
<h2><tt class="docutils literal"><span class="pre">cd</span></tt> のデフォルトの振る舞いを変更する<a class="headerlink" href="#cd" title="Permalink to this headline">¶</a></h2>
<p><a class="reference external" href="http://www.blogger.com/profile/10879711379090472478">mae</a> からです。</p>
<p>これは workon の後で実行することになる <tt class="docutils literal"><span class="pre">postactivate</span></tt> フックです。venv ルートへ移動する <tt class="docutils literal"><span class="pre">~</span></tt> へ <tt class="docutils literal"><span class="pre">cd</span></tt> で移動する代わりに VENV を知っているように <tt class="docutils literal"><span class="pre">cd</span></tt> を基本的に上書きします。IMO はとても扱い易くて、もうそれなしでは生きていけません。適切なパスが渡されると正常に移動します。</p>
<div class="highlight-python"><pre>cd () {
    if (( $# == 0 ))
    then
        builtin cd $VIRTUAL_ENV
    else
        builtin cd "$@"
    fi
}

cd</pre>
</div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
  <h3><a href="index.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Tips とトリック</a><ul>
<li><a class="reference internal" href="#zsh">zsh プロンプト</a></li>
<li><a class="reference internal" href="#path">キャッシュされた <tt class="docutils literal"><span class="pre">$PATH</span></tt> エントリを更新する</a></li>
<li><a class="reference internal" href="#pip-virtualenv">pip の virtualenv サポート</a></li>
<li><a class="reference internal" href="#id2">プロジェクトのワークディレクトリを作成する</a></li>
<li><a class="reference internal" href="#workon">ディレクトリへ移動したときに自動的に workon を実行する</a></li>
<li><a class="reference internal" href="#id3">新しい環境に共通ツールを自動的にインストールする</a></li>
<li><a class="reference internal" href="#cd"><tt class="docutils literal"><span class="pre">cd</span></tt> のデフォルトの振る舞いを変更する</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="projects.html"
                        title="previous chapter">プロジェクト管理</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="developers.html"
                        title="next chapter">開発者向け</a></p>
  <h3>This Page</h3>
  <ul class="this-page-menu">
    <li><a href="_sources/tips.txt"
           rel="nofollow">Show Source</a></li>
  </ul>
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="search.html" method="get">
      <input type="text" name="q" size="18" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="developers.html" title="開発者向け"
             >next</a></li>
        <li class="right" >
          <a href="projects.html" title="プロジェクト管理"
             >previous</a> |</li>
        <li><a href="index.html">virtualenvwrapper v3.4 documentation</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
        &copy; Copyright 2009-2011, Doug Hellmann.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.5.
    </div>
  </body>
</html>