Last active
July 25, 2020 15:28
-
-
Save aurieh/68013f0a908ddec0779250a60b94cda5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -eux | |
PYTHON="${PYTHON:-python3}" | |
PIPFLAGS="${PIPFLAGS:--qq}" | |
DOCSETS="${DOCSETS:-$HOME/.local/share/Zeal/Zeal/docsets}" | |
fail() { | |
echo 'pip2dash:' "$@" >&2 | |
exit 1 | |
} | |
_pip() { | |
[ "${VIRTUAL_ENV:-}" ] && _python="python" || _python="$PYTHON" | |
set -f | |
"$_python" -m pip $PIPFLAGS "$@" | |
set +f | |
} | |
# https://github.com/pypa/pip/issues/7122 | |
_fix_issue_7122() { | |
! grep -q 'does not provide the extra' | |
} | |
WORKDIR="$(mktemp -d)" | |
trap "rm -r $WORKDIR" EXIT | |
cd "$WORKDIR" | |
_pip download --no-deps --no-binary :all: "$@" | |
DESTDIR="$WORKDIR/dest" | |
mkdir -p "$DESTDIR" | |
tar -C "$DESTDIR" -xf ./*.tar.* | |
PACKAGEDIR="$(echo "$DESTDIR"/*)" | |
cd "$PACKAGEDIR" | |
"$PYTHON" -m venv .venv | |
ln -s .env env venv ENV .venv # fix hardcoded venv paths... | |
cat > .venv/bin/virtualenv <<EOF | |
import sys | |
import virtualenv | |
if virtualenv.__version__.startswith("16"): | |
main = virtualenv.main | |
else: | |
from virtual.__main__ import run_with_catch | |
def main(): | |
return run_with_catch(sys.argv) | |
if __name__ == "__main__": | |
sys.exit(main()) | |
EOF | |
chmod +x .venv/bin/virtualenv # ...and fix more stupid code | |
set +x; . .venv/bin/activate; set -x | |
_pip install virtualenv doc2dash sphinx # ...we *do* need virtualenv | |
_pip install --no-binary :all: . | |
_pip install --no-binary :all: '.[docs]' '.[doc]' '.[documentation]' 2>&1 | _fix_issue_7122 || { | |
for rlist in requirements.doc*.txt requirements/doc*.txt; do | |
# expect these to fail, thus another -q for level=CRITICAL | |
_pip -q install -r "$rlist" || continue | |
done | |
} | |
cd docs || cd doc || fail 'only sphinx docs are supported at the moment (or project has no doc[s] directory at the top level)' | |
make env || make environment || true # some projects, man... | |
make html | |
DOCDIR="$(pwd)/$(find . -type d -path '*/_build/html')" | |
ICON_IN="$(python3 -c 'import conf; print(getattr(conf, "html_favicon"))')" || { | |
curl -sLo favicon.in.png https://assets.readthedocs.org/static/images/favicon.png || ICON_IN= | |
ICON_IN=favicon.in.png | |
} | |
convert "$ICON_IN" favicon.png && ICON="$(pwd)/favicon.png" || ICON= | |
cd "$WORKDIR" | |
NAME="$(echo "$(basename "$PACKAGEDIR")" | tr '[:punct:]' - | awk -F '-' '{print $1;}')" | |
if [ "$ICON" ]; then | |
doc2dash -i "$ICON" -n "$NAME" "$DOCDIR" | |
else | |
doc2dash -n "$NAME" "$DOCDIR" | |
fi | |
cp -rf "$NAME.docset" "$DOCSETS/" | |
# vim:softtabstop=4:tabstop=4:shiftwidth=4:filetype=sh:nosmartindent |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment