Skip to content

Commit 4084012

Browse files
EliEli
authored andcommitted
Moved irritating HEREDOC section to separate script.
1 parent fbb54e2 commit 4084012

2 files changed

Lines changed: 39 additions & 45 deletions

File tree

.github/workflows/build_sphinx.yml

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -48,53 +48,9 @@ jobs:
4848
shell: bash -l {0}
4949
run: |
5050
micromamba activate docs
51+
python scripts/install_extras.py
5152
micromamba install -y -c conda-forge -c cadwr-dms schimpy
5253
53-
- name: Install docs extras from pyproject.toml (resolved by conda)
54-
shell: bash -l {0}
55-
run: |
56-
micromamba activate docs
57-
python - <<'PY'
58-
import sys, subprocess
59-
try:
60-
import tomllib # py>=3.11
61-
with open("pyproject.toml", "rb") as f: # NOTE: use load() with binary file
62-
data = tomllib.load(f)
63-
except ModuleNotFoundError:
64-
subprocess.check_call([sys.executable, "-m", "pip", "install", "tomli"])
65-
import tomli as tomllib
66-
with open("pyproject.toml", "rb") as f:
67-
data = tomllib.load(f)
68-
69-
NAME_MAP = {
70-
"Pillow": "pillow",
71-
"netCDF4": "netcdf4",
72-
# extend if any PyPI vs conda names differ
73-
}
74-
75-
proj = data.get("project", {})
76-
extras = proj.get("optional-dependencies", {})
77-
docs = extras.get("docs", [])
78-
if isinstance(docs, str):
79-
docs = [docs]
80-
81-
pkgs = set()
82-
for s in docs:
83-
if s:
84-
name = s.split()[0]
85-
name = name.split(";")[0]
86-
name = name.split(">=")[0].split("==")[0].split("~=")[0].split("<")[0]
87-
name = name.strip()
88-
name = NAME_MAP.get(name, name).lower()
89-
pkgs.add(name)
90-
pkgs = sorted(pkgs)
91-
if pkgs:
92-
print("Installing docs extras via conda:", pkgs, flush=True)
93-
subprocess.check_call(["micromamba","install","-y","-c","conda-forge",*pkgs])
94-
else:
95-
print("No [project.optional-dependencies].docs group found; skipping.", flush=True)
96-
PY
97-
9854
- name: Build Sphinx
9955
shell: bash -l {0}
10056
env:

scripts/install_docs_extras.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# scripts/install_docs_extras.py
2+
3+
# This script is used by the documentation action on GitHub
4+
# for installing things in the docs optional dependencies
5+
# in pyproject.toml
6+
import sys, subprocess, pathlib
7+
8+
try:
9+
import tomllib # Py>=3.11
10+
except ModuleNotFoundError:
11+
subprocess.check_call([sys.executable, "-m", "pip", "install", "tomli"])
12+
import tomli as tomllib
13+
14+
NAME_MAP = {
15+
"Pillow": "pillow",
16+
"netCDF4": "netcdf4",
17+
}
18+
19+
pp = pathlib.Path("pyproject.toml")
20+
data = tomllib.loads(pp.read_bytes())
21+
proj = data.get("project", {})
22+
extras = proj.get("optional-dependencies", {})
23+
docs = extras.get("docs", [])
24+
if isinstance(docs, str):
25+
docs = [docs]
26+
27+
def to_conda_name(spec: str) -> str:
28+
name = spec.split()[0]
29+
name = name.split(";")[0]
30+
name = name.split(">=")[0].split("==")[0].split("~=")[0].split("<")[0]
31+
return NAME_MAP.get(name.strip(), name.strip()).lower()
32+
33+
pkgs = sorted({to_conda_name(s) for s in docs if s})
34+
if pkgs:
35+
print("Installing docs extras via conda:", pkgs, flush=True)
36+
subprocess.check_call(["micromamba","install","-y","-c","conda-forge", *pkgs])
37+
else:
38+
print("No [project.optional-dependencies].docs group found; skipping.", flush=True)

0 commit comments

Comments
 (0)