Skip to content

Commit

Permalink
Merge pull request #281 from scenerygraphics/conda
Browse files Browse the repository at this point in the history
Conda packaging
  • Loading branch information
kephale committed Aug 14, 2020
2 parents 0244e95 + 3b4b156 commit 26ed007
Show file tree
Hide file tree
Showing 9 changed files with 521 additions and 26 deletions.
18 changes: 10 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ branches:
install: true
script:
#- ".travis/build.sh"
- "python .travis/ci.py"
- "python3 .travis/pre_ci.py"
# .travis/ci.py is now called from travis_build.sh, which is called by pre_ci.py ^^^
#- "conda activate scijava-conda; python3 .travis/ci.py"
cache:
directories:
- "~/.m2/repository"
Expand All @@ -18,13 +20,13 @@ env:
- secure: AhDAOBC/KNkU6JBh3wXNhs6ExY6WaqQEKxfZ15nTsiHy1ZuTTEkGy26lTx1GD+Cp19QpzaO6u9KxrE8jLPioTEd1424s+82LjBnoyM2oL8eir+lkEWnGkdLRxWG1q1coY124wXiklGRpfo5fLxuDvLMzq1QQAJ4CytryK3ODhfuIDCSy9sjZlyqLz9nnZ2pJKG/EqBq3/u1n4J+/TsBjoWFaKX/wMT+PsdBGjCCpsVD9Zun6LzV4hwXT6MRBG0gT8wEM1kMgjlDUpIGV7VO/h05wSttYqOwqRMNXvWo6A4T4IB2zMKnVqFRNIFKWX5E8XpgccP1h+PCt2hjsJkYHnK4oeIWfgvLU6hkaMg5VlhbxQ+LlcTqG4dOm9zyz3wShYG4OcwTe7OjCjoPxbnHnFS56LAGHXWsH/VkzwPBOqyzhr7Mo6EMQPKcNTTJnK6xmty/i8/2A/Q24bEvjwZJMQ6JZpU2jBX4RyWHRhnbIgEMjWR4EvLVID/SbfYiUBB9eks4WvcZ2T9jMXd9WEr2PBjAqaprZ7Z9+qmPkT5W8AnMK8yJC4X5nOcDTidwopE9YiHJlnlEAB+3fiNqqHikIpx2bnNZAYFTDaZmazIJuYPnUMCPjW0fMA3FNjXb0iXs4L2KnACZFpyFHDT8GOawKXkH7ej+g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NcvuxogFE3rj1N09yRdmuJJkODk0rLV+FSfKRrGuNPuwfJ9OVM+uKIL86kqvr6vuQ8in1jDMlHiq4pp0xnuaVWaXn/qjWKrVdtRdaB3Eehleha3cBJ5aHgcW5tvt3uMwGr7ULhhLKRFqo+Kx6y7PgPBQLViRrcn4wKG3MRGyOIeuxeXFKYMLdD1ffDlKznkC94Tby+ZMbG6KONJaOryewUNO/eEsQveq3ZHA4B8rnPbnpPzYmXeiNHkGBgahXoKoGze1waRXHJw1IYt3NG31zjjET+kc/0XdrWxFRxnjudpEcjWWwtXj/o=
#deploy:
# provider: releases
# api_key:
# secure: aiqqiUxuF4Sw7heg3DkflU6XDZ9iTvf8CTRvo7/UNJRREfh57umUXsay1BIapMAQsb29ZHAnDD4B2G/6YP1ODHhJR2l+P/w42oMWoPdmZY+cC34/JbIv5snA9eUjCtqvrRMpwlW+W52ZD8eCMGe05eMsodG3QZB4pdCE6blaOLHswq/bgpm9fb3E1XxEFHi2GHaygJvfJb1qvMB70NvD+I5mlbGoHuLsyqoTg7wQMc73dh9q9hSmsS8RIic8oY7mW6usxWJXA9P576F+ZwjTe34xMnqGfLaeoxP/WLXU/zzdPIvt+0hlCkgPBH1TJbGsGrwO0cJ3GG+cs/wf2sZd4x8VTzrihnVHejsdUTWtzJjRS+KRB5Bb/c7tpMm3nZ94N/n/U4sZNHPGL2nGq2RmWCloP4v2iMEYGAD7WXIHwYINI10skoB8N6RX0SIr09IStFu098vASHWrVIAjV2d64ZqgtOnQz+B6nCBHO6s5sNy4tetF3EQsDGF3b+1NugQFNXW+6lacDMutHuQBXoSDa9FT8v7w8nkUC32RXq4G0HRny2SxSAGzPjsRk8y0ZrXNKW6myGMnBVe8Tey4rja0gXndtXLSt9G24Vnfal9QdvGynmYSmb5tnEqXnn6DZnuAbuIFZzO8jtLrulmmPB02bItnOYhHa9m0nfIV7t0/wic=
# file: SciView_Fiji.zip
# on:
# repo: scenerygraphics/sciview
deploy:
provider: releases
api_key:
secure: aiqqiUxuF4Sw7heg3DkflU6XDZ9iTvf8CTRvo7/UNJRREfh57umUXsay1BIapMAQsb29ZHAnDD4B2G/6YP1ODHhJR2l+P/w42oMWoPdmZY+cC34/JbIv5snA9eUjCtqvrRMpwlW+W52ZD8eCMGe05eMsodG3QZB4pdCE6blaOLHswq/bgpm9fb3E1XxEFHi2GHaygJvfJb1qvMB70NvD+I5mlbGoHuLsyqoTg7wQMc73dh9q9hSmsS8RIic8oY7mW6usxWJXA9P576F+ZwjTe34xMnqGfLaeoxP/WLXU/zzdPIvt+0hlCkgPBH1TJbGsGrwO0cJ3GG+cs/wf2sZd4x8VTzrihnVHejsdUTWtzJjRS+KRB5Bb/c7tpMm3nZ94N/n/U4sZNHPGL2nGq2RmWCloP4v2iMEYGAD7WXIHwYINI10skoB8N6RX0SIr09IStFu098vASHWrVIAjV2d64ZqgtOnQz+B6nCBHO6s5sNy4tetF3EQsDGF3b+1NugQFNXW+6lacDMutHuQBXoSDa9FT8v7w8nkUC32RXq4G0HRny2SxSAGzPjsRk8y0ZrXNKW6myGMnBVe8Tey4rja0gXndtXLSt9G24Vnfal9QdvGynmYSmb5tnEqXnn6DZnuAbuIFZzO8jtLrulmmPB02bItnOYhHa9m0nfIV7t0/wic=
file: sciview-linux64
on:
repo: scenerygraphics/sciview
# branches:
# only:
# - master
32 changes: 25 additions & 7 deletions .travis/ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

release_properties_exists = os.path.exists('release.properties')

print('')
print('travis ci.py')
print('')
print('')
print('Repo: %s' % os.environ['TRAVIS_REPO_SLUG'])
Expand All @@ -34,12 +34,29 @@
print('Is Pull Request?: %s' % is_PR)
print('Commit: %s' % commit_message)

# Perform main build
print('Starting build')
subprocess.call(['curl', '-fsLO', 'https://raw.githubusercontent.com/scijava/scijava-scripts/master/travis-build.sh'])
build_var1 = os.environ['encrypted_eb7aa63bf7ac_key']
build_var2 = os.environ['encrypted_eb7aa63bf7ac_iv']
subprocess.call(['sh', 'travis-build.sh', build_var1, build_var2])
def package_conda():
subprocess.call(['sh', 'populate_fiji.sh'])
subprocess.call(['pyinstaller', '--onefile', '--add-data', 'Fiji.app/jars:jars', 'src/main/python/sciview.py'])

platform = subprocess.check_output(['uname', '-s']).decode('UTF-8')
arch = subprocess.check_output(['uname', '-m']).decode('UTF-8')

print(['platform, arch', platform, arch])

if 'Linux' in platform and 'x86_64' in arch:
exe_name = 'sciview-linux64'
elif 'Linux' in platform:
exe_name = 'sciview-linux32'
elif 'Darwin' in platform:
exe_name = 'sciview-macos'
elif 'MING' in platform:
exe_name = 'sciview-win32'
elif 'MSYS_NT' in platform:
exe_name = 'sciview-win32'

subprocess.call(['mv', 'dist/sciview', exe_name])

package_conda()

# Update sites
print('')
Expand All @@ -54,6 +71,7 @@

if ( branch == 'master' and not is_PR and travis_secure ) or \
( '[SV_IJ_DEPLOY_UNSTABLE]' in commit_message ):

print('Upload to SciView-Unstable')
subprocess.call(['sh', 'sciview_deploy_unstable.sh'])

Expand Down
66 changes: 66 additions & 0 deletions .travis/pre_ci.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@

import os
import subprocess

travis_secure = os.environ['TRAVIS_SECURE_ENV_VARS']
PR = os.environ['TRAVIS_PULL_REQUEST']
is_PR = ( PR != 'false' )

# If this is a PR we use the source branch name, and last commit message
if is_PR:
print('Fetching PR information')
branch = os.environ['TRAVIS_PULL_REQUEST_BRANCH']

import requests
import json
r = requests.get('https://api.github.com/repos/scenerygraphics/sciview/pulls/%d/commits' % int(PR))

if r.ok:
commits = json.loads(r.text or r.content)
commit_message = commits[-1]['commit']['message']
print('Commit message: %s' % commit_message)
else:
branch = os.environ['TRAVIS_BRANCH']
commit_message = os.environ['TRAVIS_COMMIT_MESSAGE']

release_properties_exists = os.path.exists('release.properties')

print('travis pre_ci.py')
print('')
print('')
print('Repo: %s' % os.environ['TRAVIS_REPO_SLUG'])
print('Branch: %s' % branch)
print('Release?: %s' % str(release_properties_exists))
print('Is Pull Request?: %s' % is_PR)
print('Commit: %s' % commit_message)

# Perform main build
print('Starting build')
# we now have our own version of travis-build.sh
#subprocess.call(['curl', '-fsLO', 'https://raw.githubusercontent.com/scijava/scijava-scripts/master/travis-build.sh'])
build_var1 = os.environ['encrypted_eb7aa63bf7ac_key']
build_var2 = os.environ['encrypted_eb7aa63bf7ac_iv']
subprocess.call(['bash', 'travis-build.sh', build_var1, build_var2])

# Setup conda environment
# def build_conda():
# from pathlib import Path
# home = str(Path.home())

# print('------ BUILD CONDA -----')

# script_name = 'Miniconda3-latest-Linux-x86_64.sh'
# miniconda_dir = '%s/miniconda' % home
# subprocess.call(['curl', '-fsLO', 'https://repo.continuum.io/miniconda/%s' % script_name])
# subprocess.call(['bash', script_name, '-b', '-p', miniconda_dir])
# subprocess.call(['source', '%s/etc/profile.d/conda.sh' % miniconda_dir])
# subprocess.call(['hash', '-r'])
# subprocess.call(['conda', 'config', '--set', 'always_yes', 'yes', '--set', 'changeps1', 'no'])
# subprocess.call(['conda', 'update', '-q', 'conda'])
# # Useful for debugging any issues with conda
# subprocess.call(['conda', 'info', '-a'])

# # Replace dep1 dep2 ... with your dependencies
# subprocess.call(['conda', 'env', 'create', '-f', 'environment.yml'])
# subprocess.call(['conda', 'activate', 'sciview'])
# build_conda()
116 changes: 116 additions & 0 deletions .travis/pre_ci.py~
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@

import os
import subprocess

travis_secure = os.environ['TRAVIS_SECURE_ENV_VARS']
PR = os.environ['TRAVIS_PULL_REQUEST']
is_PR = ( PR != 'false' )

# If this is a PR we use the source branch name, and last commit message
if is_PR:
print('Fetching PR information')
branch = os.environ['TRAVIS_PULL_REQUEST_BRANCH']

import requests
import json
r = requests.get('https://api.github.com/repos/scenerygraphics/sciview/pulls/%d/commits' % int(PR))

if r.ok:
commits = json.loads(r.text or r.content)
commit_message = commits[-1]['commit']['message']
print('Commit message: %s' % commit_message)
else:
branch = os.environ['TRAVIS_BRANCH']
commit_message = os.environ['TRAVIS_COMMIT_MESSAGE']

release_properties_exists = os.path.exists('release.properties')

print('')
print('')
print('')
print('Repo: %s' % os.environ['TRAVIS_REPO_SLUG'])
print('Branch: %s' % branch)
print('Release?: %s' % str(release_properties_exists))
print('Is Pull Request?: %s' % is_PR)
print('Commit: %s' % commit_message)

# Perform main build
print('Starting build')
# we now have our own version of travis-build.sh
#subprocess.call(['curl', '-fsLO', 'https://raw.githubusercontent.com/scijava/scijava-scripts/master/travis-build.sh'])
build_var1 = os.environ['encrypted_eb7aa63bf7ac_key']
build_var2 = os.environ['encrypted_eb7aa63bf7ac_iv']
subprocess.call(['sh', 'travis-build.sh', build_var1, build_var2])

# Setup conda environment
def build_conda():
from pathlib import Path
home = str(Path.home())

print('------ BUILD CONDA -----')

script_name = 'Miniconda3-latest-Linux-x86_64.sh'
miniconda_dir = '%s/miniconda' % home
subprocess.call(['curl', '-fsLO', 'https://repo.continuum.io/miniconda/%s' % script_name])
subprocess.call(['bash', script_name, '-b', '-p', miniconda_dir])
subprocess.call(['source', '%s/etc/profile.d/conda.sh' % miniconda_dir])
subprocess.call(['hash', '-r'])
subprocess.call(['conda', 'config', '--set', 'always_yes', 'yes', '--set', 'changeps1', 'no'])
subprocess.call(['conda', 'update', '-q', 'conda'])
# Useful for debugging any issues with conda
subprocess.call(['conda', 'info', '-a'])

# Replace dep1 dep2 ... with your dependencies
subprocess.call(['conda', 'env', 'create', '-f', 'environment.yml'])
subprocess.call(['conda', 'activate', 'sciview'])
build_conda()

def package_conda():
subprocess.call(['sh', 'populate_fiji.sh'])
subprocess.call(['pyinstaller', '--onefile', '--add-data', 'Fiji.app/jars:jars', 'src/main/python/sciview.py'])

platform = subprocess.check_output(['uname', '-s'])
arch = subprocess.check_output(['uname', '-m'])

if platform == 'Linux' and arch == 'x86_64':
exe_name = 'sciview-linux64'
elif platform == 'Linux':
exe_name = 'sciview-linux32'
elif platform == 'Darwin':
exe_name = 'sciview-macos'
elif platform.startswith('MING'):
exe_name = 'sciview-win32'
elif platform.startswith('MSYS_NT'):
exe_name = 'sciview-win32'

subprocess.call(['mv', 'dist/sciview', exe_name])
package_conda()

# Update sites
print('')
print('')
print('')
print('Checking if upload to update site needed')

## Unstable
## Commit message trigger requires one of these conditions:
## - message begin with SV_IJ_DEPLOY_UNSTABLE
## - push/merge to master

if ( branch == 'master' and not is_PR and travis_secure ) or \
( '[SV_IJ_DEPLOY_UNSTABLE]' in commit_message ):

print('Upload to SciView-Unstable')
subprocess.call(['sh', 'sciview_deploy_unstable.sh'])

## Primary
## Commit message trigger requires one of these conditions:
## - message begin with SV_IJ_DEPLOY_PRIMARY
## - release

# TODO: check branch == <pom-release-version>
if ( not is_PR and travis_secure and release_properties_exists ) or \
( '[SV_IJ_DEPLOY_PRIMARY]' in commit_message ):
print('Upload to SciView')
subprocess.call(['sh', 'sciview_deploy.sh'])

23 changes: 23 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: sciview
channels:
- conda-forge
- defaults
dependencies:
- python >=3.8
# - pyyaml
# - numpy
# - Pillow
# - pyimagej
# - opencv
# - matplotlib
# - openjdk
- maven
- git
- openjdk >=8.0.192,<8.1.0a0
- pip
- pip:
- pathlib
- requests
- pyinstaller
# - tensorflow
# - keras
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.scijava</groupId>
<artifactId>pom-scijava</artifactId>
<version>29.0.0-beta-3</version>
<version>29.2.1</version>
<relativePath />
</parent>

Expand Down
23 changes: 13 additions & 10 deletions populate_fiji.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,23 @@ deleteNatives() {
die "Delete failed"
}

case "$(uname -s),$(uname -m)" in
Linux,x86_64) launcher=ImageJ-linux64 ;;
Linux,*) launcher=ImageJ-linux32 ;;
Darwin,*) launcher=Contents/MacOS/ImageJ-macosx ;;
MING*,*) launcher=ImageJ-win32.exe ;;
MSYS_NT*,*) launcher=ImageJ-win32.exe ;;
*) die "Unknown platform" ;;
esac

# -- Check if we have a path given, in that case we do not download a new Fiji, but use the path given --
if [ -z "$1" ]
then
echo "--> Installing into pristine Fiji installation"
echo "--> If you want to install into a pre-existing Fiji installation, run as"
echo " $0 path/to/Fiji.app"
# -- Determine correct ImageJ launcher executable --

case "$(uname -s),$(uname -m)" in
Linux,x86_64) launcher=ImageJ-linux64 ;;
Linux,*) launcher=ImageJ-linux32 ;;
Darwin,*) launcher=Contents/MacOS/ImageJ-macosx ;;
MING*,*) launcher=ImageJ-win32.exe ;;
MSYS_NT*,*) launcher=ImageJ-win32.exe ;;
*) die "Unknown platform" ;;
esac


# -- Roll out a fresh Fiji --

Expand Down Expand Up @@ -121,6 +122,7 @@ installWithGroupId "$ffmpegGAV:jar:macosx-x86_64" $FijiDirectory/jars/macosx
wget "https://maven.scijava.org/service/local/repositories/releases/content/net/imagej/imagej-launcher/5.0.2/imagej-launcher-5.0.2-linux64.exe" -O $FijiDirectory/ImageJ-linux64 ||
die "Could not get linux64 launcher"
chmod +x $FijiDirectory/ImageJ-linux64
mkdir -p $FijiDirectory/Contents/MacOS/
wget "https://maven.scijava.org/service/local/repositories/releases/content/net/imagej/imagej-launcher/5.0.2/imagej-launcher-5.0.2-macosx.exe" -O $FijiDirectory/Contents/MacOS/ImageJ-macosx ||
die "Could not get macOS launcher"
chmod +x $FijiDirectory/Contents/MacOS/ImageJ-macosx
Expand Down Expand Up @@ -186,7 +188,8 @@ done

echo
echo "--> Testing installation with command: sc.iview.commands.help.About"
OUT_TEST=$(Fiji.app/$launcher --headless --run sc.iview.commands.help.About)
EXE="$FijiDirectory//$launcher"
OUT_TEST=$($EXE --headless --run sc.iview.commands.help.About)
echo $OUT_TEST

if [ -z "$OUT_TEST" ]
Expand Down
24 changes: 24 additions & 0 deletions src/main/python/sciview.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import subprocess
import os
import sys

# https://stackoverflow.com/questions/7674790/bundling-data-files-with-pyinstaller-onefile
def resource_path(relative_path):
""" Get absolute path to resource, works for dev and for PyInstaller """
try:
# PyInstaller creates a temp folder and stores path in _MEIPASS
base_path = sys._MEIPASS
except Exception:
base_path = os.path.abspath(".")

return os.path.join(base_path, relative_path)

classpath = resource_path('./jars/*')
classpath += ':%s' % resource_path( './jars/bio-formats/*' )
classpath += ':%s' % resource_path( './jars/linux32/*' )
classpath += ':%s' % resource_path( './jars/linux64/*' )
classpath += ':%s' % resource_path( './jars/macosx/*' )
classpath += ':%s' % resource_path( './jars/win32/*' )
classpath += ':%s' % resource_path( './jars/win64/*' )

subprocess.call(['java', '-cp', classpath, 'sc.iview.Main'])
Loading

0 comments on commit 26ed007

Please sign in to comment.