-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch docs hosting to gh-pages (via doctr)
Closes #68
- Loading branch information
Showing
20 changed files
with
523 additions
and
85 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
echo "# DOCTR - deploy documentation" | ||
echo "## Generate main html documentation" | ||
tox -c tox-pyenv.ini -e docs | ||
if [[ -z "$TRAVIS_TAG" ]]; then | ||
echo "Deploying as BRANCH $TRAVIS_BRANCH" | ||
else | ||
echo "Deploying as TAG $TRAVIS_TAG" | ||
echo "## Generate documentation downloads" | ||
mkdir docs/_build/download | ||
echo "### [htmlzip]" | ||
tox -c tox-pyenv.ini -e docs -- -b html _build_htmlzip | ||
cd docs || exit | ||
mv _build_htmlzip krotov.html | ||
zip -r krotov.html.zip ./krotov.html | ||
cd ../ || exit | ||
mv docs/krotov.html.zip docs/_build/download | ||
fi | ||
# deploy with doctr | ||
echo "## pip install doctr" | ||
python -m pip install doctr | ||
echo "## doctr deploy" | ||
if [[ -z "$TRAVIS_TAG" ]]; then | ||
DEPLOY_DIR="$TRAVIS_BRANCH" | ||
else | ||
DEPLOY_DIR="$TRAVIS_TAG" | ||
fi | ||
python -m doctr deploy --key-path docs/doctr_deploy_key.enc \ | ||
--command="git show $TRAVIS_COMMIT:.travis/docs_post_process.py > post_process.py && git show $TRAVIS_COMMIT:.travis/versions.py > versions.py && python post_process.py" \ | ||
--built-docs docs/_build --no-require-master --build-tags "$DEPLOY_DIR" | ||
echo "# DOCTR - DONE" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/usr/bin/env python | ||
import os | ||
import subprocess | ||
from pathlib import Path | ||
|
||
from versions import get_versions_data, write_versions_json | ||
|
||
|
||
INDEX_HTML = r'''<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta http-equiv="Refresh" content="0; url={default_branch}" /> | ||
</head> | ||
<body> | ||
<p>Got to <a href="{default_branch}">default documentation</a>.</p> | ||
</body> | ||
</html> | ||
''' | ||
|
||
|
||
def write_index_html(default_branch): | ||
"""Write an index.html that redirects to the DEFAULT_BRANCH.""" | ||
with open("index.html", "w") as out_fh: | ||
out_fh.write(INDEX_HTML.format(default_branch=default_branch)) | ||
subprocess.run(['git', 'add', 'index.html'], check=True) | ||
|
||
|
||
def find_downloads(folder): | ||
"""Find files in the 'download' subfolder of the given `folder`.""" | ||
downloads = [] | ||
for filename in Path(folder).glob(r'download/*'): | ||
label = "".join(filename.suffixes).replace('.', '').lower() | ||
if len(label) > 0: | ||
downloads.append((label, str(filename))) | ||
return downloads | ||
|
||
|
||
def main(): | ||
"""Main function.""" | ||
print("Post-processing documentation on gh-pages") | ||
print("Gather versions info") | ||
versions_data = get_versions_data(find_downloads=find_downloads) | ||
latest_release = versions_data['latest_release'] | ||
if latest_release is None: | ||
latest_release = 'master' | ||
print("Write index.html") | ||
write_index_html(latest_release) | ||
print("Write versions.json") | ||
write_versions_json(versions_data, outfile='versions.json') | ||
print("DONE post-processing") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
selected_scheme scheme-basic | ||
TEXDIR /tmp/texlive | ||
TEXMFCONFIG ~/.texlive/texmf-config | ||
TEXMFHOME ~/texmf | ||
TEXMFLOCAL /tmp/texlive/texmf-local | ||
TEXMFSYSCONFIG /tmp/texlive/texmf-config | ||
TEXMFSYSVAR /tmp/texlive/texmf-var | ||
TEXMFVAR ~/.texlive/texmf-var | ||
option_doc 0 | ||
option_src 0 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/usr/bin/env sh | ||
|
||
# Originally from https://github.com/latex3/latex3 | ||
|
||
# This script is used for building LaTeX files using Travis | ||
# A minimal current TL is installed adding only the packages that are | ||
# required | ||
|
||
# See if there is a cached version of TL available | ||
if ! command -v texlua > /dev/null; then | ||
# Obtain TeX Live | ||
wget http://mirror.ctan.org/systems/texlive/tlnet/install-tl-unx.tar.gz | ||
tar -xzf install-tl-unx.tar.gz | ||
cd install-tl-20* | ||
|
||
# Install a minimal system | ||
./install-tl --profile=../.travis/texlive/texlive.profile | ||
|
||
cd .. | ||
fi | ||
|
||
# Just including texlua so the cache check above works | ||
tlmgr install luatex | ||
|
||
# We specify the directory in which it is located texlive_packages | ||
tlmgr install $(sed 's/\s*#.*//;/^\s*$/d' .travis/texlive/texlive_packages) | ||
|
||
# Keep no backups (not required, simply makes cache bigger) | ||
tlmgr option -- autobackup 0 | ||
|
||
# Update the TL install but add nothing new | ||
tlmgr update --self --all --no-auto-install |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# In the case you have to install LaTeX packages manually, you can check | ||
# https://www.ctan.org/pkg/some-package to see in which TeX Live package it is contained, | ||
# or use tlmgr info some-package | ||
|
||
# Base tools to compile | ||
texliveonfly latexmk | ||
|
||
# Collections | ||
collection-langeuropean | ||
collection-fontsrecommended | ||
|
||
# LuaTeX | ||
luaotfload | ||
|
||
# texliveonfly does not detect the following packages automatically | ||
minted fvextra upquote lineno xstring framed caption | ||
|
||
# project-specific | ||
cmap fncychap titlesec tabulary varwidth fancyvrb float wrapfig parskip capt-of needspace |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
"""Utilities for generating versions.json.""" | ||
import json | ||
import subprocess | ||
from pathlib import Path | ||
|
||
from pkg_resources import parse_version | ||
from pkg_resources.extern.packaging.version import LegacyVersion | ||
|
||
|
||
def get_stable(versions): | ||
"""Select the latest stable release from `versions`. | ||
If there is no stable version, return None. | ||
""" | ||
try: | ||
return sorted( | ||
[v for v in versions if not parse_version(v).is_prerelease], | ||
key=parse_version, | ||
)[-1] | ||
except IndexError: | ||
return None | ||
|
||
|
||
def _clear_broken_symlinks(): | ||
"""Clear all broken symlinks in the current directory.""" | ||
for name in Path().iterdir(): | ||
if name.is_symlink(): | ||
try: | ||
name.resolve(strict=True) | ||
except FileNotFoundError: | ||
print("Remove broken symlink %s" % name) | ||
subprocess.run(['git', 'rm', name], check=True) | ||
|
||
|
||
def write_versions_json(versions_data, outfile): | ||
"""Write the versions data to a json file. | ||
This json file will be processed by the javascript that generates the | ||
version-selector. | ||
""" | ||
with open(outfile, 'w') as out_fh: | ||
json.dump(versions_data, out_fh) | ||
print(json.dumps(versions_data, indent=2)) | ||
subprocess.run(['git', 'add', outfile], check=True) | ||
|
||
|
||
def _is_unreleased(folder): | ||
"""Default `is_unreleased` function. | ||
The following are considered "unreleased": | ||
* Anything that doesn't look like a proper version according to PEP440. | ||
Proper versions are e.g. "1.0.0", "v1.0.0", "1.0.0.post1". Specifically, | ||
any branch names like "master", "develop" are considered unreleased. | ||
* Anything that PEP440 considers a pre-release, e.g. "1.0.0-dev", "1.0-rc1" | ||
* Anything that includes a "local version identifier" according to PEP440, | ||
e.g. "1.0.0+dev" | ||
""" | ||
version = parse_version(folder) | ||
if isinstance(version, LegacyVersion): | ||
return True | ||
if version.is_prerelease: | ||
return True | ||
if version.local is not None: | ||
return True | ||
return False | ||
|
||
|
||
def _find_latest_release(folders): | ||
try: | ||
return sorted(folders, key=parse_version)[-1] | ||
except IndexError: | ||
return None | ||
|
||
|
||
def _find_downloads(folder): | ||
return [] | ||
|
||
|
||
def get_versions_data( | ||
hidden=None, | ||
is_unreleased=None, | ||
find_latest_release=None, | ||
sort_key=None, | ||
labels=None, | ||
suffix_latest_release=' (latest release)', | ||
suffix_unreleased=' (dev)', | ||
find_downloads=None, | ||
): | ||
"""Get the versions data, to be serialized to json.""" | ||
if hidden is None: | ||
hidden = [] | ||
if is_unreleased is None: | ||
is_unreleased = _is_unreleased | ||
if find_latest_release is None: | ||
find_latest_release = _find_latest_release | ||
if find_downloads is None: | ||
find_downloads = _find_downloads | ||
if sort_key is None: | ||
sort_key = parse_version | ||
if labels is None: | ||
labels = {} | ||
folders = sorted( | ||
[ | ||
str(f) | ||
for f in Path().iterdir() | ||
if ( | ||
f.is_dir() | ||
and not f.is_symlink() | ||
and not str(f).startswith('.') | ||
and not str(f).startswith('_') | ||
) | ||
], | ||
key=sort_key, | ||
) | ||
labels = {folder: labels.get(folder, str(folder)) for folder in folders} | ||
versions = [] | ||
unreleased = [] | ||
for folder in folders: | ||
if folder not in hidden: | ||
versions.append(folder) | ||
if is_unreleased(folder): | ||
unreleased.append(folder) | ||
labels[folder] += suffix_unreleased | ||
latest_release = find_latest_release( | ||
[f for f in versions if f not in unreleased] | ||
) | ||
outdated = [] | ||
if latest_release is not None: | ||
labels[latest_release] += suffix_latest_release | ||
outdated = [ | ||
folder | ||
for folder in versions | ||
if (folder != latest_release and folder not in unreleased) | ||
] | ||
versions_data = { | ||
# list of *all* folders | ||
'folders': folders, | ||
# | ||
# folder => labels for every folder in "Versions" | ||
'labels': labels, | ||
# | ||
# list folders that appear in "Versions" | ||
'versions': versions, | ||
# | ||
# list of folders that do not appear in "Versions" | ||
'hidden': hidden, | ||
# | ||
# list of folders that should warn & point to latest release | ||
'outdated': outdated, | ||
# | ||
# list of dev-folders that should warn & point to latest release | ||
'unreleased': unreleased, | ||
# | ||
# the latest stable release folder | ||
'latest_release': latest_release, | ||
# | ||
# folder => list of (label, file) | ||
'downloads': {folder: find_downloads(folder) for folder in folders}, | ||
} | ||
|
||
return versions_data |
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
Oops, something went wrong.