Skip to content

Commit 750321c

Browse files
authored
Add a custom environment file for building docs on CI (#626)
Change how we install packages to build docs in Actions: instead of gathering the dependencies from the requirements files, create a new environment file that used only for that purpose. This removes the need to rename some packages that have different names in PyPI and Conda (like `build` and `python-build`), and also allows us to have more control over pinned versions of some packages, specially if some new version broke something in our workflow.
1 parent 15acbca commit 750321c

File tree

3 files changed

+50
-56
lines changed

3 files changed

+50
-56
lines changed

.github/environment.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Conda environment to build the docs in Actions.
2+
# Don't use this environment for development. This environment is solely used
3+
# by GitHub Actions to create an environment to build the documentation that
4+
# gets pushed to GitHub Pages.
5+
name: harmonica-docs
6+
channels:
7+
- conda-forge
8+
dependencies:
9+
- numpy>=1.23
10+
- pandas>=1.4
11+
- scipy>=1.9
12+
- scikit-learn>=1.1
13+
- numba>=0.57
14+
- xarray>=2022.03
15+
- verde>=1.8.1
16+
- xrft>=1.0
17+
- choclo>=0.1
18+
- boule>=0.4.1
19+
# Build
20+
- python-build
21+
- twine
22+
# Docs
23+
- sphinx==7.2.*
24+
- numpydoc==1.7.*
25+
- sphinx-book-theme==1.1.*
26+
- sphinx-gallery==0.15.*
27+
- sphinx-design==0.5.*
28+
- sphinx-copybutton==0.5.*
29+
- jupyter-sphinx==0.5.*
30+
- ipykernel
31+
- boule
32+
- pyproj
33+
- ensaio>=0.5.*
34+
- netcdf4
35+
- matplotlib
36+
- pyvista
37+
- vtk==9.4.*
38+
- pygmt
39+
- gmt
40+
- gdal
41+
- ipykernel
42+
- trame

.github/workflows/docs.yml

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ jobs:
3535
build:
3636
runs-on: ubuntu-latest
3737
env:
38-
REQUIREMENTS: env/requirements-build.txt env/requirements-docs.txt
3938
PYTHON: "3.12"
4039
ENSAIO_DATA_FROM_GITHUB: true
4140

@@ -58,47 +57,21 @@ jobs:
5857
- name: Fetch git tags
5958
run: git fetch origin 'refs/tags/*:refs/tags/*'
6059

60+
- name: Setup caching for conda packages
61+
uses: actions/cache@v5
62+
with:
63+
path: ~/conda_pkgs_dir
64+
key: conda-${{ env.PYTHON }}-${{ hashFiles('.github/environment.yml') }}
65+
6166
- name: Setup Miniforge
6267
uses: conda-incubator/setup-miniconda@835234971496cad1653abb28a638a281cf32541f
6368
with:
6469
python-version: ${{ env.PYTHON }}
6570
miniforge-version: latest
6671
channels: conda-forge
6772
conda-remove-defaults: "true"
68-
69-
- name: Collect requirements
70-
run: |
71-
echo "Install Dependente to capture dependencies:"
72-
conda install dependente==0.3.0 -c conda-forge
73-
echo ""
74-
echo "Capturing run-time dependencies:"
75-
dependente --source install > requirements-full.txt
76-
echo "Capturing dependencies from:"
77-
for requirement in $REQUIREMENTS
78-
do
79-
echo " $requirement"
80-
cat $requirement >> requirements-full.txt
81-
done
82-
echo ""
83-
echo "Collected dependencies:"
84-
cat requirements-full.txt
85-
86-
- name: Rename conda-forge packages
87-
run: |
88-
echo "Rename conda-forge packages in requirements-full.txt"
89-
# Replace "build" for "python-build"
90-
sed -s --in-place 's/^build$/python-build/' requirements-full.txt
91-
echo "Renamed dependencies:"
92-
cat requirements-full.txt
93-
94-
- name: Setup caching for conda packages
95-
uses: actions/cache@v5
96-
with:
97-
path: ~/conda_pkgs_dir
98-
key: conda-${{ runner.os }}-${{ env.PYTHON }}-${{ hashFiles('requirements-full.txt') }}
99-
100-
- name: Install requirements
101-
run: conda install --quiet --file requirements-full.txt python=$PYTHON
73+
activate-environment: harmonica-docs
74+
environment-file: .github/environment.yml
10275

10376
- name: List installed packages
10477
run: conda list

env/requirements-docs.txt

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)