{"id":1799,"date":"2019-05-07T16:24:02","date_gmt":"2019-05-07T14:24:02","guid":{"rendered":"https:\/\/iww.inria.fr\/sed-sophia\/?p=1799"},"modified":"2019-05-07T16:24:02","modified_gmt":"2019-05-07T14:24:02","slug":"a-hello-world-python-repository","status":"publish","type":"post","link":"https:\/\/iww.inria.fr\/sed-sophia\/a-hello-world-python-repository\/","title":{"rendered":"A Hello World Python Repository"},"content":{"rendered":"<p><\/p>\n<h1>python-hello_world<\/h1>\n<p>This <a href=\"https:\/\/gitlab.inria.fr\/dream\/python-hello_world\">repository<\/a> contains an example of a minimal Python package.<br \/>\nThe <code>setup.py<\/code> file is central, it uses setuptools to package the python code.<br \/>\nIn the following we consider that a Conda environment has been created and activated.<br \/>\nYou can for instance use the development environment described in the <code>conda\/environment.yaml<\/code> file.<br \/>\nTo do so, type the following command line<\/p>\n<pre><code class=\"language-console\">conda env create -f conda\/environment.yaml<\/code><\/pre>\n<p>To create a Python package that can be used in this environment, three options are possible:<\/p>\n<ol>\n<li>A develop mode.<br \/>\nUsing this mode, all local modifications of source code will be considered in your Python interpreter (when restarted) without any post-installation.<br \/>\nThis is particularly useful when adding new features.<br \/>\nTo install this package in develop mode, type the following command line<\/li>\n<\/ol>\n<pre><code class=\"language-console\">python setup.py develop --prefix=${CONDA_PREFIX}<\/code><\/pre>\n<p>Once this step is done, type the following command line for running tests<\/p>\n<pre><code class=\"language-console\">nosetests test -x -s -v<\/code><\/pre>\n<p>Note that this require to have installed <code>nose<\/code> in your environment.<\/p>\n<ol>\n<li>An install mode.<br \/>\nUsing this mode, all local modifications of source code will <strong>NOT<\/strong> be considered in your Python interpreter (when restarted).<br \/>\nTo consider your local modifications of source code, you must install the package once again.<br \/>\nThis is particularly useful when you want to install a stable version in one Conda environment while creating another environment for using the develop mode.<br \/>\nTo install this package in develop mode, type the following command line<\/li>\n<\/ol>\n<pre><code class=\"language-console\">python setup.py install --prefix=${CONDA_PREFIX}<\/code><\/pre>\n<ol>\n<li>A release mode.<br \/>\nUsing the mode, a Conda package will be created from the install mode and can be distributed with Conda.<br \/>\nTo build this package with Conda (with <code>conda-build<\/code> installed), type the following command line<\/li>\n<\/ol>\n<pre><code class=\"language-console\">conda build conda\/recipe -c defaults --override-channels<\/code><\/pre>\n<p>Then, you can upload the generated package or just install it.<br \/>\nTo install this conda package, type the following command line<\/p>\n<pre><code class=\"language-console\">conda install python-hello_world -c local -c defaults --override-channels<\/code><\/pre>\n<p>With the previous modes, the Conda environment doesn&#8217;t know that this python package has been installed.<br \/>\nBut with this method, the <code>python-hello_world<\/code> will appear in your Conda package listing.<\/p>\n<p>Once the package is installed, it can be used from the Python interpreter with namespaces defined by your directories containing <code>__init__.py<\/code> files.<br \/>\nHere, we can print the <code>\"Hello World\"<\/code> message using the following commands in the Python interpreter<\/p>\n<pre><code class=\"language-python\">import hello_world\n\nhello_world.func()<\/code><\/pre>\n<p>Moreover, in the <code>hello_world\/cli.py<\/code> we use the <code>argparse<\/code> Python module to define command line tools declared both in the <code>setup.py<\/code> and the <code>meta.yaml<\/code> of the Conda recipe (entry points).<br \/>\nSo whatever the mode chosen, to display this message you could also type in your terminal<\/p>\n<pre><code class=\"language-console\">hello_world<\/code><\/pre>\n<p><\/p>","protected":false},"excerpt":{"rendered":"<p>python-hello_world This repository contains an example of a minimal Python package. The setup.py file is central, it uses setuptools to package the python code. In the following we consider that a Conda environment has been created and activated. You can for instance use the development environment described in the conda\/environment.yaml\u2026<\/p>\n<p> <a class=\"continue-reading-link\" href=\"https:\/\/iww.inria.fr\/sed-sophia\/a-hello-world-python-repository\/\"><span>Continue reading<\/span><i class=\"crycon-right-dir\"><\/i><\/a> <\/p>\n","protected":false},"author":2253,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_members_access_role":[],"_members_access_error":""},"categories":[29,28],"tags":[117,61],"class_list":["post-1799","post","type-post","status-publish","format-standard","hentry","category-development-in-the-inria-teams","category-goodpractices","tag-conda","tag-python"],"_links":{"self":[{"href":"https:\/\/iww.inria.fr\/sed-sophia\/wp-json\/wp\/v2\/posts\/1799","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/iww.inria.fr\/sed-sophia\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/iww.inria.fr\/sed-sophia\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/iww.inria.fr\/sed-sophia\/wp-json\/wp\/v2\/users\/2253"}],"replies":[{"embeddable":true,"href":"https:\/\/iww.inria.fr\/sed-sophia\/wp-json\/wp\/v2\/comments?post=1799"}],"version-history":[{"count":7,"href":"https:\/\/iww.inria.fr\/sed-sophia\/wp-json\/wp\/v2\/posts\/1799\/revisions"}],"predecessor-version":[{"id":1806,"href":"https:\/\/iww.inria.fr\/sed-sophia\/wp-json\/wp\/v2\/posts\/1799\/revisions\/1806"}],"wp:attachment":[{"href":"https:\/\/iww.inria.fr\/sed-sophia\/wp-json\/wp\/v2\/media?parent=1799"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/iww.inria.fr\/sed-sophia\/wp-json\/wp\/v2\/categories?post=1799"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/iww.inria.fr\/sed-sophia\/wp-json\/wp\/v2\/tags?post=1799"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}