Browse Source

Add Mozilla/Virtualenv (#14)

Peter Bengtsson 3 years ago
parent
commit
5f6a978b02
2 changed files with 154 additions and 0 deletions
  1. 79 0
      files/en-us/mozilla/virtualenv/index.html
  2. 75 0
      files/en-us/mozilla/virtualenv/raw.html

+ 79 - 0
files/en-us/mozilla/virtualenv/index.html

@@ -0,0 +1,79 @@
+---
+title: Virtualenv
+slug: Mozilla/Virtualenv
+---
+<p><a class="external" href="http://pypi.python.org/pypi/virtualenv">virtualenv</a> is software for isolating <a href="/en-US/Glosdsty/Python">python</a> package environments (e.g. <code>import</code> paths). It is written by Mozilla's own <a class="external" href="https://www.ianbicking.org/">Ian Bicking</a>. Creating a virtualenv installs <a class="external" href="http://pypi.python.org/pypi/setuptools">setuptools</a> (or optionally <a class="external" href="http://packages.python.org/distribute/">distribute</a>) into the virtual environment. It is recommended that you use virtualenv for installing anything other than&nbsp;system software that you are working&nbsp;on.&nbsp; You will obviate the need to have access to your system packages and you won't mess up your system packages with whatever code you install into the site-packages directory of the virtualenv.&nbsp; <a class="external" href="http://blog.ianbicking.org/site-packages-considered-harmful.html">site-packages should mostly be for system-installed python and not python that you are installing as a user</a>.</p>
+
+<p>This page is mostly a stub for how virtualenv is used at Mozilla. For more information on virtualenv in general, see the <a class="external" href="http://virtualenv.org">virtualenv web site</a>. Python packaging at Mozilla is covered in <a href="/en-US/Glossary/Python">Python</a>.</p>
+
+<h2 id="Getting_Virtualenv">Getting Virtualenv</h2>
+
+<p>virtualenv is a <a class="external" href="http://pypi.python.org/pypi/virtualenv">python package</a>.&nbsp; You can download it from <a class="external" href="http://pypi.python.org/pypi/virtualenv">its PyPI package page</a> or install it with <a class="external" href="http://packages.python.org/distribute/easy_install.html">easy_install</a>. The <a class="link-https" href="https://github.com/pypa/virtualenv">github virtualenv repository</a> is maintained by the <a class="link-https" href="https://github.com/pypa">Python Packaging Authority</a> (including Mozilla's <a class="external" href="http://ziade.org/">Tarek Ziade</a> and <a class="external" href="https://www.ianbicking.org/">Ian Bicking</a>).&nbsp; If you have <a class="external" href="http://git-scm.com/">git</a> installed, you can clone the latest version of virtualenv: <code>git clone git://github.com/pypa/virtualenv.git</code></p>
+
+<p>If you have <a class="external" href="http://pypi.python.org/pypi/pip">pip</a> or <a class="external" href="http://packages.python.org/distribute/easy_install.html">easy_install</a>, you can install virtualenv directly from the web:</p>
+
+<pre>pip install virtualenv
+# -or-
+easy_install virtualenv
+</pre>
+
+<p>This will fetch virtualenv from <a class="external" href="http://pypi.python.org/pypi/virtualenv">PyPI</a> and install it in your <a class="external" href="http://docs.python.org/install/index.html">site-packages</a>. You may need to use <code>sudo</code> to obtain appropriate permissions for the system. If you do not have <code>pip</code> or <code>easy_install</code>, you will need to download <a class="external" href="http://pypi.python.org/pypi/virtualenv">from PyPI</a> or clone <a class="link-https" href="https://github.com/pypa/virtualenv">from the github virtualenv repository</a>, extract from the tarball (in the PyPI case), and run <code>python setup.py install</code>.&nbsp; Again, you may need to use <code>sudo</code> to install globally.&nbsp; If you're running Ubuntu, there is also an Ubuntu package available:</p>
+
+<pre>sudo apt-get install python-virtualenv
+</pre>
+
+<p><a class="link-https" href="https://raw.github.com/pypa/virtualenv/develop/virtualenv.py">virtualenv.py</a> may also be run as standalone software with the same functionality.&nbsp; It will require it to be part of a clone of <a class="link-https" href="https://github.com/pypa/virtualenv">the github repository</a> or have internet access to fetch setuptools.</p>
+
+<p>On Mac OS X, you will need Xcode to use virtualenv.&nbsp; See <a class="link-https" href="https://github.com/pypa/virtualenv/issues/168">this article for details</a>.</p>
+
+<h2 id="Using_Virtualenv">Using Virtualenv</h2>
+
+<p>Once you have virtualenv installed, you can make virtual environments:</p>
+
+<pre>&gt; virtualenv tmp
+New python executable in tmp/bin/python
+Installing setuptools............done.
+Installing pip...............done.
+</pre>
+
+<p>A python binary, as well as <code>easy_install</code> and <code>pip</code> are available in the <code>bin/</code> subdirectory (or <code>Scripts</code> on windows).</p>
+
+<pre>&gt; ls tmp/bin/
+activate      activate.fish     easy_install      pip      python
+activate.csh  activate_this.py  easy_install-2.7  pip-2.7
+</pre>
+
+<p>Using this python binary, or these scripts (which point to this python binary), you will correctly install python packages in the <code>lib/python2.x/site-packages</code> directory and they will be appropriately added to your import path (<a class="external" href="http://docs.python.org/tutorial/modules.html#the-module-search-path">sys.path</a>) via <code>lib/python2.x/site.py</code>. In order to get the virtualenv's python binary on your <code><a class="external" href="https://en.wikipedia.org/wiki/PATH_%28variable%29">PATH</a></code>, you should source the <code>bin/activate</code> script on unix or run <code>activate.bat</code> on Windows.</p>
+
+<h3 id="Unix_example">Unix example</h3>
+
+<pre>. bin/activate
+</pre>
+
+<p>Once the virtualenv is activated, the virtualenv's python (and other executables) will be on your <code>PATH</code> and you will have a new environment variable, <code>VIRTUAL_ENV</code>, that points to the path of the virtualenv, as well as a <code>deactivate</code> function for deactivating the virtualenv.</p>
+
+<h2 id="Virtualenv_tools">Virtualenv tools</h2>
+
+<p>virtualenv does one thing well: creates isolated virtual environments of python packages. Due to its utility, tools have been built around this functionality. Here are a few such tools:</p>
+
+<ul>
+ <li>carton: make a self-extracting virtualenv from directories or URLs of packages; <a class="external" href="http://pypi.python.org/pypi/carton">http://pypi.python.org/pypi/carton</a></li>
+ <li>velcro: a script that sets up a Python project for local installation; <a class="link-https" href="https://bitbucket.org/kumar303/velcro/">https://bitbucket.org/kumar303/velcro/</a></li>
+ <li>
+  <p>virtualenvwrapper: a set of extensions to Ian Bicking’s <a class="reference external" href="http://pypi.python.org/pypi/virtualenv">virtualenv</a> tool for creating isolated Python development environments; <a class="external" href="http://www.doughellmann.com/projects/virtualenvwrapper">http://www.doughellmann.com/projects...tualenvwrapper</a></p>
+ </li>
+</ul>
+
+<h2 id="The_Mozilla-Central_Virtualenv">The Mozilla-Central Virtualenv</h2>
+
+<p>In order to make use of various python modules located throughout mozilla-central, a virtualenv is created as part of the build process: http://mxr.mozilla.org/mozilla-central/source/js/src/build/autoconf/python-virtualenv.m4 . The virtualenv is created in <code>${OBJDIR}/_virtualenv</code> and should be recreated as part of the <a href="http://hg.mozilla.org/mozilla-central/file/0c45e6378f1f/client.mk#l260">configure step</a>.</p>
+
+<p>The <a href="http://mxr.mozilla.org/mozilla-central/source/build/virtualenv/populate_virtualenv.py">populate_virtualenv.py</a> script, when invoked, installs a list of packages, http://mxr.mozilla.org/mozilla-central/source/build/virtualenv/packages.txt , into the virtualenv via one of various methods.&nbsp; The <a href="/en-US/docs/Mozilla/Developer_guide/Build_Instructions">Mozilla build system</a> mostly uses <a href="http://docs.python.org/2/install/index.html#inst-search-path">.pth files</a> instead of the more typically used <code>python setup.py develop</code> or <code>python setup.py install</code> to install python modules in to the virtualenv's <a href="http://docs.python.org/2/library/sys.html#sys.path">python path</a> due to performance concerns (although such functionality is available via the <code>setup.py</code> keyword in a <code>packages.txt</code> file). When using this method, be aware that the parts of package installation invoked via <a href="http://packages.python.org/distribute/setuptools.html">setup.py</a>, such as console-script creation and dependency resolution, will not be invoked.</p>
+
+<p>The virtualenv software, mirrored from a canonical version, lives in <a href="http://packages.python.org/distribute/setuptools.html">python/virtualenv</a>.</p>
+
+<h2 id="See_also">See also</h2>
+
+<ul>
+ <li><a class="external" href="http://brasstacks.mozilla.com/toolbox/?usage=virtualenv">virtualenv usage docs</a></li>
+</ul>

+ 75 - 0
files/en-us/mozilla/virtualenv/raw.html

@@ -0,0 +1,75 @@
+<p><a class="external" href="http://pypi.python.org/pypi/virtualenv">virtualenv</a> is software for isolating <a href="/en-US/Glosdsty/Python">python</a> package environments (e.g. <code>import</code> paths). It is written by Mozilla's own <a class="external" href="https://www.ianbicking.org/">Ian Bicking</a>. Creating a virtualenv installs <a class="external" href="http://pypi.python.org/pypi/setuptools">setuptools</a> (or optionally <a class="external" href="http://packages.python.org/distribute/">distribute</a>) into the virtual environment. It is recommended that you use virtualenv for installing anything other than system software that you are working on.  You will obviate the need to have access to your system packages and you won't mess up your system packages with whatever code you install into the site-packages directory of the virtualenv.  <a class="external" href="http://blog.ianbicking.org/site-packages-considered-harmful.html">site-packages should mostly be for system-installed python and not python that you are installing as a user</a>.</p>
+
+<p>This page is mostly a stub for how virtualenv is used at Mozilla. For more information on virtualenv in general, see the <a class="external" href="http://virtualenv.org">virtualenv web site</a>. Python packaging at Mozilla is covered in <a href="/en-US/Glossary/Python">Python</a>.</p>
+
+<h2 id="Getting_Virtualenv">Getting Virtualenv</h2>
+
+<p>virtualenv is a <a class="external" href="http://pypi.python.org/pypi/virtualenv">python package</a>.  You can download it from <a class="external" href="http://pypi.python.org/pypi/virtualenv">its PyPI package page</a> or install it with <a class="external" href="http://packages.python.org/distribute/easy_install.html">easy_install</a>. The <a class="link-https" href="https://github.com/pypa/virtualenv">github virtualenv repository</a> is maintained by the <a class="link-https" href="https://github.com/pypa">Python Packaging Authority</a> (including Mozilla's <a class="external" href="http://ziade.org/">Tarek Ziade</a> and <a class="external" href="https://www.ianbicking.org/">Ian Bicking</a>).  If you have <a class="external" href="http://git-scm.com/">git</a> installed, you can clone the latest version of virtualenv: <code>git clone git://github.com/pypa/virtualenv.git</code></p>
+
+<p>If you have <a class="external" href="http://pypi.python.org/pypi/pip">pip</a> or <a class="external" href="http://packages.python.org/distribute/easy_install.html">easy_install</a>, you can install virtualenv directly from the web:</p>
+
+<pre>pip install virtualenv
+# -or-
+easy_install virtualenv
+</pre>
+
+<p>This will fetch virtualenv from <a class="external" href="http://pypi.python.org/pypi/virtualenv">PyPI</a> and install it in your <a class="external" href="http://docs.python.org/install/index.html">site-packages</a>. You may need to use <code>sudo</code> to obtain appropriate permissions for the system. If you do not have <code>pip</code> or <code>easy_install</code>, you will need to download <a class="external" href="http://pypi.python.org/pypi/virtualenv">from PyPI</a> or clone <a class="link-https" href="https://github.com/pypa/virtualenv">from the github virtualenv repository</a>, extract from the tarball (in the PyPI case), and run <code>python setup.py install</code>.  Again, you may need to use <code>sudo</code> to install globally.  If you're running Ubuntu, there is also an Ubuntu package available:</p>
+
+<pre>sudo apt-get install python-virtualenv
+</pre>
+
+<p><a class="link-https" href="https://raw.github.com/pypa/virtualenv/develop/virtualenv.py">virtualenv.py</a> may also be run as standalone software with the same functionality.  It will require it to be part of a clone of <a class="link-https" href="https://github.com/pypa/virtualenv">the github repository</a> or have internet access to fetch setuptools.</p>
+
+<p>On Mac OS X, you will need Xcode to use virtualenv.  See <a class="link-https" href="https://github.com/pypa/virtualenv/issues/168">this article for details</a>.</p>
+
+<h2 id="Using_Virtualenv">Using Virtualenv</h2>
+
+<p>Once you have virtualenv installed, you can make virtual environments:</p>
+
+<pre>&gt; virtualenv tmp
+New python executable in tmp/bin/python
+Installing setuptools............done.
+Installing pip...............done.
+</pre>
+
+<p>A python binary, as well as <code>easy_install</code> and <code>pip</code> are available in the <code>bin/</code> subdirectory (or <code>Scripts</code> on windows).</p>
+
+<pre>&gt; ls tmp/bin/
+activate      activate.fish     easy_install      pip      python
+activate.csh  activate_this.py  easy_install-2.7  pip-2.7
+</pre>
+
+<p>Using this python binary, or these scripts (which point to this python binary), you will correctly install python packages in the <code>lib/python2.x/site-packages</code> directory and they will be appropriately added to your import path (<a class="external" href="http://docs.python.org/tutorial/modules.html#the-module-search-path">sys.path</a>) via <code>lib/python2.x/site.py</code>. In order to get the virtualenv's python binary on your <code><a class="external" href="https://en.wikipedia.org/wiki/PATH_%28variable%29">PATH</a></code>, you should source the <code>bin/activate</code> script on unix or run <code>activate.bat</code> on Windows.</p>
+
+<h3 id="Unix_example">Unix example</h3>
+
+<pre>. bin/activate
+</pre>
+
+<p>Once the virtualenv is activated, the virtualenv's python (and other executables) will be on your <code>PATH</code> and you will have a new environment variable, <code>VIRTUAL_ENV</code>, that points to the path of the virtualenv, as well as a <code>deactivate</code> function for deactivating the virtualenv.</p>
+
+<h2 id="Virtualenv_tools">Virtualenv tools</h2>
+
+<p>virtualenv does one thing well: creates isolated virtual environments of python packages. Due to its utility, tools have been built around this functionality. Here are a few such tools:</p>
+
+<ul>
+ <li>carton: make a self-extracting virtualenv from directories or URLs of packages; <a class="external" href="http://pypi.python.org/pypi/carton">http://pypi.python.org/pypi/carton</a></li>
+ <li>velcro: a script that sets up a Python project for local installation; <a class="link-https" href="https://bitbucket.org/kumar303/velcro/">https://bitbucket.org/kumar303/velcro/</a></li>
+ <li>
+  <p>virtualenvwrapper: a set of extensions to Ian Bicking’s <a class="reference external" href="http://pypi.python.org/pypi/virtualenv">virtualenv</a> tool for creating isolated Python development environments; <a class="external" href="http://www.doughellmann.com/projects/virtualenvwrapper">http://www.doughellmann.com/projects...tualenvwrapper</a></p>
+ </li>
+</ul>
+
+<h2 id="The_Mozilla-Central_Virtualenv">The Mozilla-Central Virtualenv</h2>
+
+<p>In order to make use of various python modules located throughout mozilla-central, a virtualenv is created as part of the build process: http://mxr.mozilla.org/mozilla-central/source/js/src/build/autoconf/python-virtualenv.m4 . The virtualenv is created in <code>${OBJDIR}/_virtualenv</code> and should be recreated as part of the <a href="http://hg.mozilla.org/mozilla-central/file/0c45e6378f1f/client.mk#l260">configure step</a>.</p>
+
+<p>The <a href="http://mxr.mozilla.org/mozilla-central/source/build/virtualenv/populate_virtualenv.py">populate_virtualenv.py</a> script, when invoked, installs a list of packages, http://mxr.mozilla.org/mozilla-central/source/build/virtualenv/packages.txt , into the virtualenv via one of various methods.  The <a href="/en-US/docs/Mozilla/Developer_guide/Build_Instructions">Mozilla build system</a> mostly uses <a href="http://docs.python.org/2/install/index.html#inst-search-path">.pth files</a> instead of the more typically used <code>python setup.py develop</code> or <code>python setup.py install</code> to install python modules in to the virtualenv's <a href="http://docs.python.org/2/library/sys.html#sys.path">python path</a> due to performance concerns (although such functionality is available via the <code>setup.py</code> keyword in a <code>packages.txt</code> file). When using this method, be aware that the parts of package installation invoked via <a href="http://packages.python.org/distribute/setuptools.html">setup.py</a>, such as console-script creation and dependency resolution, will not be invoked.</p>
+
+<p>The virtualenv software, mirrored from a canonical version, lives in <a href="http://packages.python.org/distribute/setuptools.html">python/virtualenv</a>.</p>
+
+<h2 id="See_also">See also</h2>
+
+<ul>
+ <li><a class="external" href="http://brasstacks.mozilla.com/toolbox/?usage=virtualenv">virtualenv usage docs</a></li>
+</ul>