为Travis构建安装Python和R?

mik*_*eck 8 python r travis-ci

我一直在研究一个R包,它通过简单的服务器脚本和套接字连接与Python连接.我可以在我自己的机器上测试,但我也想在Travis构建上测试它(我不想完成设置Linux VM的工作).要做到这一点,我需要一个Python安装,我可以在我的R包测试中传递路径,以及要使用的端口号.

我已经看到这个答案,建议安装多个Python构建是可能的,但我不知道如何处理

  1. 指定Python可执行文件的路径
  2. 选择测试的端口号.还应该注意,我用于Python'服务器'的Python脚本使用'localhost'.

是否有可能在特拉维斯做我想做的事情?如果我想与特拉维斯做到这一点?

编辑这是我的Travis配置:

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
Run Code Online (Sandbox Code Playgroud)

以下是我的R包中的示例:

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")
}
Run Code Online (Sandbox Code Playgroud)

我的例子肯定找到了一条 Python路径,但是因错误而失败

socketConnection中的警告(port = self $ port,open ="r +",blocking = TRUE,:localhost:6011无法打开

错误socketConnection(port = self $ port,open ="r +",blocking = TRUE,:
无法打开连接

我用另一个端口测试了这个,发生了同样的错误.

编辑2

我也尝试过主机127.0.0.1,0.0.0.0但没有骰子.根据Travis的文档,这应该有用......也许是R容器的一个问题?

The*_*Cat 3

这是我用于 Pyle 包的 travis.yml。它只是使用 ubuntu 包管理器安装 R:

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/
Run Code Online (Sandbox Code Playgroud)

另一种方法是通过 conda 安装 R。这是 pyranges 包中的示例:

# 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
Run Code Online (Sandbox Code Playgroud)