-
Notifications
You must be signed in to change notification settings - Fork 9
/
install-devel.sh
executable file
·1223 lines (944 loc) · 32.3 KB
/
install-devel.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
# Travis: repo is provided by travis.
# build conda environment
#
# Jenkins: repo is provided by jenkins
#
# Local: code can be downloaded (--clone-from-repo)
#
# References
# http://kvz.io/blog/2013/11/21/bash-best-practices/
# http://jvns.ca/blog/2017/03/26/bash-quirks/
# exit when a command fails
set -o errexit
# exit if any pipe commands fail
set -o pipefail
# exit when your script tries to use undeclared variables
#set -o nounset
# trace what gets executed
#set -o xtrace
#set -o errtrace
# Bash traps
# http://aplawrence.com/Basics/trapping_errors.html
# https://stelfox.net/blog/2013/11/fail-fast-in-bash-scripts/
SCRIPT_NAME="$0"
SCRIPT_PARAMS="$@"
error_handler() {
echo
echo " ########################################################## "
echo
echo " An error occurred in:"
echo
echo " - line number: ${1}"
shift
echo " - exit status: ${1}"
shift
echo " - command: ${@}"
echo
echo " The script will abort now. User input was: "
echo
echo " ${SCRIPT_NAME} ${SCRIPT_PARAMS}"
echo
echo " Please copy and paste this error and report it via Git Hub: "
echo " https://github.com/cgat-developers/cgat-flow/issues "
print_env_vars
echo " ########################################################## "
}
trap 'error_handler ${LINENO} $? ${BASH_COMMAND}' ERR INT TERM
# log installation information
log() {
echo "# install-devel.sh log | `hostname` | `date` | $1 "
}
# report error and exit
report_error() {
echo
echo $1
echo
echo "Aborting."
echo
exit 1
}
# detect CGAT installation
detect_cgat_installation() {
if [[ -z "$CGAT_HOME" ]] ; then
if [[ -d "$HOME/cgat-install/conda-install" ]] ; then
UNINSTALL_DIR="$HOME/cgat-install"
fi
else
if [[ -d "$CGAT_HOME/conda-install" ]] ; then
UNINSTALL_DIR="$CGAT_HOME"
fi
fi
} # detect_cgat_installation
# configure environment variables
# set: CGAT_HOME, CONDA_INSTALL_DIR, CONDA_INSTALL_TYPE_PIPELINES
get_cgat_env() {
if [[ -z $CGAT_HOME ]] ; then
CGAT_HOME=$HOME/cgat-install
fi
if [[ -z $CGATFLOW_REPO ]] ; then
CGATFLOW_REPO="$CGAT_HOME/cgat-flow"
fi
if [[ $INSTALL_DEVEL ]] || [[ $INSTALL_PIPELINE_DEPENDENCIES ]]; then
CONDA_INSTALL_TYPE_PIPELINES="cgat-flow.yml"
CONDA_INSTALL_TYPE_APPS="cgat-apps.yml"
CONDA_INSTALL_TYPE_CORE="cgat-core.yml"
elif [[ $RUN_TESTS ]] || [[ $INSTALL_UPDATE ]] ; then
if [[ -d $CGAT_HOME/conda-install ]] ; then
AUX=`find $CGAT_HOME/conda-install/envs/cgat-* -maxdepth 0`
CONDA_INSTALL_TYPE_PIPELINES=`basename $AUX`
else
echo " The location of the CGAT code was not found (function: get_cgat_env). "
echo " Please install it first or use --location option with full path to your installation. "
echo
exit 1
fi
else
echo
echo " Wrong installation type! "
echo " Installation aborted. "
echo
exit 1
fi # if install type
# set installation folder
CONDA_INSTALL_DIR=$CGAT_HOME/conda-install
# set conda environment name
[[ ${CONDA_INSTALL_ENV} ]] || CONDA_INSTALL_ENV="cgat-flow"
} # get_cgat_env
# check whether the 'cgat-flow' conda environment is enabled
# and try to enable it if not
is_env_enabled() {
# disable error checking
set +e
# is conda available?
CONDA_PATH=$(which conda)
if [[ $? -ne 0 ]] ; then
# conda is not available
get_cgat_env
source ${CONDA_INSTALL_DIR}/etc/profile.d/conda.sh
fi
# is conda available?
CONDA_PATH=$(which conda)
if [[ $? -eq 0 ]] ; then
# conda is available
# activate cgat-flow env
conda activate ${CONDA_INSTALL_ENV}
else
# conda is not available
report_error " Conda can't be found! "
fi
# enable error checking again
set -e
}
# setup environment variables
setup_env_vars() {
export CFLAGS=$CFLAGS" -I$CONDA_INSTALL_DIR/envs/$CONDA_INSTALL_ENV/include -L$CONDA_INSTALL_DIR/envs/$CONDA_INSTALL_ENV/lib"
export CPATH=$CPATH" -I$CONDA_INSTALL_DIR/envs/$CONDA_INSTALL_ENV/include -L$CONDA_INSTALL_DIR/envs/$CONDA_INSTALL_ENV/lib"
export C_INCLUDE_PATH=$C_INCLUDE_PATH:$CONDA_INSTALL_DIR/envs/$CONDA_INSTALL_ENV/include
export CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:$CONDA_INSTALL_DIR/envs/$CONDA_INSTALL_ENV/include
export LIBRARY_PATH=$LIBRARY_PATH:$CONDA_INSTALL_DIR/envs/$CONDA_INSTALL_ENV/lib
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CONDA_INSTALL_DIR/envs/$CONDA_INSTALL_ENV/lib:$CONDA_INSTALL_DIR/envs/$CONDA_INSTALL_ENV/lib/R/lib
} # setup_env_vars
# print related environment variables
print_env_vars() {
echo
echo " Debugging: "
echo " CFLAGS: "$CFLAGS
echo " CPATH: "$CPATH
echo " C_INCLUDE_PATH: "$C_INCLUDE_PATH
echo " CPLUS_INCLUDE_PATH: "$CPLUS_INCLUDE_PATH
echo " LIBRARY_PATH: "$LIBRARY_PATH
echo " LD_LIBRARY_PATH: "$LD_LIBRARY_PATH
echo " CGAT_HOME: "$CGAT_HOME
echo " CGATFLOW_DIR: "$CGATFLOW_DIR
echo " CGATFLOW_REPO: "$CGATFLOW_REPO
echo " CONDA_INSTALL_DIR: "$CONDA_INSTALL_DIR
echo " CONDA_INSTALL_TYPE_CORE:"$CONDA_INSTALL_TYPE_CORE
echo " CONDA_INSTALL_TYPE_APPS: "$CONDA_INSTALL_TYPE_APPS
echo " CONDA_INSTALL_TYPE_PIPELINES: "$CONDA_INSTALL_TYPE_PIPELINES
echo " CONDA_INSTALL_ENV: "$CONDA_INSTALL_ENV
echo " PYTHONPATH: "$PYTHONPATH
[[ ! $RUN_TESTS ]] && echo " CGATFLOW_BRANCH: "$CGATFLOW_BRANCH
[[ ! $RUN_TESTS ]] && echo " CGATAPPS_BRANCH: "$CGATAPPS_BRANCH
[[ ! $RUN_TESTS ]] && echo " CGATCORE_BRANCH: "$CGATCORE_BRANCH
[[ ! $RUN_TESTS ]] && echo " RELEASE: "$RELEASE
echo " CODE_DOWNLOAD_TYPE: "$CODE_DOWNLOAD_TYPE
echo " CLUSTER: "$CLUSTER
echo
} # print_env_vars
# Travis installations are running out of RAM
# with large conda installations. Issue has been submitted here:
# https://github.com/conda/conda/issues/1197
# While we wait for a response, we'll try to clean up the conda
# installation folder as much as possible
conda_cleanup() {
conda clean --index-cache
conda clean --lock
conda clean --tarballs -y
conda clean --packages -y
}
# proceed with conda installation
conda_install() {
log "installing conda"
detect_cgat_installation
if [[ -n "$UNINSTALL_DIR" ]] ; then
echo
echo " An installation of the CGAT code was found in: $UNINSTALL_DIR"
echo " Please use --location to install CGAT code in a different location "
echo " or uninstall the current version before proceeding."
echo
echo " Installation is aborted."
echo
exit 1
fi
# get environment variables: CGAT_HOME, CONDA_INSTALL_DIR, CONDA_INSTALL_TYPE_PIPELINES
get_cgat_env
mkdir -p $CGAT_HOME
cd $CGAT_HOME
# select Miniconda bootstrap script depending on Operating System
MINICONDA=
if [[ `uname` == "Linux" ]] ; then
# Conda 4.4 breaks everything again!
# Conda 4.5 looks better
MINICONDA="Miniconda3-latest-Linux-x86_64.sh"
#MINICONDA="Miniconda3-4.3.31-Linux-x86_64.sh"
elif [[ `uname` == "Darwin" ]] ; then
# Conda 4.4 breaks everything again!
# Conda 4.5 looks better
MINICONDA="Miniconda3-latest-MacOSX-x86_64.sh"
#MINICONDA="Miniconda3-4.3.31-MacOSX-x86_64.sh"
else
echo
echo " Unsupported operating system detected. "
echo
echo " Aborting installation... "
echo
exit 1
fi
log "downloading miniconda"
# download and install conda
wget https://repo.continuum.io/miniconda/${MINICONDA} -O miniconda.sh;
log "installing miniconda"
bash miniconda.sh -b -p $CONDA_INSTALL_DIR
source ${CONDA_INSTALL_DIR}/bin/activate
hash -r
# install cgat environment
# Conda 4.4 breaks everything again!
# Conda 4.5 looks better
#conda install --quiet --yes 'conda=4.3.33'
conda update --all --yes
conda info -a
log "installing conda CGAT environment"
# Now using conda environment files:
# https://conda.io/docs/using/envs.html#use-environment-from-file
log "curl -o env-cgat-core.yml -O https://raw.githubusercontent.com/cgat-developers/cgat-core/${CGATCORE_BRANCH}/conda/environments/${CONDA_INSTALL_TYPE_CORE}"
curl -o env-cgat-core.yml -O https://raw.githubusercontent.com/cgat-developers/cgat-core/${CGATCORE_BRANCH}/conda/environments/${CONDA_INSTALL_TYPE_CORE}
log "curl -o env-cgat-apps.yml -O https://raw.githubusercontent.com/cgat-developers/cgat-apps/${CGATAPPS_BRANCH}/conda/environments/${CONDA_INSTALL_TYPE_APPS}"
curl -o env-cgat-apps.yml -O https://raw.githubusercontent.com/cgat-developers/cgat-apps/${CGATAPPS_BRANCH}/conda/environments/${CONDA_INSTALL_TYPE_APPS}
log "curl -o env-cgat-flow.yml -O https://raw.githubusercontent.com/cgat-developers/cgat-flow/${TRAVIS_BRANCH}/conda/environments/${CONDA_INSTALL_TYPE_PIPELINES}"
curl -o env-cgat-flow.yml -O https://raw.githubusercontent.com/cgat-developers/cgat-flow/${TRAVIS_BRANCH}/conda/environments/${CONDA_INSTALL_TYPE_PIPELINES}
[[ ${CLUSTER} -eq 0 ]] && sed -i'' -e '/drmaa/d' env-cgat-flow.yml
log "creating environment with cgat-core dependencies"
conda env create --name ${CONDA_INSTALL_ENV} --file env-cgat-core.yml
log "updating with cgat-apps dependencies"
conda env update --name ${CONDA_INSTALL_ENV} --file env-cgat-apps.yml
log "updating with cgat-flow dependencies"
conda env update --name ${CONDA_INSTALL_ENV} --file env-cgat-flow.yml
# activate cgat environment
conda activate ${CONDA_INSTALL_ENV}
# install extra deps
install_extra_deps
# install all other pipeline dependencies
# this step has to be done here, see:
# https://github.com/cgat-developers/cgat-flow/pull/119
if [[ $INSTALL_PIPELINE_DEPENDENCIES -eq 1 ]]; then
install_pipeline_deps
fi
# Set up other environment variables
#setup_env_vars
# install cgat-core
install_cgat_core
# install cgat-apps
install_cgat_apps
# install cgat-flow
install_cgat_flow
} # conda install
# install extra dependencies
install_extra_deps() {
log "install extra deps"
curl -O https://raw.githubusercontent.com/cgat-developers/cgat-flow/${TRAVIS_BRANCH}/conda/environments/pipelines-extra.yml
conda env update --name ${CONDA_INSTALL_ENV} --file pipelines-extra.yml
}
# install dependencies for running the pipelines
install_pipeline_deps() {
cd $CGAT_HOME
get_cgat_env
# activate cgat environment
is_env_enabled
log "install pipeline deps"
curl -O https://raw.githubusercontent.com/cgat-developers/cgat-flow/${TRAVIS_BRANCH}/conda/environments/cgat-flow-pipelines.yml
conda env update --name ${CONDA_INSTALL_ENV} --file cgat-flow-pipelines.yml
install_extra_envs
}
# install Python 2 dependencies in a different conda environment
install_extra_envs() {
log "install extra environments"
curl -O https://raw.githubusercontent.com/cgat-developers/cgat-flow/${TRAVIS_BRANCH}/conda/environments/pipelines-macs2.yml
conda env update --file pipelines-macs2.yml
curl -O https://raw.githubusercontent.com/cgat-developers/cgat-flow/${TRAVIS_BRANCH}/conda/environments/pipelines-tophat2.yml
conda env update --file pipelines-tophat2.yml
curl -O https://raw.githubusercontent.com/cgat-developers/cgat-flow/${TRAVIS_BRANCH}/conda/environments/pipeline-peakcalling-sicer.yml
conda env update --file pipeline-peakcalling-sicer.yml
curl -O https://raw.githubusercontent.com/cgat-developers/cgat-flow/${TRAVIS_BRANCH}/conda/environments/pipelines-splicing.yml
conda env update --file pipelines-splicing.yml
curl -O https://raw.githubusercontent.com/cgat-developers/cgat-flow/${TRAVIS_BRANCH}/conda/environments/pipelines-sailfish.yml
conda env update --file pipelines-sailfish.yml
curl -O https://raw.githubusercontent.com/cgat-developers/cgat-flow/${TRAVIS_BRANCH}/conda/environments/pipelines-salmon.yml
conda env update --file pipelines-salmon.yml
}
# helper function to install cgat-flow
install_cgat_flow() {
log "install cgat flow"
OLDWD=`pwd`
cd $CGAT_HOME
# download the code out of jenkins
if [[ ${CLONE_FROM_REPO} -eq 1 ]] ; then
if [[ $CODE_DOWNLOAD_TYPE -eq 0 ]] ; then
# get the latest version from Git Hub in zip format
curl -LOk https://github.com/cgat-developers/cgat-flow/archive/$CGATFLOW_BRANCH.zip
unzip $CGATFLOW_BRANCH.zip
rm $CGATFLOW_BRANCH.zip
if [[ ${RELEASE} ]] ; then
NEW_NAME=`echo $CGATFLOW_BRANCH | sed 's/^v//g'`
mv cgat-flow-$NEW_NAME/ $CGATFLOW_REPO
else
mv cgat-flow-$CGATFLOW_BRANCH/ $CGATFLOW_REPO
fi
elif [[ $CODE_DOWNLOAD_TYPE -eq 1 ]] ; then
# get latest version from Git Hub with git clone
git clone --branch=$CGATFLOW_BRANCH https://github.com/cgat-developers/cgat-flow.git $CGATFLOW_REPO
elif [[ $CODE_DOWNLOAD_TYPE -eq 2 ]] ; then
# get latest version from Git Hub with git clone
git clone --branch=$CGATFLOW_BRANCH git@github.com:cgat-developers/cgat-flow.git $CGATFLOW_REPO
else
report_error " Unknown download type for CGAT code... "
fi
# make sure you are in the CGAT_HOME/cgat-flow folder
cd $CGATFLOW_REPO
else
log "using existing cgat-flow repo in $CGATFLOW_REPO"
cd "$CGATFLOW_REPO"
fi
# Python preparation
log "linking cgat-flow code into conda environment"
sed -i'' -e '/REPO_REQUIREMENT/,/pass/d' setup.py
sed -i'' -e '/# dependencies/,/dependency_links=dependency_links,/d' setup.py
python setup.py develop
if [[ $? -ne 0 ]] ; then
echo
echo " There was a problem doing: 'python setup.py develop' "
echo " Installation did not finish properly. "
echo
echo " Please submit this issue via Git Hub: "
echo " https://github.com/cgat-developers/cgat-flow/issues "
echo
print_env_vars
else
clear
echo
echo " The code successfully installed!"
echo
echo " To activate the CGAT environment type: "
echo " $ source $CONDA_INSTALL_DIR/etc/profile.d/conda.sh"
echo " $ conda activate base"
echo " $ conda activate $CONDA_INSTALL_ENV"
echo
echo " To deactivate the environment, use:"
echo " $ conda deactivate"
echo
fi # if-$?
# revert setup.py if downloaded with git
[[ $CODE_DOWNLOAD_TYPE -ge 1 ]] && git checkout -- setup.py
# environment pinning
# python scripts/conda.py
# go back to old working directory
cd $OLDWD
} # install_cgat_flow
# helper function to install cgat-apps
install_cgat_apps() {
log "install cgat apps"
OLDWD=`pwd`
cd $CGAT_HOME
if [[ $CODE_DOWNLOAD_TYPE -eq 0 ]] ; then
# get the latest version from Git Hub in zip format
curl -LOk https://github.com/cgat-developers/cgat-apps/archive/$CGATAPPS_BRANCH.zip
unzip $CGATAPPS_BRANCH.zip
rm $CGATAPPS_BRANCH.zip
if [[ ${RELEASE} ]] ; then
NEW_NAME=`echo $CGATAPPS_BRANCH | sed 's/^v//g'`
mv cgat-apps-$NEW_NAME/ cgat-apps/
else
mv cgat-apps-$CGATAPPS_BRANCH/ cgat-apps/
fi
elif [[ $CODE_DOWNLOAD_TYPE -eq 1 ]] ; then
# get latest version from Git Hub with git clone
git clone --branch=$CGATAPPS_BRANCH https://github.com/cgat-developers/cgat-apps.git
elif [[ $CODE_DOWNLOAD_TYPE -eq 2 ]] ; then
# get latest version from Git Hub with git clone
git clone --branch=$CGATAPPS_BRANCH git@github.com:cgat-developers/cgat-apps.git
else
report_error " Unknown download type for CGAT code... "
fi
cd cgat-apps/
# remove install_requires (no longer required with conda package)
sed -i'' -e '/REPO_REQUIREMENT/,/pass/d' setup.py
sed -i'' -e '/# dependencies/,/dependency_links=dependency_links,/d' setup.py
python setup.py develop
if [[ $? -ne 0 ]] ; then
echo
echo " There was a problem doing: 'python setup.py develop' "
echo " Installation did not finish properly. "
echo
echo " Please submit this issue via Git Hub: "
echo " https://github.com/cgat-developers/cgat-flow/issues "
echo
print_env_vars
fi # if-$?
# revert setup.py if downloaded with git
[[ $CODE_DOWNLOAD_TYPE -ge 1 ]] && git checkout -- setup.py
# go back to old working directory
cd $OLDWD
} # install_cgat_apps
# helper function to install cgat-core
install_cgat_core() {
log "install cgat core"
OLDWD=`pwd`
cd $CGAT_HOME
if [[ $CODE_DOWNLOAD_TYPE -eq 0 ]] ; then
# get the latest version from Git Hub in zip format
curl -LOk https://github.com/cgat-developers/cgat-core/archive/$CGATCORE_BRANCH.zip
unzip $CGATCORE_BRANCH.zip
rm $CGATCORE_BRANCH.zip
if [[ ${RELEASE} ]] ; then
NEW_NAME=`echo $CGATCORE_BRANCH | sed 's/^v//g'`
mv cgat-core-$NEW_NAME/ cgat-core/
else
mv cgat-core-$CGATCORE_BRANCH/ cgat-core/
fi
elif [[ $CODE_DOWNLOAD_TYPE -eq 1 ]] ; then
# get latest version from Git Hub with git clone
git clone --branch=$CGATCORE_BRANCH https://github.com/cgat-developers/cgat-core.git
elif [[ $CODE_DOWNLOAD_TYPE -eq 2 ]] ; then
# get latest version from Git Hub with git clone
git clone --branch=$CGATCORE_BRANCH git@github.com:cgat-developers/cgat-core.git
else
report_error " Unknown download type for CGAT core... "
fi
cd cgat-core/
# remove install_requires (no longer required with conda package)
sed -i'' -e '/REPO_REQUIREMENT/,/pass/d' setup.py
sed -i'' -e '/# dependencies/,/dependency_links=dependency_links,/d' setup.py
python setup.py develop
if [[ $? -ne 0 ]] ; then
echo
echo " There was a problem doing: 'python setup.py develop' "
echo " Installation did not finish properly. "
echo
echo " Please submit this issue via Git Hub: "
echo " https://github.com/cgat-developers/cgat-apps/issues "
echo
print_env_vars
fi # if-$?
# revert setup.py if downloaded with git
[[ $CODE_DOWNLOAD_TYPE -ge 1 ]] && git checkout -- setup.py
# go back to old working directory
cd $OLDWD
} # install_cgat_core
# test code with conda install
conda_test() {
log "starting conda_test"
# get environment variables: CGAT_HOME, CONDA_INSTALL_DIR, CONDA_INSTALL_TYPE_PIPELINES
get_cgat_env
#setup_env_vars
# setup environment and run tests
if [[ $TRAVIS_INSTALL ]] || [[ $JENKINS_INSTALL ]] ; then
# activate cgat environment
is_env_enabled
# show conda environment used for testing
conda env list
log "conda env export"
conda env export
# install cgat-core
install_cgat_core
# install cgat-apps
install_cgat_apps
# python preparation
log "install CGAT code into conda environment"
cd $CGAT_HOME
# Python preparation
sed -i'' -e 's/CGATScripts/scripts/g' setup.py
sed -i'' -e '/REPO_REQUIREMENT/,/pass/d' setup.py
sed -i'' -e '/# dependencies/,/dependency_links=dependency_links,/d' setup.py
python setup.py develop
log "starting tests"
# run nosetests
if [[ $TEST_ALL ]] ; then
log "test_style.py" && nosetests -v tests/test_style.py && \
log "test_import.py" && nosetests -v tests/test_import.py && \
echo -e "restrict:\n manifest:\n" > tests/_test_commandline.yaml && \
log "test_commandline" && nosetests -v tests/test_commandline.py && \
log "test_scripts" && nosetests -v tests/test_scripts.py ;
elif [[ $TEST_IMPORT ]] ; then
nosetests -v tests/test_import.py ;
elif [[ $TEST_STYLE ]] ; then
nosetests -v tests/test_style.py ;
elif [[ $TEST_CMDLINE ]] ; then
echo -e "restrict:\n manifest:\n" > tests/_test_commandline.yaml
nosetests -v tests/test_commandline.py ;
elif [[ $TEST_PRODUCTION_SCRIPTS ]] ; then
echo -e "restrict:\n manifest:\n" > tests/_test_scripts.yaml
nosetests -v tests/test_scripts.py ;
else
nosetests -v tests/test_scripts.py ;
fi
else
if [[ $CONDA_INSTALL_TYPE_PIPELINES ]] ; then
# activate cgat environment
is_env_enabled
# show conda environment used for testing
conda env list
log "conda env export"
conda env export
# make sure you are in the CGAT_HOME/cgat-flow folder
cd $CGATFLOW_REPO
OUTPUT_DIR=`pwd`
# run tests, note: OSX has no options (no -v, -o)
/usr/bin/time nosetests -v tests/test_import.py
if [[ $? -eq 0 ]] ; then
echo
echo " test_import.py passed successfully! "
echo
else
echo
echo " test_import.py failed. Please see $OUTPUT_DIR/test_import.out file for detailed output. "
echo
print_env_vars
fi
/usr/bin/time nosetests -v tests/test_scripts.py
if [[ $? -eq 0 ]] ; then
echo
echo " test_scripts.py passed successfully! "
echo
else
echo
echo " test_scripts.py failed. Please see $OUTPUT_DIR/test_scripts.out file for detailed output. "
echo
print_env_vars
fi
else
echo
echo " There was an error running the tests. "
echo " Execution aborted. "
echo
print_env_vars
exit 1
fi
fi # if travis or jenkins
} # conda_test
# update conda installation
conda_update() {
# get environment variables: CGAT_HOME, CONDA_INSTALL_DIR, CONDA_INSTALL_TYPE_PIPELINES
get_cgat_env
# activate cgat environment
is_env_enabled
conda update --all
if [[ ! $? -eq 0 ]] ; then
echo
echo " There was a problem updating the installation. "
echo
echo " Please submit this issue via Git Hub: "
echo " https://github.com/cgat-developers/cgat-flow/issues "
echo
else
echo
echo " All packages were succesfully updated. "
echo
fi
} # conda_update
# unistall CGAT code collection
uninstall() {
detect_cgat_installation
if [[ -z "$UNINSTALL_DIR" ]] ; then
echo
echo " The location of the CGAT code was not found. "
echo " Please uninstall manually."
echo
exit 1
else
rm -rf $UNINSTALL_DIR
if [[ $? -eq 0 ]] ; then
echo
echo " CGAT code successfully uninstalled."
echo
exit 0
else
echo
echo " There was a problem uninstalling the CGAT code."
echo " Please uninstall manually."
echo
exit 1
fi
fi
}
# test whether --git and --git-ssh download is doable
test_git() {
git --version >& /dev/null || GIT_AVAIL=$?
if [[ $GIT_AVAIL -ne 0 ]] ; then
echo
echo " Git is not available but --git or --git-ssh option was given."
echo " Please rerun this script on a computer with git installed "
echo " or try again without --git or --git-ssh"
report_error " "
fi
}
# test whether --git-ssh download is doable
test_git_ssh() {
ssh-add -L >& /dev/null || SSH_KEYS_LOADED=$?
if [[ $SSH_KEYS_LOADED -ne 0 ]] ; then
echo
echo " Please load your ssh keys for GitHub before proceeding!"
echo
echo " Try: "
echo " 1. eval \$(ssh-agent)"
echo " 2. ssh-add ~/.ssh/id_rsa # or the file where your private key is"
report_error " and run this script again. "
fi
}
# don't mix branch and release options together
test_mix_branch_release() {
# don't mix branch and release options together
if [[ $RELEASE ]] ; then
if [[ "$CGATFLOW_BRANCH" != "master" ]] || [[ $CGATAPPS_BRANCH != "master" ]] ; then
echo
echo " You cannot mix git branches and releases for the installation."
echo
echo " Your input was: "$SCRIPT_PARAMS
report_error " Please either use branches or releases but not both."
fi
fi
}
# test whether a branch exists in the cgat-core repository
# https://stackoverflow.com/questions/12199059/how-to-check-if-an-url-exists-with-the-shell-and-probably-curl
test_core_branch() {
RELEASE_TEST=0
curl --output /dev/null --silent --head --fail https://raw.githubusercontent.com/cgat-developers/cgat-core/${CGATCORE_BRANCH}/README.md || RELEASE_TEST=$?
if [[ ${RELEASE_TEST} -ne 0 ]] ; then
echo
echo " The branch provided for cgat-core does not exist: ${CGATCORE_BRANCH}"
echo
echo " Please have a look at valid branches here: "
echo " https://github.com/cgat-developers/cgat-core/branches"
echo
report_error " Please use a valid branch and try again."
fi
}
# test whether a branch exists in the cgat-apps repository
# https://stackoverflow.com/questions/12199059/how-to-check-if-an-url-exists-with-the-shell-and-probably-curl
test_apps_branch() {
RELEASE_TEST=0
curl --output /dev/null --silent --head --fail https://raw.githubusercontent.com/cgat-developers/cgat-apps/${CGATAPPS_BRANCH}/README.rst || RELEASE_TEST=$?
if [[ ${RELEASE_TEST} -ne 0 ]] ; then
echo
echo " The branch provided for cgat-apps does not exist: ${CGATAPPS_BRANCH}"
echo
echo " Please have a look at valid branches here: "
echo " https://github.com/cgat-developers/cgat-apps/branches"
echo
report_error " Please use a valid branch and try again."
fi
}
# test whether a release exists or not
# https://stackoverflow.com/questions/12199059/how-to-check-if-an-url-exists-with-the-shell-and-probably-curl
test_release() {
RELEASE_PIPELINES=0
# check pipelines
curl --output /dev/null \
--silent --head --fail \
https://raw.githubusercontent.com/cgat-developers/cgat-flow/${RELEASE}/README.rst || RELEASE_PIPELINES=$?
if [[ ${RELEASE_PIPELINES} -ne 0 ]] ; then
echo
echo " The release number provided for the pipelines does not exist: ${RELEASE}"
echo
echo " Please have a look at valid releases here: "
echo " https://github.com/cgat-developers/cgat-flow/releases"
echo
echo " An example of valid release is: --release v0.4.0"
report_error " Please use a valid release and try again."
fi
RELEASE_SCRIPTS=0
# check scripts
curl --output /dev/null \
--silent --head --fail \
https://raw.githubusercontent.com/cgat-developers/cgat-apps/${RELEASE}/README.rst || RELEASE_SCRIPTS=$?
if [[ ${RELEASE_SCRIPTS} -ne 0 ]] ; then
echo
echo " The release number provided for the scripts does not exist: ${RELEASE}"
echo
echo " Please have a look at valid releases here: "
echo " https://github.com/cgat-developers/cgat-apps/releases"
echo
echo " An example of valid release is: --release v0.4.0"
report_error " Please use a valid release and try again."
fi
}
# test whether a C/C++ compiler is available
test_compilers() {
which gcc &> /dev/null || report_error " C compiler not found "
which g++ &> /dev/null || report_error " C++ compiler not found "
}
# clean up environment
# deliberately use brute force
cleanup_env() {
set +e
conda deactivate >& /dev/null || true
conda deactivate >& /dev/null || true
unset -f conda || true
unset PYTHONPATH || true
# Next actions disabled. Please see:
# https://github.com/cgat-developers/cgat-core/issues/44
#module purge >& /dev/null || true
#mymodule purge >& /dev/null || true
set -e
}
# function to display help message
help_message() {
cat << EOF
usage="$(basename "$0") cgatflow install script
where:
-h/--help show this help text. The following options are supported:
--install-repo install cgatflow from repository. This will also install
conda and the conda environment.
--install-pipeline-dependencies install dependencies for running the pipelines
included in the cgat-flow repository.
--clone-from-repo clone a fresh copy from git for the install. Please specify
either --clone-from-repo or --use-repo.
--use-repo PATH install from an existing repository in PATH, see above.
--location PATH installation PATH for the conda environment. Must not exist.
--cgatflow-branch BRANCH branch to use for cgatflow repository checkout. Default
is master.
--cgatapps-branch BRANCH branch to install from cgatapps. Default is master.
--cgatcore-branch BRANCH branch to install from cgatapps. Default is master.
--env-name NAME name of conda environment. Default is 'cgat-flow'
Examples:
For an install from a clone in the current directory into a new conda installation, type:
./install-devel.sh
--install-repo
--install-pipeline-dependencies
--use-repo .
--location </full/path/to/folder/without/trailing/slash>
To install a specific branch of the code on GitHub from scratch:
curl -O https://raw.githubusercontent.com/cgat-developers/cgat-flow/master/install-devel.sh
./install-devel.sh
--install-repo
--install-pipeline-dependencies
--clone-from-repo
--cgatflow-branch <branch>
--location </full/path/to/folder/without/trailing/slash>
Please submit any issues via Git Hub:
https://github.com/cgat-developers/cgat-flow/issues
EOF
} # help_message
# the script starts here
cleanup_env
test_compilers
if [[ $# -eq 0 ]] ; then
help_message
fi
# conda installation type. If set to 1, cgat-core and cgat-apps
# will be installed from repository.