Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace conda for pip on Actions and split requirements files #282

Merged
merged 11 commits into from
Nov 19, 2021
45 changes: 19 additions & 26 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ jobs:
build:
runs-on: ubuntu-latest
env:
CONDA_REQUIREMENTS: requirements.txt
CONDA_REQUIREMENTS_DEV: requirements-dev.txt
CONDA_REQUIREMENTS_DOC: requirements-doc.txt
PYTHON: 3.8
REQUIREMENTS: requirements.txt env/requirements-docs.txt
PYTHON: 3.9

steps:
# Cancel any previous run of the test job
Expand Down Expand Up @@ -83,28 +81,13 @@ jobs:

- name: Install requirements
run: |
requirements_file=full-conda-requirements.txt
if [ ! -z "$CONDA_REQUIREMENTS" ]; then
echo "Capturing dependencies from $CONDA_REQUIREMENTS"
cat $CONDA_REQUIREMENTS >> $requirements_file
fi
if [ ! -z "$CONDA_REQUIREMENTS_DEV" ]; then
echo "Capturing dependencies from $CONDA_REQUIREMENTS_DEV"
cat $CONDA_REQUIREMENTS_DEV >> $requirements_file
fi
if [ ! -z "$CONDA_REQUIREMENTS_DOC" ]; then
echo "Capturing dependencies from $CONDA_REQUIREMENTS_DOC"
cat $CONDA_REQUIREMENTS_DOC >> $requirements_file
fi
if [ "$DEPENDENCIES" == "optional" ]; then
echo "Capturing optional dependencies from $CONDA_REQUIREMENTS_OPTIONAL"
cat $CONDA_REQUIREMENTS_OPTIONAL >> $requirements_file
fi
if [ ! -z "$CONDA_INSTALL_EXTRA" ]; then
echo "Capturing extra dependencies: $CONDA_INSTALL_EXTRA"
echo "# Extra" >> $requirements_file
# Use xargs to print one argument per line
echo $CONDA_INSTALL_EXTRA | xargs -n 1 >> $requirements_file
requirements_file=requirements-full.txt
if [ ! -z "$REQUIREMENTS" ]; then
echo "Capturing dependencies from $REQUIREMENTS"
for requirement in $REQUIREMENTS
do
cat $requirement >> $requirements_file
done
fi
if [ -f $requirements_file ]; then
echo "Collected dependencies:"
Expand All @@ -128,6 +111,16 @@ jobs:
- name: Install the package
run: pip install --no-deps dist/*.whl

- name: Copy test data to cache
run: |
echo "Copy data to " $HARMONICA_DATA_DIR/master
set -x -e
mkdir -p $HARMONICA_DATA_DIR/master
cp -r data/* $HARMONICA_DATA_DIR/master
env:
# Define directory where sample data will be copied
HARMONICA_DATA_DIR: ${{ runner.temp }}/cache/harmonica

- name: Build the documentation
run: make -C doc clean all

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: "3.8"
python-version: "3.9"

- name: Install requirements
run: python -m pip install setuptools twine wheel
run: python -m pip install -r env/requirements-build.txt

- name: List installed packages
run: python -m pip freeze
Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: "3.8"
python-version: "3.9"

- name: Install requirements
run: pip install black>=20.8b1
run: pip install -r env/requirements-style.txt

- name: List installed packages
run: pip freeze
Expand All @@ -51,10 +51,10 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: "3.8"
python-version: "3.9"

- name: Install requirements
run: pip install flake8
run: pip install -r env/requirements-style.txt

- name: List installed packages
run: pip freeze
Expand All @@ -74,10 +74,10 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: "3.8"
python-version: "3.9"

- name: Install requirements
run: pip install pylint==2.4.*
run: pip install -r env/requirements-style.txt

- name: List installed packages
run: pip freeze
Expand All @@ -97,10 +97,10 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: "3.8"
python-version: "3.9"

- name: Install requirements
run: pip install pathspec
run: pip install -r env/requirements-style.txt

- name: List installed packages
run: pip freeze
Expand Down
75 changes: 32 additions & 43 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,26 @@ defaults:
# The -l {0} is necessary for conda environments to be activated
# But this breaks on MacOS if using actions/setup-python:
# https:/actions/setup-python/issues/132
shell: bash -l {0}
shell: bash

jobs:
#############################################################################
# Run tests and upload to codecov
test:
name: ${{ matrix.os }} py${{ matrix.python }} ${{ matrix.dependencies }}
name: ${{ matrix.os }} py${{ matrix.python }}
runs-on: ${{ matrix.os }}-latest
strategy:
# Otherwise, the workflow would stop if a single job fails. We want to
# run all of them to catch failures in different combinations.
fail-fast: false
matrix:
os: [ubuntu, macos, windows]
python: [3.6, 3.9]
python: ["3.6", "3.9"]
# If "optional", will install non-required dependencies in the build
# environment. Otherwise, only required dependencies are installed.
dependencies: [""]
env:
# Define directory where sample data will be copied
CONDA_REQUIREMENTS: requirements.txt
CONDA_REQUIREMENTS_DEV: requirements-dev.txt
CONDA_INSTALL_EXTRA: ""
DEPENDENCIES: ${{ matrix.dependencies }}
REQUIREMENTS: requirements.txt env/requirements-tests.txt
# Used to tag codecov submissions
OS: ${{ matrix.os }}
PYTHON: ${{ matrix.python }}
Expand Down Expand Up @@ -78,56 +74,48 @@ jobs:
- name: Fetch git tags
run: git fetch origin 'refs/tags/*:refs/tags/*'

- name: Setup caching for conda packages
uses: actions/cache@v2
- name: Setup Python
uses: actions/setup-python@v2
with:
path: ~/conda_pkgs_dir
key: conda-${{ runner.os }}-${{ matrix.python }}-${{ hashFiles('requirements*.txt') }}
python-version: ${{ matrix.python }}

- name: Setup Miniconda
uses: conda-incubator/[email protected]
- name: Get the pip cache folder
id: pip-cache
run: |
echo "::set-output name=dir::$(pip cache dir)"

- name: Setup caching for pip packages
uses: actions/cache@v2
with:
python-version: ${{ matrix.python }}
miniconda-version: "latest"
auto-update-conda: true
channels: conda-forge
show-channel-urls: true
activate-environment: testing
# Needed for caching
use-only-tar-bz2: true
path: ${{ steps.pip-cache.outputs.dir }}
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements*.txt') }}
restore-keys: |
${{ runner.os }}-pip-${{ hashFiles('**/requirements*.txt') }}

- name: Install requirements
run: |
requirements_file=full-conda-requirements.txt
if [ ! -z "$CONDA_REQUIREMENTS" ]; then
echo "Capturing dependencies from $CONDA_REQUIREMENTS"
cat $CONDA_REQUIREMENTS >> $requirements_file
fi
if [ ! -z "$CONDA_REQUIREMENTS_DEV" ]; then
echo "Capturing dependencies from $CONDA_REQUIREMENTS_DEV"
cat $CONDA_REQUIREMENTS_DEV >> $requirements_file
fi
if [ "$DEPENDENCIES" == "optional" ]; then
echo "Capturing optional dependencies from $CONDA_REQUIREMENTS_OPTIONAL"
cat $CONDA_REQUIREMENTS_OPTIONAL >> $requirements_file
fi
if [ ! -z "$CONDA_INSTALL_EXTRA" ]; then
echo "Capturing extra dependencies: $CONDA_INSTALL_EXTRA"
echo "# Extra" >> $requirements_file
# Use xargs to print one argument per line
echo $CONDA_INSTALL_EXTRA | xargs -n 1 >> $requirements_file
requirements_file=requirements-full.txt
if [ ! -z "$REQUIREMENTS" ]; then
echo "Capturing dependencies from $REQUIREMENTS"
for requirement in $REQUIREMENTS
do
cat $requirement >> $requirements_file
done
fi
if [ -f $requirements_file ]; then
echo "Collected dependencies:"
cat $requirements_file
echo ""
conda install --quiet --file $requirements_file python=$PYTHON
# Install wheel before anything else so pip can use wheels for
# other packages.
python -m pip install -r env/requirements-build.txt
python -m pip install -r $requirements_file
else
echo "No requirements defined."
fi

- name: List installed packages
run: conda list
run: python -m pip freeze

- name: Build source and wheel distributions
run: |
Expand Down Expand Up @@ -167,8 +155,9 @@ jobs:
run: coverage xml

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v2
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage.xml
env_vars: OS,PYTHON
# Don't mark the job as failed if the upload fails for some reason.
Expand Down
2 changes: 1 addition & 1 deletion MAINTENANCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ The main advantages of this are:
We use GitHub Actions continuous integration (CI) services to build and
test the project on Windows, Linux, and Mac.
The configuration files for this service are in `.github/workflows`.
They rely on the `requirements.txt`, `requirements-optional.txt`, etc
They rely on the `requirements.txt` and `env/requirements-*.txt`
files to install the required dependencies using conda or pip.

The CI jobs include:
Expand Down
5 changes: 5 additions & 0 deletions env/requirements-build.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Requirements to build and check distributions
twine
wheel
setuptools
setuptools_scm
4 changes: 4 additions & 0 deletions requirements-doc.txt → env/requirements-docs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
sphinx==3.5.*
sphinx-book-theme==0.0.41
sphinx-gallery==0.8.*
boule
pyproj
matplotlib
cartopy>=0.18
5 changes: 5 additions & 0 deletions env/requirements-style.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Requirements for checking code style
black
flake8
pylint
pathspec
5 changes: 5 additions & 0 deletions env/requirements-tests.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Requirements for running the tests
boule
pytest
pytest-cov
coverage
11 changes: 0 additions & 11 deletions requirements-dev.txt

This file was deleted.