Skip to content

Commit 275e5c3

Browse files
authored
Conda package (#113)
Add conda recipe and add/update CI jobs to build conda package artifacts
1 parent 066a4e1 commit 275e5c3

File tree

12 files changed

+225
-2
lines changed

12 files changed

+225
-2
lines changed

.circleci/config.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ workflows:
2121
requires:
2222
- test-node-v6
2323
- test-node-v8
24+
- conda-build-package:
25+
requires:
26+
- test-node-v6
27+
- test-node-v8
2428

2529
version: 2
2630
jobs:
@@ -156,3 +160,34 @@ jobs:
156160
- run: mv release/orca* artifacts
157161
- store_artifacts:
158162
path: artifacts
163+
164+
conda-build-package:
165+
docker:
166+
- image: circleci/node:8.11.1-browsers
167+
steps:
168+
- restore_cache:
169+
key: v1-source-{{ .Branch }}-{{ .Revision }}
170+
keys:
171+
- v1-source-{{ .Branch }}-
172+
- v1-source-
173+
- checkout
174+
- save_cache:
175+
key: v1-source-{{ .Branch }}-{{ .Revision }}
176+
paths:
177+
- ".git"
178+
- restore_cache:
179+
key: v3-npm-{{ checksum "package-lock.json" }}
180+
keys:
181+
- v3-npm-
182+
183+
- run: wget http://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh
184+
- run: chmod +x miniconda.sh
185+
- run: ./miniconda.sh -b -p $HOME/miniconda
186+
- run: $HOME/miniconda/bin/conda install --yes conda-build
187+
- run: $HOME/miniconda/bin/conda build recipe/
188+
- run: ls $HOME/miniconda/conda-bld/linux-64
189+
- run: mkdir artifacts
190+
- run: cp -r $HOME/miniconda/conda-bld/linux-64 ./linux-64
191+
- run: zip -r artifacts/conda-linux-64.zip ./linux-64
192+
- store_artifacts:
193+
path: artifacts

.travis.yml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,36 @@ cache:
1414
- $HOME/.cache/electron
1515
- $HOME/.cache/electron-builder
1616

17+
before_install:
18+
# Conda config based on
19+
# https://github.com/astrofrog/example-travis-conda/blob/master/.travis.yml
20+
#
21+
# Here we just install Miniconda, which you shouldn't have to change.
22+
- wget http://repo.continuum.io/miniconda/Miniconda3-latest-MacOSX-x86_64.sh -O miniconda.sh
23+
- chmod +x miniconda.sh
24+
- ./miniconda.sh -b -p $HOME/miniconda
25+
- $HOME/miniconda/bin/conda install --yes conda-build
26+
1727
install:
1828
- npm install
1929

2030
script:
2131
- npm run pack
2232
- ls release/
2333
- zip mac-release.zip release/orca* --junk-paths
34+
- $HOME/miniconda/bin/conda build recipe/
35+
- ls $HOME/miniconda/conda-bld/osx-64
36+
- cp -r $HOME/miniconda/conda-bld/osx-64 ./osx-64
37+
- zip -r conda-osx-64.zip ./osx-64
2438

2539
before_cache:
2640
- rm -rf $HOME/.cache/electron-builder/wine
2741

2842
addons:
2943
artifacts:
3044
s3_region: us-east-1
31-
paths: mac-release.zip
45+
paths:
46+
- mac-release.zip
47+
- conda-osx-64.zip
48+
3249
debug: true

CONTRIBUTING.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,19 @@ automate this process somehow.
114114
+ Grab the Mac build automatically pushed to [Amazon S3](https://s3.console.aws.amazon.com/s3/buckets/image-exporter-travis-artifacts/plotly/orca/?region=us-east-1&tab=overview) from Travis.
115115
**N.B.** Select the latest build (largest number *note:* the folders are not necessarily sequential) -> release.zip
116116
- Run `npm publish`
117+
- Publish conda packages:
118+
+ Download the following artifacts as above:
119+
- `conda-linux-64.zip` (CircleCI)
120+
- `conda-win-64.zip` (AppVeyor)
121+
- `conda-osx-64.zip` (Travis)
122+
+ Unzip each artifact
123+
+ `conda-linux-64.zip` becomes `linux-64/plotly-orca-*.tar.bz2`
124+
+ `conda-win-64.zip` becomes `win-64/plotly-orca-*.tar.bz2`
125+
+ `conda-osx-64.zip` becomes `osx-64/plotly-orca-*.tar.bz2`
126+
+ From a conda environment with the `anaconda-client` package installed run `anaconda login`
127+
+ Enter the credentials for the plotly anaconda channel
128+
+ For each of the three `plotly-orca-*.tar.bz2` files listed above, run `anaconda upload /path/to/XX-64/plotly-orca-*.tar.bz2`
129+
+ Run `anaconda logout`
117130
- :beers:
118131

119132
## Overview

appveyor.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ version: 0.1.{build}
33
environment:
44
matrix:
55
- nodejs_version: 8
6+
MINICONDA: C:\Miniconda36-x64
67

78
platform:
89
- x64
@@ -16,19 +17,26 @@ cache:
1617

1718
init:
1819
- git config --global core.autocrlf input
20+
- "set PATH=%MINICONDA%;%MINICONDA%\\Scripts;%MINICONDA%\\Library\\bin;%PATH%"
21+
- conda install -y conda-build
1922

2023
install:
2124
- ps: Install-Product node $env:nodejs_version $env:platform
2225
- npm i
26+
- conda build recipe\
27+
- dir C:\Miniconda36-x64\conda-bld\win-64
2328

2429
build_script:
2530
- npm run pack
2631

2732
after_build:
2833
- 7z a release.zip release/latest.yml release/*.exe
34+
- 7z a conda-win-64.zip C:\Miniconda36-x64\conda-bld\win-64\
2935

3036
artifacts:
3137
- path: release.zip
3238
name: release
39+
- path: conda-win-64.zip
40+
name: conda_package
3341

3442
test: off

bin/orca.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
#!/bin/bash
2-
"/Applications/orca.app/Contents/MacOS/orca" "$@"
2+
exec "/Applications/orca.app/Contents/MacOS/orca" "$@"

recipe/README.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
Building the conda package
2+
==========================
3+
This directory contains the configuration files that are needed to build
4+
orca into a standalone conda package.
5+
6+
To build the conda package, first install
7+
[Anaconda](https://www.anaconda.com/download/#macos) or
8+
[Miniconda](https://conda.io/miniconda.html).
9+
10+
Next, use `conda` to install the `conda-build` package:
11+
12+
```bash
13+
$ conda install conda-build
14+
```
15+
16+
Finally, build the package from the root project directory:
17+
18+
```bash
19+
$ conda build recipe/
20+
```
21+
22+
The resulting package will be named `plotly-orca-*.tar.bz2`, and the build
23+
command will display the full path of the output location.
24+
25+
How it works
26+
------------
27+
Here's a quick tour of the build configuration. For more information see the
28+
official conda docs for
29+
[building packags](https://conda.io/docs/user-guide/tasks/build-packages/define-metadata.html).
30+
31+
### `meta.yaml` ###
32+
The `meta.yaml` file in this directory is the top-level configuration file for
33+
the conda package. Here we specify the package name (`package.name`) and
34+
version (`package.version`, more on the version logic below), along with the
35+
relative path to the orca source directory (`source.path`).
36+
37+
The build number (`build.number`) parameter should always start at 1 for
38+
each new version of orca. It should be incremented if it becomes necessary to
39+
publish multiple conda builds that correspond to the same orca version.
40+
41+
By default, conda-build does a lot of work to
42+
[make binary packages relocatable](https://conda.io/docs/user-guide/tasks/build-packages/make-relocatable.html).
43+
On Linux, this logic results in a gconf settings warning being raised each
44+
time orca is used, and it doens't seem to be necessary, so it has been
45+
disabled by setting the `build.binary_relocation` property to `False`.
46+
47+
Finally, the `requirements.build` section is used to specify that we need
48+
`nodejs` available during the package build process (but not at runtime).
49+
50+
## `build.sh` and `bld.bat`
51+
The `build.sh` and `bld.bat` files are scripts with special names that are
52+
recognized by conda-build. On Linux and OS X the `build.sh` script will be
53+
executed in a fresh conda environment that contains only the packages
54+
specified in the `requirements.build` section of `meta.yaml`
55+
(just `nodejs` in our case). Likewise, on Windows the `bld.bat` script is
56+
executed under the same conditions.
57+
58+
These build scripts all start off by running `npm install` and `npm run pack`
59+
to create the electron build of orca in the `release/` directory.
60+
61+
Then, for each OS, the directory of extracted build files is moved to a
62+
directory under the root of the environment
63+
(conda populates the `PREFIX` environment variable with this location).
64+
65+
Finally, an entry-point script named `orca` (`orca.cmd` on Windows) is placed
66+
somewhere in the environment that will end up on the user's `PATH`
67+
(`$PREFIX/bin` for Linux and OS X, and just `$PREFIX` for Windows). This
68+
script is responsible for passing command line arguments through to the `orca`
69+
executable that lives somewhere inside the directory of build files that was
70+
moved in the previous step.
71+
72+
## Package version and `load_setup_py_data()`
73+
The canonical version string for `orca` resides in `package.json`. In order to
74+
avoid having a separate copy of this string in `meta.yaml` we use the following
75+
approach:
76+
77+
conda build provides a built-in function called `load_setup_py_data` that can
78+
be used inside a `jinja2` template expression in `meta.yaml` to load all of
79+
the metadata associated with the project's `setup.py` file. Orca is not a
80+
Python library, but it order to take advantage of this function,
81+
a `setup.py` script has been added to the root project directory. The
82+
`setup.py` script is responsible for dynamically loading the version string
83+
from the `package.json` file.

recipe/bin/orca

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
if [[ "$OSTYPE" == "darwin"* ]]; then
3+
# Mac OSX
4+
exec /opt/anaconda1anaconda2anaconda3/lib/orca.app/Contents/MacOS/orca "$@"
5+
else
6+
# Assume linux
7+
exec /opt/anaconda1anaconda2anaconda3/lib/orca_app/orca "$@"
8+
fi

recipe/bin/orca.cmd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@echo off
2+
"/opt/anaconda1anaconda2anaconda3\orca_app\orca.exe" %*

recipe/bld.bat

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
call npm install
2+
call npm run pack
3+
move release\win-unpacked "%PREFIX%\orca_app"
4+
copy "%RECIPE_DIR%\bin\orca.cmd" "%PREFIX%\"

recipe/build.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/sh
2+
npm install
3+
npm run pack
4+
mkdir -p $PREFIX/lib
5+
6+
if [[ "$OSTYPE" == "darwin"* ]]; then
7+
# Mac OSX
8+
mv release/mac/orca.app $PREFIX/lib
9+
else
10+
# Assume Linux
11+
mv release/linux-unpacked/ $PREFIX/lib/orca_app
12+
fi
13+
14+
mkdir -p $PREFIX/bin
15+
ORCA_ENTRY=$PREFIX/bin/orca
16+
cp $RECIPE_DIR/bin/orca $ORCA_ENTRY
17+
chmod +x $ORCA_ENTRY

recipe/meta.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{% set data = load_setup_py_data() %}
2+
3+
package:
4+
name: plotly-orca
5+
version: {{ data.get('version') }}
6+
7+
source:
8+
path: ../
9+
10+
build:
11+
number: 1
12+
binary_relocation: False
13+
14+
requirements:
15+
build:
16+
- nodejs =8

setup.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from distutils.core import setup
2+
import json
3+
4+
# Rational
5+
# --------
6+
# This file only exists to help give conda-build access to the version in our
7+
# package.json file. conda-build has built-in support for loading meta-data
8+
# from setup.py through the load_setup_py_data() function. See
9+
# https://conda.io/docs/user-guide/tasks/build-packages/define-metadata.html#
10+
11+
with open('package.json') as f:
12+
package_json=json.load(f)
13+
14+
# Convert NPM-compatible semantic version (e.g. "1.0.1-rc.1")
15+
# to setup tools compatible version string (e.g. "1.0.1rc1")
16+
npm_version = package_json['version']
17+
ver_split = npm_version.split('-')
18+
py_version = ver_split[0] + ''.join(ver_split[1:]).replace('.', '')
19+
20+
setup(version=py_version)

0 commit comments

Comments
 (0)