Skip to content

Commit

Permalink
[MRG+2] Fix conda deployments (#300)
Browse files Browse the repository at this point in the history
* Use git url

* Change windows

* Remove extra curly brace

* Temp changes for local testing

* Specify python version

* Use curly braces...

* Add root path back

* Add string back

* Add check step

* Activate env

* Update string

* Try double quotes

* Add echo

* Try adding ls to mac

* Change gitignore

* Try bld files?

* Try removing ignore installed

* Use double quotes

* Update Conda

* Add yes flag

* Add it on mac build too...

* Try dollar python

* Try dollar prefix

* Revert previous change

* Try setup.py

* Remove preprocessing on mac

* Try setting INLCUDE and LIBRARY paths

* Consolidate a bunch of stuff

* Try bld.sh

* Added echo statements

* Apparently it is build.sh

* Install dependencies

* Try dollar python

* Add cat step

* Try removing stuff from build section

* Add conda render step

* Use conda's versioning

* Fix render_meta

* Try overwriting?

* Remove numpy from build section

* Don't use dollar python

* Add set flags

* Don't use build.sh

* Make build env before building...

* Try source activate

* Try isntalling twice?

* Bring windows back

* Don't activate on unix for some reason

* Add comment

* Remove activate on windows

* Try conda-build

* Add check for lib on unix

* Fix check for lib

* Try fix windows

* Ditch lib check

* Ensure VERSION is created before building

* Clarifiying comment

* Add lib check back in

* Remove brackets

* Add lib check on all three platforms

* Fix deploy variable

* Fix for windows

* Try which

* Try 7zip on windows

* Use 7z instead of 7zip

* Try force-local

* lib -> Lib

* Ensure lib is created before deploying

* Execute file, now that we have a previous step
  • Loading branch information
aaronreidsmith committed Feb 18, 2020
1 parent 486e0f3 commit 942f284
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 133 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,4 @@ ENV/
VERSION

# Since we use a Jinja Template, we only want this to be created as build time
/conda/
meta.yaml
18 changes: 16 additions & 2 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ jobs:
architecture: '$(architecture)'
displayName: 'Setting Python version and system architecture'

- template: build_tools/azure/conda/linux.yml
- bash: echo "##vso[task.prependpath]$CONDA/bin"
displayName: 'Adding conda to PATH'

- template: build_tools/azure/conda/common.yml
- template: build_tools/azure/conda/unix.yml
- template: build_tools/azure/conda/deploy.yml

- job: Mac
Expand All @@ -75,7 +79,13 @@ jobs:
architecture: '$(architecture)'
displayName: 'Setting Python version and system architecture'

- template: build_tools/azure/conda/mac.yml
- bash: |
echo "##vso[task.prependpath]$CONDA/bin"
sudo chown -R $USER $CONDA
displayName: 'Adding conda to PATH'
- template: build_tools/azure/conda/common.yml
- template: build_tools/azure/conda/unix.yml
- template: build_tools/azure/conda/deploy.yml

- job: Windows
Expand All @@ -100,6 +110,10 @@ jobs:
architecture: '$(architecture)'
displayName: 'Setting Python version and system architecture'

- powershell: Write-Host "##vso[task.prependpath]$env:CONDA\Scripts"
displayName: 'Adding conda to PATH'

- template: build_tools/azure/conda/common.yml
- template: build_tools/azure/conda/windows.yml
- template: build_tools/azure/conda/deploy.yml

Expand Down
21 changes: 21 additions & 0 deletions build_tools/azure/conda/common.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
steps:
- script: conda update conda --yes
displayName: 'Updating Conda'

- script: conda install python=$(python.version) --yes
displayName: 'Fixing conda Python version'

- script: conda install conda-build anaconda-client --yes
displayName: 'Installing conda-build and anaconda-client'

- bash: |
mkdir conda
python -m pip install jinja2
python build_tools/azure/render_meta.py
# This line is purely for debugging
conda render --python=$(python.version) conda/
displayName: 'Rendering meta.yaml file'
- bash: make version
condition: contains(variables['Build.SourceBranch'], 'refs/tags')
displayName: 'Ensuring VERSION file is created'
3 changes: 1 addition & 2 deletions build_tools/azure/conda/deploy.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/bin/bash

# This looks like it is running `conda build` again, but it just returns the output file
output_file=$(conda-build --output --python=$(python.version) conda/)
output_file=$1

# Check our VERSION. Basically, if it contains letters, it is a pre-release. Otherwise,
# it has to match X.Y or X.Y.Z
Expand Down
7 changes: 5 additions & 2 deletions build_tools/azure/conda/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ steps:
fi
displayName: Checking for VERSION file
- bash: build_tools/azure/conda/deploy.sh
condition: and(succeeded(), eq(variables['VERSION_EXISTS'], 'true'), contains(variables['Build.SourceBranch'], 'refs/tags'))
- bash: |
# This looks like it is running `conda build` again, but it just returns the output file
output_file=$(conda-build --output --python=$(python.version) conda/)
./build_tools/azure/conda/deploy.sh $output_file
condition: and(succeeded(), eq(variables['LIB_CREATED'], 'true'), eq(variables['VERSION_EXISTS'], 'true'), contains(variables['Build.SourceBranch'], 'refs/tags'))
displayName: Deploying to conda
env:
ANACONDA_API_TOKEN: $(anacondaToken)
37 changes: 0 additions & 37 deletions build_tools/azure/conda/linux.yml

This file was deleted.

39 changes: 0 additions & 39 deletions build_tools/azure/conda/mac.yml

This file was deleted.

22 changes: 22 additions & 0 deletions build_tools/azure/conda/unix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
steps:
# A lot of our requirements don't exist on conda (scipy>1.3.3, for instance), so we pip install all of them
- bash: |
conda create --name build-env python=$(python.version) --yes
python -m pip install -r requirements.txt
displayName: 'Creating build environment'
- bash: |
source activate build-env
conda build --python=$(python.version) conda/
displayName: 'Building and testing conda distribution'
- bash: |
output_file=$(conda-build --output --python=$(python.version) conda/)
if tar -tf "$output_file" | grep "lib"; then
echo "##vso[task.setvariable variable=LIB_CREATED]true"
echo "Lib directory created properly"
else
echo "Lib directory not created"
exit 1
fi
displayName: 'Looking for lib folder'
37 changes: 12 additions & 25 deletions build_tools/azure/conda/windows.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,20 @@
steps:
- powershell: Write-Host "##vso[task.prependpath]$env:CONDA\Scripts"
displayName: 'Add conda to PATH'

- script: conda install conda-build anaconda-client --yes
displayName: 'Installing conda-build and anaconda-client'

- script: make version
displayName: 'Ensuring VERSION file is created'
condition: contains(variables['Build.SourceBranch'], 'refs/tags')

- bash: |
mkdir conda
python -m pip install jinja2
python build_tools/azure/render_meta.py
displayName: 'Rendering meta.yaml file'
# A lot of our requirements don't exist on conda (scipy>1.3.3, for instance), so we pip install all of them
# Windows is weird and fails if we try to do these as separate steps
- script: |
conda create --name build-env python=$(python.version) --yes
call activate build-env
pip install -r requirements.txt
python -m pip install -r requirements.txt
conda-build --python=$(python.version) conda/
displayName: 'Building and testing conda distribution'
# Run pmdarima.show_versions() because I don't 100% trust the conda builder
# Have to cd .. because pmdarima doesn't like importing from own dir
- bash: |
source activate build-env
cd ..
conda install --use-local pmdarima --yes
python -c "import pmdarima; pmdarima.show_versions()"
displayName: 'Testing conda installation'
output_file=$(conda-build --output --python=$(python.version) conda/)
# Windows has to use --force-local to ignore colons, and `Lib` has to be capitalized
if tar -tf "$output_file" --force-local | grep "Lib"; then
echo "##vso[task.setvariable variable=LIB_CREATED]true"
echo "Lib directory created properly"
else
echo "Lib directory not created"
exit 1
fi
displayName: 'Looking for lib folder'
31 changes: 22 additions & 9 deletions build_tools/azure/meta_template.yml.j2
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
{# This is a Jinja2 template that will render out to $ROOT/conda/meta.yaml #}
package:
name: 'pmdarima'
version: '{{ VERSION }}'
name: "pmdarima"
version: "{{ VERSION }}"

{# Path where setup.py lies from root/conda (since that is where this will be rendered) #}
source:
path: ../
git_url: ../

build:
string: 'py{{ py_version }}'
script: 'python -m pip install dist/{{ wheel }} --no-deps -vv' # [not win]
script: 'python setup.py install' # [win]
{% raw %}
number: {{ environ.get('GIT_DESCRIBE_NUMBER', 0) }}
string: py{{ CONDA_PY }}{{ environ.get('GIT_DESCRIBE_HASH', '') }}_{{ environ.get('GIT_DESCRIBE_NUMBER', 0) }}
{% endraw %}
{#
The first one here installs to the default location (which is where testing happens)
and the second one installs to $PREFIX, which is set by conda-build and is necessary
for the `lib` folder to end up in the tar.bz2
#}
script: |
python -m pip install --no-deps --ignore-installed .
python -m pip install --prefix $PREFIX --no-deps --ignore-installed .
ignore_run_exports:
- pip
- statsmodels
Expand All @@ -24,20 +33,23 @@ build:

requirements:
build:
- {{ numpy_version }}
{% raw %}
- {{ compiler('c') }}
{% endraw %}

host:
- pip
- python
{% raw %}
- python {{ PY_VER }}
{% endraw %}
{% for package in requirements %}
- {{ package }}
{% endfor %}

run:
- python
{% raw %}
- python {{ PY_VER }}
{% endraw %}
{% for package in requirements %}
- {{ package }}
{% endfor %}
Expand All @@ -48,6 +60,7 @@ test:
- pip install pytest pytest-mpl pytest-benchmark
{# Cannot use `make` in the meta.yaml file #}
- pytest --showlocals --durations=20 --pyargs pmdarima --benchmark-skip
- python -c "import pmdarima; pmdarima.show_versions()"

about:
home: https://github.com/alkaline-ml/pmdarima
Expand Down
27 changes: 11 additions & 16 deletions build_tools/azure/render_meta.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
import sys
import re

from jinja2 import Environment, FileSystemLoader
from pathlib import Path
Expand Down Expand Up @@ -28,26 +28,21 @@
VERSION = '0.0.0'

# Find the requirements and versions
# conda puts a space between packages and versions, so we have to match that
requirements = []
with open(str(REQUIREMENTS_FILE.resolve())) as file:
requirements = [line.strip() for line in file.readlines()]

# We build from source on windows, otherwise, we looks for a wheel
if sys.platform != 'win32':
wheel = next(file for file in os.listdir(str(DIST_PATH.resolve()))
if file.endswith('.whl'))
else:
wheel = None

# Numpy version is used for building
numpy_version = next(package for package in requirements if 'numpy' in package)
for line in file:
requirement = line.strip()
match = re.match(r'^([A-Za-z\-0-9]+)', requirement)
_, match_end = match.span()
package = match.group(0)
version = requirement[match_end:].replace('==', '')
requirements.append(f'{package} {version}')

# Render and write the meta.yaml file to $ROOT/conda/meta.yaml
context = {
'requirements': requirements,
'numpy_version': numpy_version,
'VERSION': VERSION,
'wheel': wheel,
'py_version': '{0.major}{0.minor}'.format(sys.version_info)
'VERSION': VERSION
}

# Ensure output directory exists
Expand Down

0 comments on commit 942f284

Please sign in to comment.