<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Blog | Dr. Giselle Zeno</title><link>https://giselle.zeno.phd/blog/</link><atom:link href="https://giselle.zeno.phd/blog/index.xml" rel="self" type="application/rss+xml"/><description>Blog</description><generator>HugoBlox Kit (https://hugoblox.com)</generator><language>en-us</language><lastBuildDate>Fri, 26 Jul 2019 00:00:00 +0000</lastBuildDate><image><url>https://giselle.zeno.phd/media/icon_hu_4c9497d79ce0a228.png</url><title>Blog</title><link>https://giselle.zeno.phd/blog/</link></image><item><title>From Python to Julia</title><link>https://giselle.zeno.phd/blog/from-python-to-julia/</link><pubDate>Fri, 26 Jul 2019 00:00:00 +0000</pubDate><guid>https://giselle.zeno.phd/blog/from-python-to-julia/</guid><description>&lt;h2 id="python-and-julia"&gt;Python and Julia&lt;/h2&gt;
&lt;p&gt;I attended JuliaCon 2019 this week to learn more about the language. I have excllusively used Python for my research the last 6 years. What I love about Python is the ease and speed of implementing code. However, there have been many times where I wished I could make my experiments run faster. Even though there are some neat tricks that are optimized to run faster, such as list comprehensions, sometimes it&amp;rsquo;s not enough.&lt;/p&gt;
&lt;p&gt;Julia claims to run fast and the syntax is similar to Python, so I thought to give it a try. I will make a series of posts with what I learn along the way.&lt;/p&gt;
&lt;h3 id="references"&gt;References&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;
by
and
&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;</description></item><item><title>iPython Notebooks on a remote server</title><link>https://giselle.zeno.phd/blog/ipython-notebooks-on-a-remote-server/</link><pubDate>Fri, 15 May 2015 00:00:00 +0000</pubDate><guid>https://giselle.zeno.phd/blog/ipython-notebooks-on-a-remote-server/</guid><description>&lt;h2 id="what-is-ipython-notebook"&gt;What is iPython Notebook?&lt;/h2&gt;
&lt;p&gt;From
:&lt;/p&gt;
&lt;blockquote class="border-l-4 border-neutral-300 dark:border-neutral-600 pl-4 italic text-neutral-600 dark:text-neutral-400 my-6"&gt;
&lt;p&gt;The IPython Notebook is an interactive computational environment, in which you can combine code execution, rich text, mathematics, plots and rich media, as shown in this example session:&lt;/p&gt;
&lt;p&gt;
&lt;figure &gt;
&lt;div class="flex justify-center "&gt;
&lt;div class="w-full" &gt;
&lt;img alt="iPython Notebook example"
srcset="https://giselle.zeno.phd/blog/ipython-notebooks-on-a-remote-server/ipython_notebook_example_hu_b31c4dcd66933a36.webp 320w, https://giselle.zeno.phd/blog/ipython-notebooks-on-a-remote-server/ipython_notebook_example_hu_c5979fdc73a568a5.webp 480w, https://giselle.zeno.phd/blog/ipython-notebooks-on-a-remote-server/ipython_notebook_example_hu_ef380894a7bee8f2.webp 493w"
sizes="(max-width: 480px) 100vw, (max-width: 768px) 90vw, (max-width: 1024px) 80vw, 760px"
src="https://giselle.zeno.phd/blog/ipython-notebooks-on-a-remote-server/ipython_notebook_example_hu_b31c4dcd66933a36.webp"
width="493"
height="458"
loading="lazy" data-zoomable /&gt;&lt;/div&gt;
&lt;/div&gt;&lt;/figure&gt;
&lt;/p&gt;
&lt;p&gt;The IPython notebook with embedded rich text, code, mathematics and figures.
It aims to be an agile tool for both exploratory computation and data analysis, and provides a platform to support reproducible research, since all inputs and outputs may be stored in a one-to-one way in notebook documents.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id="setup-your-virtualenv"&gt;Setup your virtualenv&lt;/h2&gt;
&lt;p&gt;You can follow the instructions to setup a virtualenv
.&lt;/p&gt;
&lt;h3 id="install-ipython-notebook"&gt;Install iPython Notebook&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;Start your virtualenv&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;pip install ipython['notebook']&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="run-ipython-notebook"&gt;Run iPython Notebook&lt;/h3&gt;
&lt;p&gt;Run &lt;code&gt;ipython notebook --no-browser --port=54321&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: You can use any open port higher than 1024 and less than 65535&lt;/p&gt;
&lt;h2 id="forward-the-connection-locally"&gt;Forward the connection locally&lt;/h2&gt;
&lt;p&gt;On another terminal, run &lt;code&gt;ssh -L 54321:localhost:54321 user@server&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: Remember to change &lt;code&gt;user&lt;/code&gt;, &lt;code&gt;server&lt;/code&gt; and the &lt;em&gt;port&lt;/em&gt; to what you specified previously.&lt;/p&gt;
&lt;h2 id="accessing-your-ipython-notebook"&gt;Accessing your iPython Notebook&lt;/h2&gt;
&lt;p&gt;Open up your favorite browser and go to &lt;code&gt;http://localhost:54321&lt;/code&gt;&lt;/p&gt;</description></item><item><title>Testing with Pytest</title><link>https://giselle.zeno.phd/blog/testing-with-pytest/</link><pubDate>Wed, 20 Aug 2014 00:00:00 +0000</pubDate><guid>https://giselle.zeno.phd/blog/testing-with-pytest/</guid><description>&lt;h2 id="about-pytest"&gt;About pytest&lt;/h2&gt;
&lt;p&gt;From
:&lt;/p&gt;
&lt;blockquote class="border-l-4 border-neutral-300 dark:border-neutral-600 pl-4 italic text-neutral-600 dark:text-neutral-400 my-6"&gt;
&lt;ul&gt;
&lt;li&gt;a mature full-featured Python testing tool&lt;/li&gt;
&lt;li&gt;provides easy no-boilerplate testing&lt;/li&gt;
&lt;li&gt;scales from simple unit to complex functional testing&lt;/li&gt;
&lt;li&gt;integrated with other testing methods and tools&lt;/li&gt;
&lt;li&gt;extensive plugin and customization system&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;h2 id="installing-pytest"&gt;Installing pytest&lt;/h2&gt;
&lt;p&gt;If you have already created your &lt;code&gt;virtualenv&lt;/code&gt;, download the latest
package and run &lt;code&gt;pip install pytest-[version].tar.gz&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id="writing-your-tests"&gt;Writing your tests&lt;/h2&gt;
&lt;h3 id="basic-example"&gt;Basic example&lt;/h3&gt;
&lt;p&gt;This is the most basic example, adapted from the
:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;# content of test_sample.py
def func(x):
return x + 1
def test_func():
assert func(3) == 5
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You only need to prefix your test function with &lt;code&gt;test_&lt;/code&gt; so that Pytest can find it. A good practice is to use the name of the function you are testing after the prefix.&lt;/p&gt;
&lt;h3 id="mocking-modules-and-environments"&gt;Mocking modules and environments&lt;/h3&gt;
&lt;p&gt;From
:&lt;/p&gt;
&lt;blockquote class="border-l-4 border-neutral-300 dark:border-neutral-600 pl-4 italic text-neutral-600 dark:text-neutral-400 my-6"&gt;
&lt;p&gt;Sometimes tests need to invoke functionality which depends on global settings or which invokes code which cannot be easily tested such as network access. The monkeypatch function argument helps you to safely set/delete an attribute, dictionary item or environment variable or to modify sys.path for importing.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Monkeypatch is a module that helps you set the return values for other functions that your function depends on.&lt;/p&gt;
&lt;blockquote class="border-l-4 border-neutral-300 dark:border-neutral-600 pl-4 italic text-neutral-600 dark:text-neutral-400 my-6"&gt;
&lt;p&gt;If you want to pretend that os.expanduser returns a certain directory, you can use the monkeypatch.setattr() method to patch this function before calling into a function which uses it:&lt;/p&gt;
&lt;/blockquote&gt;
&lt;pre&gt;&lt;code&gt;# content of test_module.py
import os.path
def getssh(): # pseudo application code
return os.path.join(os.path.expanduser(&amp;quot;~admin&amp;quot;), '.ssh')
def test_mytest(monkeypatch):
def mockreturn(path):
return '/abc'
monkeypatch.setattr(os.path, 'expanduser', mockreturn)
x = getssh()
assert x == '/abc/.ssh'
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id="mock"&gt;Mock&lt;/h3&gt;
&lt;p&gt;Another useful module is
, which now comes with Unittest for Python 3.3 onward.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s mock a class, for example:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;my_mock = Mock()
my_mock.some_attribute = 5
my_mock.some_method = Mock()
my_mock.some_method.return_value = 10
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now, &lt;code&gt;my_mock.some_method()&lt;/code&gt; will return &lt;strong&gt;10&lt;/strong&gt;. Similarly, &lt;code&gt;my_mock.some_attribute&lt;/code&gt; will return &lt;strong&gt;3&lt;/strong&gt;.&lt;/p&gt;
&lt;h2 id="running-your-tests"&gt;Running your tests&lt;/h2&gt;
&lt;p&gt;To run your tests, you only need run the command from your &lt;code&gt;tests&lt;/code&gt; directory.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;py.test -v
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;em&gt;Note:&lt;/em&gt; Remember to install the package you want to test beforehand with &lt;code&gt;python setup.py install&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id="test-discovery"&gt;Test discovery&lt;/h3&gt;
&lt;p&gt;Pytest has a &amp;lsquo;discovery&amp;rsquo; feature to automatically find your tests within your code. This is how it works by default:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;collection starts from the initial command line arguments which may be directories, filenames or test ids.&lt;/li&gt;
&lt;li&gt;recurse into directories, unless they match &lt;code&gt;norecursedirs&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;test_*.py&lt;/code&gt; or &lt;code&gt;*_test.py&lt;/code&gt; files, imported by their &lt;code&gt;package name&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Test&lt;/code&gt; prefixed test classes (without an &lt;code&gt;__init__&lt;/code&gt; method)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;test_&lt;/code&gt; prefixed test functions or methods are test items&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;em&gt;Note:&lt;/em&gt; If you run them from your package directory, and you have your &lt;code&gt;virtualenv&lt;/code&gt; directory in there, then &lt;code&gt;pytest&lt;/code&gt; will find the tests for the packages installed and run them.&lt;/p&gt;
&lt;h2 id="verifying-test-coverage"&gt;Verifying test coverage&lt;/h2&gt;
&lt;p&gt;Pytest has a plugin called
for coverage reporting of your tests. You can install this package using &lt;code&gt;pip&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;For verifying centralized testing coverage in EC, we would run the following:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;py.test --cov package-path/ tests-path/
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;em&gt;Note:&lt;/em&gt; Pytest-cov depends on
and on
.&lt;/p&gt;
&lt;h2 id="further-reading"&gt;Further reading&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;/li&gt;
&lt;/ul&gt;</description></item><item><title>Sphinx for Python documentation</title><link>https://giselle.zeno.phd/blog/sphinx-for-python-documentation/</link><pubDate>Fri, 01 Aug 2014 00:00:00 +0000</pubDate><guid>https://giselle.zeno.phd/blog/sphinx-for-python-documentation/</guid><description>&lt;h2 id="what-is-sphinx"&gt;What is Sphinx?&lt;/h2&gt;
&lt;p&gt;From
:&lt;/p&gt;
&lt;blockquote class="border-l-4 border-neutral-300 dark:border-neutral-600 pl-4 italic text-neutral-600 dark:text-neutral-400 my-6"&gt;
&lt;p&gt;Sphinx is a tool that makes it easy to create intelligent and beautiful documentation, written by Georg Brandl and licensed under the BSD license.&lt;/p&gt;
&lt;p&gt;It was originally created for the new Python documentation, and it has excellent facilities for the documentation of Python projects, but C/C++ is already supported as well, and it is planned to add special support for other languages as well.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id="installing-sphinx"&gt;Installing Sphinx&lt;/h2&gt;
&lt;p&gt;You can install
with &lt;code&gt;pip&lt;/code&gt;. If your project uses additional Python packages, you will need those installed in the virtualenv too.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;pip install sphinx
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id="dependencies"&gt;Dependencies&lt;/h3&gt;
&lt;p&gt;Sphinx requires the following packages, so make sure to install them first:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="generating-documentation"&gt;Generating documentation&lt;/h2&gt;
&lt;h3 id="create-documentation-directory"&gt;Create documentation directory&lt;/h3&gt;
&lt;p&gt;Create a documentation directory within your project directory. This is where the source files for your documentation will be.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;mkdir docs
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; docs
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now, you will run a script called &lt;code&gt;sphinx-quickstart&lt;/code&gt; to do the setup.&lt;/p&gt;
&lt;p&gt;From the
:&lt;/p&gt;
&lt;blockquote class="border-l-4 border-neutral-300 dark:border-neutral-600 pl-4 italic text-neutral-600 dark:text-neutral-400 my-6"&gt;
&lt;p&gt;Sphinx comes with a script called &lt;code&gt;sphinx-quickstart&lt;/code&gt; that sets up a source directory and creates a default &lt;code&gt;conf.py&lt;/code&gt; with the most useful configuration values from a few questions it asks you.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The script will ask you some setup questions and you can leave the default answer by pressing &lt;code&gt;enter&lt;/code&gt;. However, for these questions you will change the answer:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;when it asks to &lt;strong&gt;separate the &lt;code&gt;source&lt;/code&gt; and &lt;code&gt;build&lt;/code&gt; directories&lt;/strong&gt;, type &lt;code&gt;y&lt;/code&gt; and press &lt;code&gt;enter&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;when it asks for &lt;strong&gt;the &lt;code&gt;autodoc&lt;/code&gt; extension&lt;/strong&gt;, type &lt;code&gt;y&lt;/code&gt; and press &lt;code&gt;enter&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Afterwards, you will notice that your directory structure is something like:&lt;/p&gt;
&lt;pre&gt;
myproject/
|-- README
|-- setup.py
|-- myvirtualenv/
|-- mypackage/
| |-- __init__.py
| `-- mymodule.py
`-- docs/
|-- MakeFile
|-- build/
`-- source/
&lt;/pre&gt;
&lt;h3 id="automatically-generating-documentation"&gt;Automatically generating documentation&lt;/h3&gt;
&lt;p&gt;With &lt;code&gt;autodoc&lt;/code&gt;, you can tell Sphinx to look at your docstrings and generate the documentation for your project.&lt;/p&gt;
&lt;p&gt;First, open the &lt;code&gt;docs/source/conf.py&lt;/code&gt; file to change the configuration. You need to uncomment the following line and add the relative path to where your code is.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sys.path.insert&lt;span class="o"&gt;(&lt;/span&gt;0, os.path.abspath&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;../..&amp;#39;&lt;/span&gt;&lt;span class="o"&gt;))&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now, you will run &lt;code&gt;sphinx-apidoc&lt;/code&gt; to automatically generate the &lt;code&gt;.rst&lt;/code&gt; files for your module documentation.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sphinx-apidoc -f -o source/ ../mypackage/
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The flags used in the previous command are the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;-f&lt;/code&gt; &amp;ndash; Normally, sphinx-apidoc does not overwrite any files. Use this option to force the overwrite of all files that it generates.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;-o outputdir&lt;/code&gt; &amp;ndash; Gives the directory in which to place the generated output.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you look now in your source directory, you will see new &lt;code&gt;.rst&lt;/code&gt; files for each of your modules in addition to the &lt;code&gt;index.rst&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;To generate the documentation, from your docs directory run this command:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;make html
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h4 id="using-docstrings-for-generating-documentation"&gt;Using docstrings for generating documentation&lt;/h4&gt;
&lt;p&gt;Example of docstring used for generating the documentation, from
.&lt;/p&gt;
&lt;p&gt;See
.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;public_fn_with_sphinxy_docstring&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="s2"&gt;&amp;#34;&amp;#34;&amp;#34;This function does something.
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s2"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s2"&gt; :param name: The name to use.
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s2"&gt; :type name: str.
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s2"&gt; :param state: Current state to be in.
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s2"&gt; :type state: bool.
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s2"&gt; :returns: int -- the return code.
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s2"&gt; :raises: AttributeError, KeyError
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s2"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s2"&gt; &amp;#34;&amp;#34;&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h4 id="plugins"&gt;Plugins&lt;/h4&gt;
&lt;p&gt;There are also a couple of IDEs that have plugins that support reStructuredText (ReST) and Sphinx.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;PyCharm does not have a Sphinx plugin, but it supports the ReST format for docstrings. Here&amp;rsquo;s the documentation on how to set that up:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id="writing-your-own-documentation"&gt;Writing your own documentation&lt;/h1&gt;
&lt;h2 id="creating-your-own-rest-rst-source-files"&gt;Creating your own ReST (.rst) source files&lt;/h2&gt;
&lt;p&gt;After using &lt;code&gt;sphinx-quickstart&lt;/code&gt; and &lt;code&gt;sphinx-autodoc&lt;/code&gt;, you will have a &lt;code&gt;source&lt;/code&gt; directory.&lt;/p&gt;
&lt;pre&gt;
myproject/
|-- README
|-- setup.py
|-- myvirtualenv/
|-- mypackage/
`-- docs/
|-- MakeFile
|-- build/
`-- source/ &lt;-- in this directory
|-- _static/
|-- _templates/
|-- index.rst
`-- (other .rst files auto-generated)
&lt;/pre&gt;
&lt;p&gt;You can create other files here for additional documentation. Once you have created them, then you can include them in the table of contents in &lt;code&gt;index.rst&lt;/code&gt;.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-rst" data-lang="rst"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="gh"&gt;Welcome to myproject&amp;#39;s documentation!&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="gh"&gt;====================================&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="err"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;..&lt;/span&gt; &lt;span class="ow"&gt;include&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt; intro.rst&lt;span class="err"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="err"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="gh"&gt;Contents&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="gh"&gt;--------&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;..&lt;/span&gt; &lt;span class="ow"&gt;toctree&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nc"&gt;:maxdepth:&lt;/span&gt; &lt;span class="nf"&gt;2&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; modules &lt;span class="err"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;You can include the contents of other .rst files in here with the command &lt;code&gt;.. include:: filename.rst&lt;/code&gt;. For the table of contents, you only have to add the filename of the the automatically generated &lt;code&gt;modules.rst&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id="restructuredtext-rest-syntax"&gt;reStructuredText (ReST) Syntax&lt;/h3&gt;
&lt;p&gt;If you need a reference to ReST syntax and markup for Sphinx,
that explains it very well.&lt;/p&gt;
&lt;h3 id="including-code-samples"&gt;Including code samples&lt;/h3&gt;
&lt;p&gt;To include code snippets in your ReST documentation, you could use something like:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-rst" data-lang="rst"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;..&lt;/span&gt; &lt;span class="ow"&gt;literalinclude&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt; path/to/my_script.py&lt;span class="err"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nc"&gt;:language:&lt;/span&gt; &lt;span class="nf"&gt;python&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nc"&gt;:lines:&lt;/span&gt; &lt;span class="nf"&gt;12-13&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nc"&gt;:emphasize-lines:&lt;/span&gt; &lt;span class="nf"&gt;2&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h1 id="hosting-in-github-pages"&gt;Hosting in github pages&lt;/h1&gt;
&lt;p&gt;If you are using Github for version control and hosting your code, you might be interested in using Github Pages to host and version control your html documentation as well.&lt;/p&gt;
&lt;h2 id="change-the-build-directory"&gt;Change the build directory&lt;/h2&gt;
&lt;h3 id="create-new-directory"&gt;Create new directory&lt;/h3&gt;
&lt;p&gt;First create a directory for the generated documentation next to the directory for your code.
Example:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;mkdir myproject-docs
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id="makefile-changes"&gt;Makefile changes&lt;/h3&gt;
&lt;p&gt;After setting up the docs directory for your documentation source files, you only need to do a few changes to the configuration to set it up for github pages. This part of the tutorial is based on this
.&lt;/p&gt;
&lt;p&gt;Open your &lt;code&gt;myproject/docs/Makefile&lt;/code&gt; for editing.&lt;/p&gt;
&lt;p&gt;First, change:&lt;/p&gt;
&lt;pre&gt;
BUILDDIR = build
&lt;/pre&gt;
&lt;p&gt;to:&lt;/p&gt;
&lt;pre&gt;
BUILDDIR = ../../myproject-docs
PDFBUILDDIR = /tmp
PDF = ../manual.pdf
&lt;/pre&gt;
&lt;p&gt;The first line points to the new directory we just created. Now, running &lt;code&gt;make html&lt;/code&gt; will create an html directory in there.&lt;/p&gt;
&lt;p&gt;We will need to make another change in the file. Change these lines:&lt;/p&gt;
&lt;pre&gt;
latexpdf:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo "Running LaTeX files through pdflatex..."
make -C $(BUILDDIR)/latex all-pdf
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
&lt;/pre&gt;
&lt;p&gt;To this:&lt;/p&gt;
&lt;pre&gt;
latexpdf:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(PDFBUILDDIR)/latex
@echo "Running LaTeX files through pdflatex..."
make -C $(PDFBUILDDIR)/latex all-pdf
cp $(PDFBUILDDIR)/latex/*.pdf $(PDF)
@echo "pdflatex finished; see $(PDF)"
&lt;/pre&gt;
&lt;p&gt;Now, the PDF temporary files will be in a tmp directory while it is being built. Afterwards, the resulting PDF will be copied to your main code repo.
To generate the files again, run make html.&lt;/p&gt;
&lt;h2 id="create-gh-pages-branch"&gt;Create gh-pages branch&lt;/h2&gt;
&lt;p&gt;First, make sure to commit the code, documentation source files, and the PDF generated from the documentation in your main branch.&lt;/p&gt;
&lt;p&gt;Next, change to the directory for your gh-pages repository; in this example, it would be &lt;code&gt;myproject-docs&lt;/code&gt;. We will commit this to a new branch gh-pages.
We will clone the repository and then create the branch.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; ../myproject-docs
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;git clone https://github.com/&lt;span class="o"&gt;[&lt;/span&gt;user&lt;span class="o"&gt;]&lt;/span&gt;/&lt;span class="o"&gt;[&lt;/span&gt;repository&lt;span class="o"&gt;]&lt;/span&gt;.git html
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; html
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;git branch gh-pages
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now, we need to do some cleanup to remove the files.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;git symbolic-ref HEAD refs/heads/gh-pages &lt;span class="c1"&gt;# auto-switches branches to gh-pages &lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;rm .git/index
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;git clean -fdx
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Check if we&amp;rsquo;re in the gh-pages branch.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;git branch
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Generate your documentation again with &lt;code&gt;make html&lt;/code&gt;. Afterwards, we&amp;rsquo;re going to add the files and commit them.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;git add .
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;git commit -m &lt;span class="s2"&gt;&amp;#34;Rebuilt docs&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;git push origin gh-pages
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id="add-a-nojekyll-file"&gt;Add a .nojekyll file&lt;/h3&gt;
&lt;p&gt;We need to add an empty file called &lt;code&gt;.nojekyll&lt;/code&gt; in our &lt;code&gt;html&lt;/code&gt; directory so that Github will render our html instead of looking for jekyll files to render.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;touch .nojekyll
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;git add .nojekyll
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;git commit -m &lt;span class="s2"&gt;&amp;#34;Added .nojekyll&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;git push origin gh-pages
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;To view your documentation, go to
&lt;/p&gt;
&lt;h2 id="directory-structure"&gt;Directory structure&lt;/h2&gt;
&lt;p&gt;You should now have a directory structure similar to this:&lt;/p&gt;
&lt;pre&gt;
myproject/
|-- README
|-- setup.py
|-- myvirtualenv/
|-- mypackage/
| |-- __init__.py
| `-- mymodule.py
`-- docs/
|-- MakeFile
|-- build/
`-- source/
myproject-docs/
|-- doctrees/ &lt;-- this directory is autogenerated, but not committed to gh-pages
`-- html/ &lt;-- everything *under* here is committed to the gh-pages branch
|-- .nojekyll
|-- index.html
|-- (more HTML files from sphinx-apidoc reST documents)
|-- _sources/
`-- _static/
&lt;/pre&gt;
&lt;h2 id="further-reading"&gt;Further reading&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;/li&gt;
&lt;/ul&gt;</description></item><item><title>Python virtual environments</title><link>https://giselle.zeno.phd/blog/python-virtual-environments/</link><pubDate>Sun, 01 Jun 2014 00:00:00 +0000</pubDate><guid>https://giselle.zeno.phd/blog/python-virtual-environments/</guid><description>&lt;h2 id="what-is-virtualenv"&gt;What is virtualenv?&lt;/h2&gt;
&lt;p&gt;From the Python Guide:&lt;/p&gt;
&lt;blockquote class="border-l-4 border-neutral-300 dark:border-neutral-600 pl-4 italic text-neutral-600 dark:text-neutral-400 my-6"&gt;
&lt;p&gt;A Virtual Environment, put simply, is an isolated working copy of Python which allows you to work on a specific project without worry of affecting other projects.&lt;/p&gt;
&lt;p&gt;For example, you can work on a project which requires Django 1.3 while also maintaining a project which requires Django 1.0.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id="what-is-pip"&gt;What is pip?&lt;/h2&gt;
&lt;p&gt;Pip is a package manager system for installing and managing Python packages.&lt;/p&gt;
&lt;h2 id="getting-virtualenv"&gt;Getting virtualenv##&lt;/h2&gt;
&lt;p&gt;If you already have &lt;code&gt;pip&lt;/code&gt;, then you can install virtualenv like so:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;pip install virtualenv
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Virtualenv includes pip, so all we need is to get virtualenv.&lt;/p&gt;
&lt;p&gt;If you need an alternate way of installing it, refer to the
.&lt;/p&gt;
&lt;h2 id="creating-the-virtualenv"&gt;Creating the virtualenv&lt;/h2&gt;
&lt;p&gt;Usually, you will want to have a virtual environment per project. So first, lets create a directory for the project and change directories to it.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;mkdir my_project
cd my_project
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now, we will create the virtual environment. If you want to use your current python version, then you only need to run the following command.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;virtualenv my_venv
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If you would like to use a different Python version for your virtual environment, then you only have to add an argument &lt;code&gt;-p&lt;/code&gt; to specify the location of the Python version you want to use.&lt;/p&gt;
&lt;h2 id="using-the-virtualenv"&gt;Using the virtualenv&lt;/h2&gt;
&lt;p&gt;To use your virtual environment, you need to activate it first:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;source my_venv/bin/activate
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To exit the virtual environment, just type:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;deactivate
&lt;/code&gt;&lt;/pre&gt;
&lt;h1 id="installing-python-packages-in-virtualenv"&gt;Installing Python packages in virtualenv&lt;/h1&gt;
&lt;p&gt;Another reason for using virtualenv, besides having different Python versions for your projects, is that you can have different Python packages in separate environments. It makes it easier to manage multiple projects. :)&lt;/p&gt;
&lt;h2 id="installing-packages-example"&gt;Installing packages example&lt;/h2&gt;
&lt;p&gt;Let&amp;rsquo;s use the
package as an example of how to install packages in a virtual environment. Flask has the following (nested) requirements:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;code&gt;pip&lt;/code&gt; will automatically donwload and install ay package dependencies for you, if you have internet access.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;pip install Flask
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id="no-internet"&gt;No internet?&lt;/h2&gt;
&lt;h3 id="create-a-repository"&gt;Create a repository&lt;/h3&gt;
&lt;p&gt;If you don&amp;rsquo;t have access to the internet from the server, then you will need to download the packages and their dependencies to install them manually. You can create a directory to store the package archives in and save them for future installations.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;mkdir repo
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id="getting-package-sources"&gt;Getting package sources&lt;/h3&gt;
&lt;p&gt;You can look for Python package sources in the
using the search or browse functionalities.&lt;/p&gt;
&lt;h2 id="uninstalling-packages"&gt;Uninstalling packages&lt;/h2&gt;
&lt;p&gt;Uninstalling packages using &lt;code&gt;pip&lt;/code&gt; is very straightforward. For example, if we were to uninstall Flask, we would do:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;pip uninstall Flask
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id="getting-a-list-of-requirements"&gt;Getting a list of requirements&lt;/h2&gt;
&lt;p&gt;If you would like to know what Python packages you have installed in your virtual environment, then you can run the following command:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;pip list
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This will give you a list of the installed packages, like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;distribute (0.6.34)
Flask (0.10.1)
itsdangerous (0.24)
Jinja2 (2.7.2)
MarkupSafe (0.21)
Werkzeug (0.9.4)
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id="exporting-requirements"&gt;Exporting requirements&lt;/h2&gt;
&lt;p&gt;Using pip we can export a list of requirements (installed packages) for our Python environment.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;pip freeze &amp;gt; requirements.txt
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;From our example, this creates a file with the following list of requirements:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Flask==0.10.1
Jinja2==2.7.2
MarkupSafe==0.21
Werkzeug==0.9.4
distribute==0.6.34
itsdangerous==0.24
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id="importing-requirements"&gt;Importing requirements&lt;/h2&gt;
&lt;p&gt;We can also use the requirements list to import the packages we want to install and specify a local directory to look for the packages.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;pip install -r requirements.txt --no-index --find-links=[file://]&amp;lt;DIR&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The &lt;code&gt;--no-index&lt;/code&gt; flag is for ignoring the package index and looking only at &lt;code&gt;--find-links&lt;/code&gt; URLs or directories.&lt;/p&gt;
&lt;h2 id="further-reading"&gt;Further reading&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;/li&gt;
&lt;/ul&gt;</description></item><item><title>Getting started with a Django app</title><link>https://giselle.zeno.phd/blog/getting-started-with-a-django-app/</link><pubDate>Fri, 30 Aug 2013 00:00:00 +0000</pubDate><guid>https://giselle.zeno.phd/blog/getting-started-with-a-django-app/</guid><description>&lt;h2 id="create-an-app"&gt;Create an app&lt;/h2&gt;
&lt;p&gt;In the directory for your Django project, run the following command &lt;code&gt;python manage.py startapp my_app&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;This will create a directory that looks like this&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;my_app&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="fm"&gt;__init__&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;py&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;py&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;tests&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;py&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;views&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;py&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id="create-your-models"&gt;Create your models&lt;/h2&gt;
&lt;p&gt;Edit the &lt;strong&gt;my_app/models.py&lt;/strong&gt; file to add your models there.&lt;/p&gt;
&lt;p&gt;You can see quick examples of how to make your modes
.&lt;/p&gt;
&lt;p&gt;If you are having trouble finding the field types in the documentation, I know I did, take a look
.&lt;/p&gt;</description></item><item><title>My Django project setup</title><link>https://giselle.zeno.phd/blog/my-django-project-setup/</link><pubDate>Fri, 30 Aug 2013 00:00:00 +0000</pubDate><guid>https://giselle.zeno.phd/blog/my-django-project-setup/</guid><description>&lt;p&gt;This is a continuation of the series of posts on my workflow with Django. I am writing as a means of documenting my work, but feel free to follow it you find it helpful.&lt;/p&gt;
&lt;p&gt;This is loosely based on the Django tutorial from
. This tutorial uses the 1.5 version of Django.&lt;/p&gt;
&lt;h2 id="project-setup"&gt;Project setup&lt;/h2&gt;
&lt;p&gt;Let&amp;rsquo;s set up a Django project!&lt;/p&gt;
&lt;h3 id="creating-a-project"&gt;Creating a project&lt;/h3&gt;
&lt;p&gt;To create a project, use the following command &lt;code&gt;django-admin.py startproject myproject&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;This will create a starter project with the following structure:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;myproject/
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; manage.py
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; myproject/
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; __init__.py
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; settings.py
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; urls.py
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; wsgi.py
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id="database-settings"&gt;Database settings&lt;/h3&gt;
&lt;p&gt;Now, if you change to the directory that contains the &lt;strong&gt;settings.py&lt;/strong&gt; file, you can change your projects settings. Here you can specify the database engine you will be using (SQLite, PostgreSQL or MySQL) and enter the database credentials (if applicable).&lt;/p&gt;
&lt;p&gt;The following is an excerpt of &lt;strong&gt;settings.py&lt;/strong&gt;:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;DATABASES&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="s2"&gt;&amp;#34;default&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="s2"&gt;&amp;#34;ENGINE&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;django.db.backends.postgresql_psycopg2&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;# Add &amp;#34;postgresql_psycopg2&amp;#34;, &amp;#34;mysql&amp;#34;, &amp;#34;sqlite3&amp;#34; or &amp;#34;oracle&amp;#34;.&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="s2"&gt;&amp;#34;NAME&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;MY_DATABASE_NAME&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;# Or path to database file if using sqlite3.&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="c1"&gt;# The following settings are not used with sqlite3:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="s2"&gt;&amp;#34;USER&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;MY_DATABASE_USER&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="s2"&gt;&amp;#34;PASSWORD&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;MY_DATABASE_PASSWORD&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="s2"&gt;&amp;#34;HOST&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;# Empty for localhost through domain sockets or &amp;#34;127.0.0.1&amp;#34; for localhost through TCP.&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="s2"&gt;&amp;#34;PORT&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;# Set to empty string for default.&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;I changed the engine to be &lt;code&gt;django.db.backends.postgresql_psycopg2&lt;/code&gt; as I will be using PostgreSQL. I already created the database so I added the database name, user, and password also.&lt;/p&gt;
&lt;p&gt;If you are going to be using any other database or need more information, refer to the Django
.&lt;/p&gt;
&lt;h3 id="sync-database"&gt;Sync database&lt;/h3&gt;
&lt;p&gt;To sync the database to create the database tables, use this command &lt;code&gt;python manage.py syncdb&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;This will create the database tables for the installed apps that you have enabled in your &lt;strong&gt;settings.py&lt;/strong&gt; file.&lt;/p&gt;
&lt;h3 id="get-to-work"&gt;Get to work!&lt;/h3&gt;
&lt;p&gt;The project is now set up. You can continue now by creating an app.&lt;/p&gt;</description></item><item><title>My Django development setup</title><link>https://giselle.zeno.phd/blog/my-django-development-setup/</link><pubDate>Thu, 29 Aug 2013 00:00:00 +0000</pubDate><guid>https://giselle.zeno.phd/blog/my-django-development-setup/</guid><description>&lt;h2 id="part-1---installing-software"&gt;Part 1 - Installing software&lt;/h2&gt;
&lt;p&gt;For this part, I loosely followed this guide on
.&lt;/p&gt;
&lt;h3 id="install-pip"&gt;Install pip&lt;/h3&gt;
&lt;p&gt;I already had pip installed. However, if I were to install it, I would need: &lt;code&gt;sudo easy_install pip&lt;/code&gt;&lt;/p&gt;
&lt;h3 id="install-virtualenv"&gt;Install virtualenv&lt;/h3&gt;
&lt;p&gt;I installed virtualenv with this command: &lt;code&gt;sudo pip install virtualenv&lt;/code&gt;&lt;/p&gt;
&lt;h3 id="install-virtualenvwrapper"&gt;Install virtualenvwrapper&lt;/h3&gt;
&lt;p&gt;Next, I installed virtualenvwrapper as so: &lt;code&gt;sudo pip install virtualenvwrapper&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Then, I had to go to my home directory &lt;code&gt;cd $HOME&lt;/code&gt; and create a directory for the virtualenvs &lt;code&gt;mkdir .virtualenvs&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;For my shell to load the virtualenvwrapper script, I needed to add this to my bash file. So, I opened my bash profile file &lt;code&gt;nano .bash_profile&lt;/code&gt; and added this line &lt;code&gt;source /usr/local/bin/virtualenvwrapper.sh&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;To verify the installation, I reinitiated the terminal and typed &lt;code&gt;mkv&lt;/code&gt; and hit Tab. It should autocomplete to &lt;code&gt;mkvirtualenv&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id="part-2---setting-up-environment"&gt;Part 2 - Setting up environment&lt;/h2&gt;
&lt;p&gt;For this part, I loosely followed this guide on
.&lt;/p&gt;
&lt;h3 id="export-current-environment-requirements"&gt;Export current environment requirements&lt;/h3&gt;
&lt;p&gt;I already had installed dependencies via pip, so to export them I ran the following command &lt;code&gt;pip freeze &amp;gt; requirements.txt&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id="create-a-virtualenv"&gt;Create a virtualenv&lt;/h3&gt;
&lt;p&gt;Next, I created my virtualenv &lt;em&gt;from my project directory&lt;/em&gt; with the dependencies I exported &lt;code&gt;mkvirtualenv my_virtual_env -a `pwd` -r requirements.txt&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id="installing-django-in-the-virtualenv"&gt;Installing Django in the virtualenv&lt;/h3&gt;
&lt;p&gt;Since I am now working in a virtualenv, I have to install Django in here &lt;code&gt;sudo pip install Django&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id="part-3---begin-django-project"&gt;Part 3 - Begin Django project&lt;/h2&gt;
&lt;p&gt;Now, I&amp;rsquo;m ready to start my Django project!&lt;/p&gt;
&lt;p&gt;It is recommended to have a virtualenv per Django project since the dependencies may defer. You could also have multiple virtualenvs for a project if you need different Python versions, for example.&lt;/p&gt;</description></item></channel></rss>