Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing both Python and R for a Travis build?

I've been working on an R package which interfaces with Python via a simple server script and socket connections. I can test in on my own machine just fine, but I'd like to test it on a Travis build as well (I don't want to go through the effort of setting up a Linux VM). To do this I would need a Python install that I can pass the path to in my R package tests, and a port number to use.

I've seen this answer which suggests installing multiple Python builds is possible, but I'm not sure how to approach

  1. Specifying the path(s) to the Python executable(s)
  2. choosing a port number for the test. It should also be noted that the Python script I am using for the Python 'server' uses 'localhost'.

Is it possible to do what I want on Travis? Should I want to do this with Travis?

EDIT Here's my Travis config:

language: r
r:
  - release
  - devel
cache: packages
sudo: false

matrix:
  include:
    - python:2.7
    - python:3.6

# Be strict when checking our package
warnings_are_errors: true

# System dependencies for HTTP calling
r_binary_packages:
 - jsonlite
 - R6

And here is the example in my R package:

pypath = Sys.which('python') 
if(nchar(pypath) > 0) {
  py = PythonEnv$new(port = 6011, path = pypath)
  py$start
  py$running
  py$set(a = 5)
  py$get('a')
  py$stop
} else {
  message("No Python environment available")
}

My example definitely finds a Python path, but fails with the error

Warning in socketConnection(port = self$port, open = "r+", blocking = TRUE, : localhost:6011 cannot be opened

Error socketConnection(port = self$port, open = "r+", blocking = TRUE, :
cannot open the connection

I tested this with another port and same error occurs.

EDIT 2

I've also tried it with host 127.0.0.1 and 0.0.0.0 but no dice. According to the Travis documentation, this should work... perhaps an issue with the R container?

like image 358
mikeck Avatar asked Jun 01 '17 21:06

mikeck


1 Answers

Here is a travis.yml I use for my pyrle package. It just installs R usinq the ubuntu package manager:

language: python
python:
  - "3.6"
install:
  - pip install cython pytest hypothesis
  - sudo apt-get install -y r-base
  - echo 'source("https://bioconductor.org/biocLite.R"); biocLite("S4Vectors"); biocLite("GenomicRanges")' > install.R
  - python setup.py install

script:
  - py.test tests/

Another way is to install R through conda. Here is an example from the pyranges package:

# Stolen from http://conda.pydata.org/docs/travis.html
language: python
python:
  # We don't actually use the Travis Python, but this keeps it organized.
  - "3.6"
install:
  - sudo apt-get update
  # We do this conditionally because it saves us some downloading if the
  # version is the same.
  - wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh;
  - bash miniconda.sh -b -p $HOME/miniconda
  - export PATH="$HOME/miniconda/bin:$PATH"
  - hash -r
  - conda config --set always_yes yes --set changeps1 no
  - conda update -q conda
  - conda config --add channels bioconda
  - conda config --add channels r
  # Useful for debugging any issues with conda
  - conda info -a
  - conda create -q -n test-environment python=$TRAVIS_PYTHON_VERSION numpy scipy pandas pytest pytest-cov cython tabulate hypothesis bedtools # ray
  - source activate test-environment
  - python setup.py install # will install ncls
  - python --version
  - python -c 'import pandas as pd; print(pd.__version__)'
  - ls tests

script: py.test -v tests # verbose to see that tests run and so that travis does not time out on hypothesis tests
like image 173
The Unfun Cat Avatar answered Oct 03 '22 23:10

The Unfun Cat