python - 为 Travis 构建同时安装 Python 和 R?

标签 python r travis-ci

我一直在研究一个 R 包,它通过简单的服务器脚本和套接字连接与 Python 交互。我可以在我自己的机器上测试,但我也想在 Travis 构建上测试它(我不想经历设置 Linux VM 的努力)。为此,我需要一个 Python 安装,我可以将路径传递到我的 R 包测试中,以及一个要使用的端口号。

我看过 this answer这表明可以安装多个 Python 版本,但我不确定如何处理

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

是否可以在 Travis 上做我想做的事? 我应该和 Travis 一起做这件事吗?

编辑 这是我的 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

这是我的 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")
}

我的示例确实找到了一个 Python 路径,但失败并出现错误

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

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

编辑 2

我也用主机 127.0.0.10.0.0.0 尝试过,但没有骰子。根据 Travis 文档,这应该可行……也许是 R 容器的问题?

最佳答案

这是我用于 pyrle 包的 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/

另一种方法是通过 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

关于python - 为 Travis 构建同时安装 Python 和 R?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44317627/

相关文章:

类级别变量上的 Python 装饰器作为反射的元数据?

python - Numpy:二维数组的 reshape

c# - 如何加快从客户端到服务器的图像传输

docker - 为什么从 Travis CI 推送后 Docker 镜像没有出现在 Docker Hub 上

python - 无法使用 Django manage.py 创建 super 用户

r - 如何在 R 中绘制堆积柱形图?

r - 复制矩阵以形成列表

r - 在 R 中,有什么有效的方法可以将两个不同的多层栅格数据聚合/合并为一个吗?

php - 由于 Composer 命令调用,Travis-CI 的构建失败

travis-ci - 将 secret 环境变量添加到 Travis CI