Skip to content

Commit 2aa3bab

Browse files
EliEli
authored andcommitted
Changed workflow for sphinx to conda.
1 parent d8a8bff commit 2aa3bab

1 file changed

Lines changed: 58 additions & 33 deletions

File tree

.github/workflows/build_sphinx.yml

Lines changed: 58 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -23,54 +23,79 @@ jobs:
2323
build:
2424
runs-on: ubuntu-latest
2525
steps:
26+
- name: Checkout
2627
- uses: actions/checkout@v4
2728
with:
2829
fetch-depth: 0
29-
- name: Set up Python 3.11
30-
uses: actions/setup-python@v5
30+
- name: Set up micromamba (conda-forge + optional org channel)
31+
uses: mamba-org/setup-micromamba@v2
3132
with:
32-
python-version: "3.11"
33-
cache: "pip"
33+
init-shell: bash
34+
cache-downloads: true
35+
environment-name: docs
36+
create-args: >-
37+
python>=3.11
38+
sphinx
39+
sphinx-rtd-theme
40+
numpydoc
41+
condarc: |
42+
channel_priority: strict
43+
channels:
44+
- conda-forge
45+
- cadwr-dms # keep if you publish your internal deps here
3446
35-
- name: Install schimpy (no deps), then docs extras
47+
- name: Install schimpy (from conda channels)
3648
shell: bash -l {0}
3749
run: |
38-
python -m pip install --upgrade pip
39-
# install just your package (no runtime deps pulled)
40-
python -m pip install -e . --no-deps -v
50+
micromamba activate docs
51+
micromamba install -y -c conda-forge -c cadwr-dms schimpy
4152
42-
# install docs extras from pyproject if present
53+
- name: Install docs extras from pyproject.toml (resolved by conda)
54+
shell: bash -l {0}
55+
run: |
56+
micromamba activate docs
4357
python - <<'PY'
44-
import sys, subprocess, pathlib
58+
import sys, subprocess
4559
try:
46-
import tomllib # Py>=3.11
60+
import tomllib # py>=3.11
4761
except ModuleNotFoundError:
4862
subprocess.check_call([sys.executable, "-m", "pip", "install", "tomli"])
4963
import tomli as tomllib
50-
51-
pp = pathlib.Path("pyproject.toml")
52-
raw = pp.read_text(encoding="utf-8")
53-
data = tomllib.loads(raw)
64+
65+
NAME_MAP = {
66+
"Pillow": "pillow",
67+
"netCDF4": "netcdf4",
68+
# extend if any PyPI vs conda names differ
69+
}
70+
71+
data = tomllib.loads(open("pyproject.toml","rb").read())
5472
proj = data.get("project", {})
55-
opt = proj.get("optional-dependencies", {})
56-
57-
# prefer 'docs' but accept 'doc' as a fallback
58-
pkgs = opt.get("docs") or opt.get("doc")
59-
if not pkgs:
60-
print("No [project.optional-dependencies].docs (or .doc) group found; skipping docs extras.")
61-
sys.exit(0)
62-
63-
# normalize to list
64-
if isinstance(pkgs, str):
65-
pkgs = [pkgs]
66-
67-
# install the extras (with deps)
68-
cmd = [sys.executable, "-m", "pip", "install", *pkgs]
69-
print("Installing docs extras:", " ".join(pkgs))
70-
subprocess.check_call(cmd)
73+
extras = proj.get("optional-dependencies", {})
74+
docs = extras.get("docs", [])
75+
if isinstance(docs, str):
76+
docs = [docs]
77+
78+
# Convert specifiers like "pkg>=1.2" -> "pkg" for conda
79+
def to_conda_name(spec):
80+
name = spec.split()[0] # drop environment markers
81+
name = name.split(";")[0] # drop markers after semicolon
82+
name = name.split(">=")[0].split("==")[0].split("~=")[0].split("<")[0]
83+
name = name.strip()
84+
return NAME_MAP.get(name, name).lower()
85+
86+
pkgs = sorted({to_conda_name(s) for s in docs if s})
87+
if pkgs:
88+
print("Installing docs extras via conda:", pkgs, flush=True)
89+
subprocess.check_call(["micromamba","install","-y","-c","conda-forge", *pkgs])
90+
else:
91+
print("No [project.optional-dependencies].docs group found; skipping.", flush=True)
7192
PY
72-
73-
- name: Build docs
93+
94+
- name: Build Sphinx
95+
shell: bash -l {0}
96+
env:
97+
# flip to "0" if/when you want a full unmocked build
98+
DOCS_USE_MOCKS: "0"
7499
run: |
75100
sphinx-apidoc --force -o . ../schimpy -T --templatedir ./_templates
76101
make -C docsrc clean

0 commit comments

Comments
 (0)