简体   繁体   English

如何在travis上使用osx环境构建python项目

[英]How can I build a python project with osx environment on travis

I am trying to build osx support for a project on Travis. 我正在尝试为Travis上的项目构建osx支持。 The problem is osx don't ship python virtualenv natively. 问题是osx本身不发布python virtualenv。 Here is the issue for that. 是问题所在。 I have gone through that issue and modified my travis file accordingly. 我已经解决了这个问题并相应地修改了我的travis文件。 Still my builds are failing with osx. 我的构建仍然失败了osx。 Here is a travis build link. 是一个travis构建链接。 Here is my travis.yml file 这是我的travis.yml文件

language: python
matrix:
    include:
        # Use the built in venv for linux builds
        - os: linux
          sudo: required
          python: "2.7"
          dist: trusty

        - os: linux
          sudo: required
          python: "3.5"
          dist: trusty

        - os: linux
          sudo: required
          python: "3.6"
          dist: trusty

        # Use generic language for osx
        - os: osx
          language: generic
          python: "2.7"

        - os: osx
          language: generic
          python: "3.5"

        - os: osx
          language: generic
          python: "3.6"

before_install:
 - .travis/before_install.sh
 - mkdir $HOME/data
 - echo $PWD
 - cd $HOME/data && wget ftp://ftp.astron.nl/outgoing/Measures/WSRT_Measures.ztar && tar xf WSRT_Measures.ztar && cd -
 - echo $PWD
install:
 - export PATH="$HOME/miniconda/bin:$PATH"
 - source activate testenv
 - export CPATH="$HOME/miniconda/envs/testenv/include:$CPATH"
 - echo $CPATH
 - python setup.py develop
 - pip install -r tests/requirements.txt
 - pip install coveralls travis-sphinx
script:
 - nosetests --with-coverage
 - travis-sphinx --nowarn -s doc build

and Here is my before_install.sh file. 这是我的before_install.sh文件。

set -e
set -v

if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update; fi
if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then 
    if [[ "$TRAVIS_PYTHON_VERSION" == "2.7" ]]; then
        brew install python;
        virtualenv venv -p python;
        source venv/bin/activate;
    else
        brew install python3;
        virtualenv venv -p python3;
        source venv/bin/activate;
    fi
fi


if [ "$TRAVIS_OS_NAME" = linux ]; then
    sudo apt-get update
    MINICONDAVERSION="Linux"
else
    MINICONDAVERSION="MacOSX"
fi

if [[ "$TRAVIS_PYTHON_VERSION" == "2.7" ]]; then
  wget https://repo.continuum.io/miniconda/Miniconda2-latest-$MINICONDAVERSION-x86_64.sh -O miniconda.sh;
else
  wget https://repo.continuum.io/miniconda/Miniconda3-latest-$MINICONDAVERSION-x86_64.sh -O miniconda.sh;
  fi

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 conda-forge
# Useful for debugging any issues with conda
conda info -a
which python
conda create -q -n testenv python=$TRAVIS_PYTHON_VERSION casacore=2.3.0

echo "measures.directory: /home/travis/data" > $HOME/.casarc

It states the following error when I tried to build a conda environment. 当我尝试构建conda环境时,它会指出以下错误。

CondaValueError: invalid package specification: python=

Like @randomir recommended in the comments, 像@randomir在评论中推荐的那样,
Look at the Travis docs running python on OSX 看一下在OSX上运行pythonTravis docs
and be sure you define your TRAVIS_PYTHON_VERSION 并确保定义TRAVIS_PYTHON_VERSION

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM