pythonanacondacondatravis-cicontinuous-deployment

Deploying Python package on Anaconda with TravisCI


I'm trying to deploy my Python package on Anaconda using TravisCI. I've already set up the PyPi deployment, which runs fine. This is the related part of the travis.yml file:

deploy:
  provider: pypi
  username: "__token__"
  password:
    secure: ......
  on:
    tags: true
  distributions: "sdist bdist_wheel"
  skip_existing: true

after_deploy:
  - conda install conda-build
  - conda install anaconda-client
  - bash .ci/conda_upload.sh

The error happens in .ci/conda_upload.sh. Here is conda_upload.sh:

USER=myusername

mkdir ~/conda-bld
conda config --set anaconda_upload no
export CONDA_BLD_PATH=~/conda-bld
ls -l
conda build .

find $CONDA_BLD_PATH/ -name *.tar.bz2 | while read file
do
    echo $file
    anaconda -t $CONDA_UPLOAD_TOKEN upload -u $USER $file --force
done

The error message I get happens at conda build ., it cannot find setup.py file. However the previous ls -l call clearly indicates that there is a setup.py file there:

...
-rw-rw-r-- 1 travis travis     1190 Aug 15 09:42 setup.py
...

I also included

build:
  script_env:
   - CONDA_BLD_PATH

in the meta.yaml file.

Here is the full output I get on Travis:

WARNING:conda_build.metadata:No numpy version specified in conda_build_config.yaml.  Falling back to default numpy value of 1.11

Adding in variants from internal_defaults

INFO:conda_build.variants:Adding in variants from internal_defaults

Attempting to finalize metadata for pysprint

INFO:conda_build.metadata:Attempting to finalize metadata for pysprint

Collecting package metadata (repodata.json): ...working... done

Solving environment: ...working... done

Collecting package metadata (repodata.json): ...working... done

Solving environment: ...working... done

BUILD START: ['pysprint-0.12.1-py38_0.tar.bz2']

Collecting package metadata (repodata.json): ...working... done

Solving environment: ...working... done

## Package Plan ##
  environment location: /home/travis/conda-bld/pysprint_1597484753718/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl

The following NEW packages will be INSTALLED:

    # deleted this section to save space

Preparing transaction: ...working... done

Verifying transaction: ...working... done

Executing transaction: ...working... done

Collecting package metadata (repodata.json): ...working... done

Solving environment: ...working... done

/home/travis/conda-bld/pysprint_1597484753718/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/bin/python: can't open file 'setup.py': [Errno 2] No such file or directory

source tree in: /home/travis/conda-bld/pysprint_1597484753718/work

export PREFIX=/home/travis/conda-bld/pysprint_1597484753718/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl

export BUILD_PREFIX=/home/travis/conda-bld/pysprint_1597484753718/_build_env

export SRC_DIR=/home/travis/conda-bld/pysprint_1597484753718/work

Traceback (most recent call last):

  File "/home/travis/miniconda/bin/conda-build", line 11, in <module>

    sys.exit(main())

  File "/home/travis/miniconda/lib/python3.8/site-packages/conda_build/cli/main_build.py", line 474, in main

    execute(sys.argv[1:])

  File "/home/travis/miniconda/lib/python3.8/site-packages/conda_build/cli/main_build.py", line 463, in execute

    outputs = api.build(args.recipe, post=args.post, test_run_post=args.test_run_post,

  File "/home/travis/miniconda/lib/python3.8/site-packages/conda_build/api.py", line 208, in build

    return build_tree(absolute_recipes, config, stats, build_only=build_only, post=post,

  File "/home/travis/miniconda/lib/python3.8/site-packages/conda_build/build.py", line 2859, in build_tree

    packages_from_this = build(metadata, stats,

  File "/home/travis/miniconda/lib/python3.8/site-packages/conda_build/build.py", line 1994, in build

    utils.check_call_env(cmd, env=env, rewrite_stdout_env=rewrite_env,

  File "/home/travis/miniconda/lib/python3.8/site-packages/conda_build/utils.py", line 405, in check_call_env

    return _func_defaulting_env_to_os_environ('call', *popenargs, **kwargs)

  File "/home/travis/miniconda/lib/python3.8/site-packages/conda_build/utils.py", line 385, in _func_defaulting_env_to_os_environ

    raise subprocess.CalledProcessError(proc.returncode, _args)

subprocess.CalledProcessError: Command '['/bin/bash', '-o', 'errexit', '/home/travis/conda-bld/pysprint_1597484753718/work/conda_build.sh']' returned non-zero exit status 2.

The problem seems to be that the environment location is set to

environment location: /home/travis/conda-bld/pysprint_1597484753718/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl

but I can't figure out how to solve this. I'm pretty new to linux environments and shell scripting, I'd appreciate if anyone could help me out.

EDIT: Contents of meta.yaml:

{% set name = "pysprint" %}
{% set version = "0.12.1" %}

package:
  name: "{{ name|lower }}"
  version: "{{ version }}"

source:
  url: "https://pypi.org/packages/source/{{ name[0] }}/{{ name }}/{{ name }}-{{ version }}.tar.gz"
  sha256: 5fee159c59c81fd31957e23bbd292bcfc1c947583f27eda7f4215594ec898ddd

build:
  script_env:
   - CONDA_BLD_PATH

requirements:
  host:
    - matplotlib
    - numpy >=1.16.6
    - pandas
    - pip
    - python
    - scipy

test:
  imports:
    - pysprint

Solution

  • It turns out that the deploy section somehow messes up the conda deployment. I changed the after_deploy section to before_deploy and it works.

    before_deploy:
      - conda install conda-build
      - conda install anaconda-client
      - bash .ci/conda_upload.sh
    
    deploy:
      provider: pypi
      username: "__token__"
      password:
        secure: ......
      on:
        tags: true
      distributions: "sdist bdist_wheel"
      skip_existing: true
    

    However it is not clear to me at all what causes the issue.