2017-04-10 25 views
0

我有一個使用需要構建的庫的python項目。鑑於我使用了蟒蛇。我想爲travis創建一個計劃,讓我測試多個python版本,但我無法做到這一點。以下是我有:帶有anaconda和travis的多個python版本

  • 我想測試它針對多個版本的Python(如2.7,3.5,3.6)
  • 我有requirements.yml文件,它看起來像以下:
channels: 
     - kne 
    dependencies: 
     - numpy 
     - pytest 
     - numpy 
     - scipy 
     - matplotlib 
     - seaborn 
     - pybox2d 
     - pip: 
     - gym 
     - codecov 
     - pytest 
     - pytest-cov 

.travis.yml包含:

language: python 

# sudo false implies containerized builds 
sudo: false 

python: 
    - 3.5 
    - 3.4 

before_install: 
# Here we download miniconda and install the dependencies 
- export MINICONDA=$HOME/miniconda 
- export PATH="$MINICONDA/bin:$PATH" 
- hash -r 
- wget http://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh -O miniconda.sh 
- bash miniconda.sh -b -f -p $MINICONDA 
- conda config --set always_yes yes 
- conda update conda 
- conda info -a 
- echo "Python version var" 
- echo $TRAVIS_PYTHON_VERSION 
- conda env create -n testenv -f environment.yml python=$TRAVIS_PYTHON_VERSION 
- source activate testenv 

install: 
- python setup.py install 

script: 
- python --version 
- python -m pytest --cov=. 
- codecov 

如果我把Python版本放入environment.yml它工作正常,但我不能使用多個python版本。對我而言,如果提供-f,它似乎會忽略列出的任何其他軟件包conda env create

此外,env創建後添加- conda install -n testenv python=$TRAVIS_PYTHON_VERSION不起作用。

UnsatisfiableError: The following specifications were found to be in conflict: 
    - functools32 -> python 2.7.* 
    - python 3.5* 
Use "conda info <package>" to see the dependencies for each package. 

我該怎麼辦,爲了讓它工作?

//如果你想看到更多的細節,它可以在這裏找到:https://travis-ci.org/mbednarski/Chiron/jobs/220644726

回答

1

您可以使用sed修改創建暢達環境之前在environment.yml文件蟒蛇依賴。

包括在environment.yml蟒蛇:

channels: 
    - kne 
dependencies: 
    - python=3.6 
    - numpy 
    - pytest 
    - numpy 
    - scipy 
    - matplotlib 
    - seaborn 
    - pybox2d 
    - pip: 
     - gym 
     - codecov 
     - pytest 
     - pytest-cov 

然後修改您的.travis.yml:

before_install: 
    # Here we download miniconda and install the dependencies 
    - export MINICONDA=$HOME/miniconda 
    - export PATH="$MINICONDA/bin:$PATH" 
    - hash -r 
    - wget http://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh -O miniconda.sh 
    - bash miniconda.sh -b -f -p $MINICONDA 
    - conda config --set always_yes yes 
    - conda update conda 
    - conda info -a 
    - echo "Python version var" 
    - echo $TRAVIS_PYTHON_VERSION 
    # Edit the environment.yml file for the target Python version 
    - sed -i -E 's/(python=)(.*)/\1'$TRAVIS_PYTHON_VERSION'/' ./environment.yml 
    - conda env create -n testenv -f environment.yml 
    - source activate testenv 

sed正則表達式將替換文本蟒蛇= 3.6具有同等的目標python版本。

BTW:我在你的倉庫中看到你已經使用多個environment.yml文件解決了這個問題。這看起來是合理的,甚至對於某些依賴關係來說也是必需的,但是對於許多Python版本來說可能很乏味。