=======================
Using package managers
=======================

.. contents::
   :local:
   :depth: 1


Repository supports two package managers,
`conda <http://conda.pydata.org/>`_ and
`PyPI <https://pypi.org/>`_. To work with conda or PyPI packages,
you must use their corresponding subdomains.

EXAMPLE: To install conda packages from the user "travis," use
the Repository URL::

  https://conda.<your-anaconda-repo>/travis

EXAMPLE: To install PyPI packages from the user "travis," use the
Repository URL::

  https://pypi.<your-anaconda-repo>/travis


.. _repo-conda-packages:

Working with conda packages
===========================

.. _repo-build-conda-packages:

Building a conda package
-------------------------

To build a package using ``conda build``:

#. Install Anaconda Client and conda build::

    conda install anaconda-client conda-build

#. Choose the repository for which you would like to build the
   package. In this example, we use a simple, public `conda test
   package <https://github.com/anaconda-platform/anaconda-client/
   tree/develop/example-packages/conda>`_::

     git clone https://github.com/anaconda-platform/anaconda-client
     cd anaconda-client/example-packages/conda/



   In this directory, there are two required files,
   `build.sh <https://github.com/anaconda-platform/anaconda-client/
   blob/develop/example-packages/conda/build.sh>`_, and
   `meta.yaml <https://github.com/anaconda-platform/anaconda-client/
   blob/develop/example-packages/conda/meta.yaml>`_.

   NOTE: Linux and macOS systems are Unix systems. Packages built
   for Unix systems require a ``build.sh`` file, packages built
   for Windows require a ``bld.bat`` file, and packages built for
   both Unix and Windows systems require both a ``build.sh`` file
   and a ``bld.bat`` file. All packages require a ``meta.yaml``
   file.

#. To build the package, turn off automatic Client uploading
   and then run the ``conda build`` command::

    conda config --set anaconda_upload no
    conda build .

   All packages built in this way are placed in a subdirectory of
   :doc:`Anaconda's </anaconda/index>` ``conda-bld`` directory.

#. You can check where the resulting file was placed with the
   ``--output`` option::

    conda build . --output

For more information on conda's overall build framework, you may
also want to read the articles `Building conda
packages <http://conda.pydata.org/docs/building/bpp.html>`_
and `Tutorials on conda build
<http://conda.pydata.org/docs/build_tutorials.html>`_.

.. _repo-uploading-conda-packages:

Uploading a conda package
--------------------------

Upload the test package to Repository with the :ref:`anaconda
upload <cli-upload>` command::

    anaconda login
    anaconda upload /path/to/conda-package.tar.bz2

NOTE: Replace ``/path/to/`` with the path to where you
stored the package.

Installing conda packages
-------------------------

You can install conda packages from Repository by adding channels to
your conda configuration.

#. Because conda knows how to interact with Repository, specifying
   the channel "sean" translates to
   ``https://<your-anaconda-repo>/sean``::

     conda config --add channels sean

#. You can now install public conda packages from Sean's Repository
   account. Try installing the testci package at
   ``https://<your-anaconda-repo>/sean/testci``::

     conda install testci

You can also install a package from a channel with a token and a label::

      conda install -c https://conda.anaconda.org/t/<token>/<channel>/label/<labelname> <package>

NOTE: Replace ``<token>`` with the provided token,``<channel>`` with the user
channel, ``<labelname>`` with the label name and ``<package>`` with the package
name you want to install.

.. _repo-pypi-packages:


Working with PyPI packages
==========================

.. _repo-uploading-pypi-packages:

Uploading PyPI packages
-----------------------

You can test PyPI package uploading with a small, public example
package saved in the `anaconda-client repository
<https://github.com/anaconda-platform/anaconda-client/tree/
develop/example-packages/pypi>`_:

#. Begin by cloning the repository from the command line::

     git clone git@github.com:anaconda-platform/anaconda-client.git
     cd anaconda-client/example-packages/pypi/



#. You can now create your PyPI package with the ``setup.py`` script::

     python setup.py sdist

#. Your package now is built as a source "tarball" and is ready
   to be uploaded with::

     anaconda upload dist/*.tar.gz

Your package is now available at::

  http://<your-anaconda-repo>/USERNAME/PACKAGE

NOTE: Replace ``<your-anaconda-repo>`` with the name of your
local Repository, ``USERNAME`` with your username and ``PACKAGE``
with the package name.

Installing PyPI packages
------------------------


The best way to install a PyPI package is using pip. For the
following command, you can use the package you authored in the
above steps::

  pip install --extra-index-url https://pypi.<your-anaconda-repo>/USERNAME/PACKAGE



NOTE: Replace ``<your-anaconda-repo>`` with the name of your local
Repository, ``USERNAME`` with your username and
``PACKAGE`` with the test-package name.
