Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to run script to generate docs #104

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions __tests__/integration/fixtures/ok-with-hook/docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Neptunia vapor

## Has mente et

Lorem markdownum aequora Famemque, a ramos regna Ulixem verba, posito qui
nubilus membra. Pendet dixit canisve, hanc quoque animosa **veni**, inducere.
Fer quem, mihi vallem; reposcunt aequoreae Haec, inposita. Eras dicere sic! Ore
ad at nec pius rivi pectora Pandione amari pietas Ulixem.

> Argenteus sinit. Corpore non Booten Uranie, in hac has dixi herbas. *Oculos
> omnes Dixerat* suae coloribus et antris spernitque silva, dixit.

Mihi [quamvis](http://caput-latebris.com/), ardua venit nam, de mox in et inquit
incisa relevare reseminet Cycnus forma sororis. In mater artus utque iustis me
vestrae magno datque, quaque multumque oscula iubemur.

## Aditumque ubi

Brevibus cervice inmunibus sunt peragit, [sua tanto
insuper](http://ampycuslyncides.org/), arva ubi: torto mixta. Sanguis
conscendunt sumit, utilis illo nec quaecumque ad urbis inpositaque. Alto sic
esse resumere albet, pharetras sola, erat, [non longo
paviunt](http://verba.org/) dives aurem. Nomina genus nulli insignia, carpere
dare quo vident, *nox flemus sed* Telamon auras, erant illuc, tantum. Regia
[duroque opto](http://www.flectathiberi.io/estredeunt), segetes paterna de
crimen!

var edutainment_php = plain_ring_scan(adfUgcImap * delPanel);
var click_meta_dv = 3 +
systemScrollingDocument.snippetCdAnimated.memoryInstallHost(service(
bezel_trojan_plagiarism, 1, base_resources), intelligence,
umlWiSkin.software_olap.on(quadHocData));
var bare = jumper_server_solid - rupE + 3;
var timeRegistryStandby = disk_ppc_menu + gigahertzCifsRss;
if (im(correction_desktop, disk_integer_soft(serviceLogic, data_zone,
daw_ssid_web)) > graphicsExpansionBug + active) {
apiSpam = storageVisual + 3;
}

Mors cum cum proturbat, gente nasci Semiramis sonum, toto est eris facto dapibus
propulit; a! Rogantis ira canat, [in nec
sanguine](http://acceptiordefensus.io/accepto) probro inmunesque molliter
sustineat quem quamquam parentis non. Per **quod nec** rapit ipsa nec,
territaque fallacis fluviis progenies aratro. Colla puer regesta si Haec
silentia omen Paeonia, harenis puer Marmaridae pectora ingens miratur Thisbes
veri. Plaga profugi, iram, praestans, pro hanc vehit, vites.

Illa per acerris vivit difficile pulveris, faciebat pontus populabile utque? In
flagrant umbrae marito, coniunx parari, **quoque sanguine Nisi**, ego
[saxo](http://cervice-fessusque.com/), fovet, ait unda contigit. Gaudet in,
herba quibus? Ore ne ambo mecumque pectoraque alta: viri illi in puer corpore
expersque pharetra solutum proximitas. Gorgonis adempto, in montes terga quae
nec remoratur nives perque insidias exsiluit tribuitque mille.
10 changes: 10 additions & 0 deletions __tests__/integration/fixtures/ok-with-hook/mkdocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
site_name: "Example"

docs_dir: ./docs

plugins:
- monorepo

nav:
- Home: index.md
- project-1: "!include project-2/mkdocs.yml"
11 changes: 11 additions & 0 deletions __tests__/integration/fixtures/ok-with-hook/project-1/mkdocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@


nav:
- Home: index.md
- About: about.md


mono_docs_hook:
hook:
- my_hook.py
- $TEMP_DOCS_DIR
16 changes: 16 additions & 0 deletions __tests__/integration/fixtures/ok-with-hook/project-1/my_hook.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import sys
from pathlib import Path

temp_docs_dir = Path(sys.argv[1])

with open(temp_docs_dir / "index.md", "w") as md_f:
md_f.writelines([
"# Hello",
"Welcome to project 1's docs!"
])

with open(temp_docs_dir / "about.md", "w") as md_f:
md_f.writelines([
"# About",
"This is the about page."
])
12 changes: 12 additions & 0 deletions __tests__/integration/fixtures/ok-with-hook/project-2/mkdocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@


nav:
- Home: index.md
- About: about.md


mono_docs_hook:
cwd: ../project-1
hook:
- my_hook.py
- $TEMP_DOCS_DIR
9 changes: 9 additions & 0 deletions __tests__/integration/test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,15 @@ teardown() {
[[ "$output" == *"This contains a sentence which only exists in the ok-include-wildcard/project-b fixture."* ]]
}

@test "builds a mkdocs site with hooks" {
cd ${fixturesDir}/ok-with-hook
assertSuccessMkdocs build
assertFileExists site/project-1/index.html
assertFileExists site/project-1/about.html
assertFileExists site/project-2/index.html
assertFileExists site/project-2/about.html
}

@test "fails if !include path is above current folder" {
cd ${fixturesDir}/error-include-path-is-parent
assertFailedMkdocs build
Expand Down
4 changes: 2 additions & 2 deletions __tests__/test-local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

# Lint via flake8
echo "Running flake8 linter -------->"
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics --exclude=setup.py
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics --exclude=setup.py
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics --exclude=setup.py,venv,env,.venv,.env
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics --exclude=setup.py,venv,env,.venv,.env

# Running unit-tests
python3 -m unittest
Expand Down
30 changes: 25 additions & 5 deletions mkdocs_monorepo_plugin/merger.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@
import os
from os.path import join
from pathlib import Path
import subprocess

from mkdocs.utils import warning_filter
from mkdocs.utils import warning_filter, yaml_load

log = logging.getLogger(__name__)
log.addFilter(warning_filter)


TEMP_DOCS_DIR = "TEMP_DOCS_DIR"

# This collects the multiple docs/ folders and merges them together.


Expand All @@ -33,11 +37,11 @@ def __init__(self, config):
self.config = config
self.root_docs_dir = config['docs_dir']
self.docs_dirs = list()
self.append('', self.root_docs_dir)
self.append('', self.root_docs_dir, getattr(config, "config_file_path", Path("mkdocs.yml")))
self.files_source_dir = dict()

def append(self, alias, docs_dir):
self.docs_dirs.append([alias, docs_dir])
def append(self, alias, docs_dir, yaml_file):
self.docs_dirs.append([alias, docs_dir, yaml_file])

def merge(self):
self.temp_docs_dir = TemporaryDirectory('', 'docs_')
Expand All @@ -50,7 +54,9 @@ def merge(self):
"Current registered site names in the monorepository: {}".format(', '.join(aliases)))
raise SystemExit(1)

for alias, docs_dir in self.docs_dirs:
for alias, docs_dir, yaml_file in self.docs_dirs:
with open(yaml_file) as f:
config = yaml_load(f)
source_dir = docs_dir
if len(alias) == 0:
dest_dir = self.temp_docs_dir.name
Expand All @@ -60,6 +66,20 @@ def merge(self):

if os.path.exists(source_dir):
copy_tree(source_dir, dest_dir)
mono_docs_hook = config.get("mono_docs_hook", {})
hook, python_path = mono_docs_hook.get("hook"), mono_docs_hook.get("python_path")
cwd = mono_docs_hook.get("cwd")
project_dir = Path(docs_dir).parent
if cwd and not cwd.is_absolute():
cwd = project_dir / cwd
if mono_docs_hook and hook:
comp_proc = subprocess.run(
f"{python_path or 'python'} {' '.join(hook)}",
cwd=Path(cwd).resolve() if cwd else project_dir,
env={TEMP_DOCS_DIR: dest_dir, **os.environ.copy()},
shell=True
)
comp_proc.check_returncode()
for file_abs_path in Path(source_dir).rglob('*.md'):
file_abs_path = str(file_abs_path) # python 3.5 compatibility
if os.path.isfile(file_abs_path):
Expand Down
2 changes: 1 addition & 1 deletion mkdocs_monorepo_plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def on_config(self, config):
self.aliases = {}
for alias, docs_dir, yaml_file in resolvedPaths:
self.aliases[alias] = { 'docs_dir': docs_dir, 'yaml_file': yaml_file }
self.merger.append(alias, docs_dir)
self.merger.append(alias, docs_dir, yaml_file)
new_docs_dir = self.merger.merge()

# Update the docs_dir with our temporary one!
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

setuptools.setup(
name='mkdocs-monorepo-plugin',
version='1.0.5',
version='1.0.6',
description='Plugin for adding monorepository support in Mkdocs.',
long_description="""
This introduces support for the !include syntax in mkdocs.yml, allowing you to import additional Mkdocs navigation.
Expand Down