Skip to content

Commit

Permalink
move draft generation to conf.py from tox - this way will work in rea…
Browse files Browse the repository at this point in the history
…dthedocs
  • Loading branch information
gaborbernat committed Jun 25, 2018
1 parent 3b459d2 commit 906b6f2
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ htmlcov
py27/

.*_cache
_draft.rst
2 changes: 1 addition & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ on Github:
folder. If necessary, the generated text can be edited afterwards to e.g. merge rc changes
into the final release notes.
.. include:: ../.tox/docs_out/draft_changelog.rst
.. include:: ../_draft.rst

.. towncrier release notes start
Expand Down
25 changes: 23 additions & 2 deletions doc/conf.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,38 @@
import os
import sys
import re
import subprocess
from datetime import date
from pathlib import Path

from pkg_resources import get_distribution

sys.path.insert(0, os.path.dirname(__file__))
DOC_DIR = Path(__file__).parents[1]
extensions = [
"sphinx.ext.autodoc",
"sphinx.ext.extlinks",
"sphinx.ext.intersphinx",
"sphinx.ext.viewcode",
]


def generate_draft_news():
home = "https://github.com"
issue = "{}/issue".format(home)
fragments_path = DOC_DIR / "changelog"
for pattern, replacement in (
(r"[^`]@([^,\s]+)", r"`@\1 <{}/\1>`_".format(home)),
(r"[^`]#([\d]+)", r"`#pr\1 <{}/\1>`_".format(issue)),
):
for path in fragments_path.glob("*.rst"):
path.write_text(re.sub(pattern, replacement, path.read_text()))
changelog = subprocess.check_output(
["towncrier", "--draft", "--version", "DRAFT"], cwd=str(DOC_DIR)
)
(DOC_DIR / "_draft.rst").write_bytes(changelog)


generate_draft_news()

project = u"tox"
_full_version = get_distribution(project).version
release = _full_version.split("+", 1)[0]
Expand Down
4 changes: 1 addition & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ passenv = *
basepython = python3.6
extras = docs
changedir = {toxinidir}
commands = python tasks/pre-process-changelog.py
python -c 'import subprocess; from pathlib import Path; Path("{toxworkdir}/docs_out/draft_changelog.rst").write_bytes(subprocess.check_output(["towncrier", "--draft", "--version", "DRAFT"]))'
sphinx-build -d "{toxworkdir}/docs_doctree" doc "{toxworkdir}/docs_out" --color -W -bhtml {posargs}
commands = sphinx-build -d "{toxworkdir}/docs_doctree" doc "{toxworkdir}/docs_out" --color -W -bhtml {posargs}
python -m webbrowser -t "{toxworkdir}/docs_out/index.html"

[testenv:fix-lint]
Expand Down

0 comments on commit 906b6f2

Please sign in to comment.