annotate garcon/documentation.py @ 1051:971b4d67e82a

serve: Fix problems with assets disappearing between servings. When an asset file changes, its source's pipeline is re-run. But that created a bake record that only had that pipeline's output, so the other outputs were incorrectly considered empty and therefore any stray files were removed. Now we copy over bake records for the pipelines we don't run.
author Ludovic Chabant <ludovic@chabant.com>
date Fri, 26 Jan 2018 18:05:02 -0800
parents 22cf13b86cc3
children bd6cc78666b7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
642
79aefe82c6b6 cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1 import os
79aefe82c6b6 cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
2 import os.path
670
a409a7bb3948 cm: Improve documentation generation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 647
diff changeset
3 import re
a409a7bb3948 cm: Improve documentation generation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 647
diff changeset
4 import sys
642
79aefe82c6b6 cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
5 from invoke import task, run
79aefe82c6b6 cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
6
79aefe82c6b6 cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
7
670
a409a7bb3948 cm: Improve documentation generation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 647
diff changeset
8 pyver_re = re.compile('^Python (?P<maj>\d)\.(?P<min>\d)\.(?P<pat>\d)$')
a409a7bb3948 cm: Improve documentation generation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 647
diff changeset
9
a409a7bb3948 cm: Improve documentation generation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 647
diff changeset
10
a409a7bb3948 cm: Improve documentation generation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 647
diff changeset
11 @task(help={
a409a7bb3948 cm: Improve documentation generation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 647
diff changeset
12 'tmp_dir': "The directory in which to bake the docs temporarily.",
a409a7bb3948 cm: Improve documentation generation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 647
diff changeset
13 'out_dir': "If the bake is successful, the directory in which to deploy "
a409a7bb3948 cm: Improve documentation generation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 647
diff changeset
14 "the files at the end.",
a409a7bb3948 cm: Improve documentation generation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 647
diff changeset
15 'root_url': "Set the docs site root URL to this if needed.",
a409a7bb3948 cm: Improve documentation generation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 647
diff changeset
16 'venv_dir': "The directory of the virtual environment to use to run "
a409a7bb3948 cm: Improve documentation generation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 647
diff changeset
17 "PieCrust."
a409a7bb3948 cm: Improve documentation generation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 647
diff changeset
18 })
990
22cf13b86cc3 cm: Upgrade Garcon tasks to the latest PyInvoke version.
Ludovic Chabant <ludovic@chabant.com>
parents: 800
diff changeset
19 def gendocs(ctx, tmp_dir=None, out_dir=None, root_url=None, venv_dir=None):
670
a409a7bb3948 cm: Improve documentation generation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 647
diff changeset
20 base_dir = os.path.abspath(
a409a7bb3948 cm: Improve documentation generation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 647
diff changeset
21 os.path.join(os.path.dirname(__file__), '..'))
a409a7bb3948 cm: Improve documentation generation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 647
diff changeset
22 os.chdir(base_dir)
a409a7bb3948 cm: Improve documentation generation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 647
diff changeset
23
642
79aefe82c6b6 cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
24 if not tmp_dir:
670
a409a7bb3948 cm: Improve documentation generation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 647
diff changeset
25 tmp_dir = os.path.join(base_dir, '_docs-counter')
a409a7bb3948 cm: Improve documentation generation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 647
diff changeset
26
a409a7bb3948 cm: Improve documentation generation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 647
diff changeset
27 if not venv_dir:
a409a7bb3948 cm: Improve documentation generation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 647
diff changeset
28 venv_dir = os.path.join(base_dir, 'venv')
a409a7bb3948 cm: Improve documentation generation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 647
diff changeset
29
a409a7bb3948 cm: Improve documentation generation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 647
diff changeset
30 if not os.path.isdir(venv_dir):
a409a7bb3948 cm: Improve documentation generation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 647
diff changeset
31 print("Creating virtual environment in: %s" % venv_dir)
a409a7bb3948 cm: Improve documentation generation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 647
diff changeset
32 run('virtualenv -p python3 "%s"' % venv_dir)
a409a7bb3948 cm: Improve documentation generation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 647
diff changeset
33
a409a7bb3948 cm: Improve documentation generation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 647
diff changeset
34 pyexe = os.path.join(venv_dir, 'bin', 'python')
a409a7bb3948 cm: Improve documentation generation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 647
diff changeset
35 pyver_out = run('%s --version' % pyexe, hide=True)
a409a7bb3948 cm: Improve documentation generation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 647
diff changeset
36 if pyver_out.failed or not pyver_out.stdout.startswith('Python 3.'):
a409a7bb3948 cm: Improve documentation generation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 647
diff changeset
37 raise Exception("Can't run Python3 from: %s" % pyexe)
a409a7bb3948 cm: Improve documentation generation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 647
diff changeset
38 print("Using: %s" % pyver_out.stdout.strip())
a409a7bb3948 cm: Improve documentation generation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 647
diff changeset
39
a409a7bb3948 cm: Improve documentation generation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 647
diff changeset
40 pipexe = os.path.join(venv_dir, 'bin', 'pip')
a409a7bb3948 cm: Improve documentation generation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 647
diff changeset
41 pipver_out = run('%s --version' % pipexe, hide=True)
a409a7bb3948 cm: Improve documentation generation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 647
diff changeset
42 if pipver_out.failed or '(python 3.' not in pipver_out.stdout:
a409a7bb3948 cm: Improve documentation generation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 647
diff changeset
43 raise Exception("Can't run pip3 from: %s" % pipexe)
a409a7bb3948 cm: Improve documentation generation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 647
diff changeset
44 print("Using: %s" % pipver_out.stdout.strip())
a409a7bb3948 cm: Improve documentation generation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 647
diff changeset
45
a409a7bb3948 cm: Improve documentation generation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 647
diff changeset
46 npmver_out = run('npm --version', hide=True)
a409a7bb3948 cm: Improve documentation generation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 647
diff changeset
47 print("Using: npm %s" % npmver_out.stdout.strip())
a409a7bb3948 cm: Improve documentation generation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 647
diff changeset
48
a409a7bb3948 cm: Improve documentation generation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 647
diff changeset
49 bowerver_out = run('bower --version', hide=True)
a409a7bb3948 cm: Improve documentation generation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 647
diff changeset
50 print("Using: bower %s" % bowerver_out.stdout.strip())
a409a7bb3948 cm: Improve documentation generation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 647
diff changeset
51
a409a7bb3948 cm: Improve documentation generation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 647
diff changeset
52 print("Updating virtual environment.")
a409a7bb3948 cm: Improve documentation generation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 647
diff changeset
53 run("%s install pip -U" % pipexe)
a409a7bb3948 cm: Improve documentation generation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 647
diff changeset
54 run("%s install -r requirements.txt" % pipexe)
a409a7bb3948 cm: Improve documentation generation script.
Ludovic Chabant <ludovic@chabant.com>
parents: 647
diff changeset
55 run("%s install -r dev-requirements.txt" % pipexe)
642
79aefe82c6b6 cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
56
645
3060a6f26330 cm: Update the node modules before building the documentation.
Ludovic Chabant <ludovic@chabant.com>
parents: 642
diff changeset
57 print("Update node modules")
3060a6f26330 cm: Update the node modules before building the documentation.
Ludovic Chabant <ludovic@chabant.com>
parents: 642
diff changeset
58 run("npm install")
3060a6f26330 cm: Update the node modules before building the documentation.
Ludovic Chabant <ludovic@chabant.com>
parents: 642
diff changeset
59
642
79aefe82c6b6 cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
60 print("Update Bower packages")
79aefe82c6b6 cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
61 run("bower update")
79aefe82c6b6 cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
62
79aefe82c6b6 cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
63 print("Generate PieCrust version")
647
be67fb6add5f cm: Fixes and tweaks to the documentation generation task.
Ludovic Chabant <ludovic@chabant.com>
parents: 645
diff changeset
64 run(pyexe + ' setup.py version')
642
79aefe82c6b6 cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
65 from piecrust.__version__ import APP_VERSION
79aefe82c6b6 cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
66 version = APP_VERSION
79aefe82c6b6 cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
67
79aefe82c6b6 cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
68 print("Baking documentation for version: %s" % version)
647
be67fb6add5f cm: Fixes and tweaks to the documentation generation task.
Ludovic Chabant <ludovic@chabant.com>
parents: 645
diff changeset
69 if root_url:
be67fb6add5f cm: Fixes and tweaks to the documentation generation task.
Ludovic Chabant <ludovic@chabant.com>
parents: 645
diff changeset
70 print("Using root URL: %s" % root_url)
642
79aefe82c6b6 cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
71 args = [
647
be67fb6add5f cm: Fixes and tweaks to the documentation generation task.
Ludovic Chabant <ludovic@chabant.com>
parents: 645
diff changeset
72 pyexe, 'chef.py',
642
79aefe82c6b6 cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
73 '--root', 'docs',
647
be67fb6add5f cm: Fixes and tweaks to the documentation generation task.
Ludovic Chabant <ludovic@chabant.com>
parents: 645
diff changeset
74 '--config', 'dist']
be67fb6add5f cm: Fixes and tweaks to the documentation generation task.
Ludovic Chabant <ludovic@chabant.com>
parents: 645
diff changeset
75 if root_url:
be67fb6add5f cm: Fixes and tweaks to the documentation generation task.
Ludovic Chabant <ludovic@chabant.com>
parents: 645
diff changeset
76 args += ['--config-set', 'site/root', root_url]
be67fb6add5f cm: Fixes and tweaks to the documentation generation task.
Ludovic Chabant <ludovic@chabant.com>
parents: 645
diff changeset
77 args += [
642
79aefe82c6b6 cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
78 'bake',
79aefe82c6b6 cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
79 '-o', tmp_dir
79aefe82c6b6 cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
80 ]
79aefe82c6b6 cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
81 run(' '.join(args))
79aefe82c6b6 cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
82
79aefe82c6b6 cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
83 if out_dir:
79aefe82c6b6 cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
84 print("Synchronizing %s" % out_dir)
79aefe82c6b6 cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
85 if not os.path.isdir(out_dir):
79aefe82c6b6 cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
86 os.makedirs(out_dir)
79aefe82c6b6 cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
87
79aefe82c6b6 cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
88 tmp_dir = tmp_dir.rstrip('/') + '/'
79aefe82c6b6 cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
89 out_dir = out_dir.rstrip('/') + '/'
79aefe82c6b6 cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
90 run('rsync -av --delete %s %s' % (tmp_dir, out_dir))
79aefe82c6b6 cm: Move all scripts into a `garcon` package with `invoke` support.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
91