-
Notifications
You must be signed in to change notification settings - Fork 3
Create a Conda Package from a GitHub directory
A Conda package is a software package uploaded onto Anaconda Cloud. It is readily for the Conda users to download and install via a simple conda install
command. In this tutorial, we assume you have written a python package and uploaded it onto Github. Following the below instructions, you can create a Conda package and upload it to Anaconda Cloud. We will use the package TreeShrink as an example.
First, you need to download Anaconda and follow the instructions to install it.
On your local machine, create a directory for your package
mkdir treeshrink
Change to the created directory. Now you need to create 3 files for your package: meta.yaml, build.sh, and bld.bat.
The file meta.yaml contains the meta data of your package. As an example, the meta.yaml for the package TreeShrink is as follow:
package:
name: treeshrink
version: 1.3.1
source:
git_rev: master
requirements:
host:
- python
- setuptools
run:
- python
test:
imports:
- treeshrink
about:
license: GNU GENERAL PUBLIC LICENSE
license_file: LICENSE
Besides meta.yaml, 2 files are required for a build:
- build.sh - Shell script for macOS and Linux.
- bld.bat - Batch file for Windows.
These two files must be placed at the same directory as meta.yaml. The files contain the commands needed to install the package in the corresponding architecture. We will walk through the creation of these files for TreeShrink as a demonstration. As TreeShrink uses setuptools and it has the setup.py file included in the Github repository, one command needed to build TreeShrink is calling python to run setup.py. In addition, since TreeShrink uses the R package BMS, we must also include a command to build this package. As such, the build.sh for TreeShrink should be
R CMD INSTALL -l Rlib dependencies/BMS_0.3.3.tar.gz
$PYTHON setup.py install --single-version-externally-managed --record=record.txt # Python command to install the script.
Similarly, bld.bat for TreeShrink should contain the following two commands
R CMD INSTALL -l Rlib dependencies\BMS_0.3.3.tar.gz
if errorlevel 1 exit 1
"%PYTHON%" setup.py install --single-version-externally-managed --record=record.txt
if errorlevel 1 exit 1
Use conda-build to build the package
conda-build treeshrink
When conda build is finished, it displays the package filename and location.
To install the package to your local machine, type
conda install --use-local treeshrink