2020-03-18 13:02:32 +00:00
|
|
|
|
#!/usr/bin/env python3
|
2020-03-30 08:25:29 +00:00
|
|
|
|
|
2018-07-09 19:59:07 +00:00
|
|
|
|
import argparse
|
2018-08-10 14:44:49 +00:00
|
|
|
|
import datetime
|
2018-07-09 19:59:07 +00:00
|
|
|
|
import logging
|
|
|
|
|
import os
|
|
|
|
|
import shutil
|
2018-10-12 15:43:16 +00:00
|
|
|
|
import subprocess
|
2018-07-09 19:59:07 +00:00
|
|
|
|
import sys
|
2018-10-16 10:47:17 +00:00
|
|
|
|
import time
|
|
|
|
|
|
2020-03-30 08:25:29 +00:00
|
|
|
|
import jinja2
|
2020-03-13 19:35:03 +00:00
|
|
|
|
import livereload
|
2018-10-16 10:47:17 +00:00
|
|
|
|
import markdown.util
|
2018-07-09 19:59:07 +00:00
|
|
|
|
|
2020-05-08 08:04:09 +00:00
|
|
|
|
import nav # monkey patches mkdocs
|
|
|
|
|
|
2018-07-09 19:59:07 +00:00
|
|
|
|
from mkdocs import config
|
|
|
|
|
from mkdocs import exceptions
|
2020-05-08 08:04:09 +00:00
|
|
|
|
import mkdocs.commands.build
|
2019-04-08 16:01:54 +00:00
|
|
|
|
|
2020-05-08 08:04:09 +00:00
|
|
|
|
import amp
|
2018-12-12 17:28:00 +00:00
|
|
|
|
import mdx_clickhouse
|
2020-05-08 08:04:09 +00:00
|
|
|
|
|
|
|
|
|
import redirects
|
|
|
|
|
import single_page
|
2018-12-18 11:32:08 +00:00
|
|
|
|
import test
|
2019-04-08 16:01:54 +00:00
|
|
|
|
import util
|
2020-03-30 11:39:26 +00:00
|
|
|
|
import website
|
2018-07-09 19:59:07 +00:00
|
|
|
|
|
|
|
|
|
|
2018-10-16 10:47:17 +00:00
|
|
|
|
class ClickHouseMarkdown(markdown.extensions.Extension):
|
|
|
|
|
class ClickHousePreprocessor(markdown.util.Processor):
|
|
|
|
|
def run(self, lines):
|
|
|
|
|
for line in lines:
|
|
|
|
|
if '<!--hide-->' not in line:
|
|
|
|
|
yield line
|
|
|
|
|
|
|
|
|
|
def extendMarkdown(self, md):
|
|
|
|
|
md.preprocessors.register(self.ClickHousePreprocessor(), 'clickhouse_preprocessor', 31)
|
2018-07-09 19:59:07 +00:00
|
|
|
|
|
2019-04-08 16:01:54 +00:00
|
|
|
|
|
2018-10-16 10:47:17 +00:00
|
|
|
|
markdown.extensions.ClickHouseMarkdown = ClickHouseMarkdown
|
2018-10-16 06:58:03 +00:00
|
|
|
|
|
2019-04-08 16:01:54 +00:00
|
|
|
|
|
2018-07-09 19:59:07 +00:00
|
|
|
|
def build_for_lang(lang, args):
|
2020-03-22 12:12:53 +00:00
|
|
|
|
logging.info(f'Building {lang} docs')
|
2018-12-12 17:28:00 +00:00
|
|
|
|
os.environ['SINGLE_PAGE'] = '0'
|
2018-07-09 19:59:07 +00:00
|
|
|
|
|
2020-03-22 12:12:53 +00:00
|
|
|
|
config_path = os.path.join(args.docs_dir, f'toc_{lang}.yml')
|
2019-12-10 08:17:26 +00:00
|
|
|
|
if args.is_stable_release and not os.path.exists(config_path):
|
2020-03-22 12:12:53 +00:00
|
|
|
|
logging.warning(f'Skipping {lang} docs, because {config} does not exist')
|
2019-12-10 08:17:26 +00:00
|
|
|
|
return
|
2018-07-09 19:59:07 +00:00
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
theme_cfg = {
|
2020-03-22 12:12:53 +00:00
|
|
|
|
'name': None,
|
2020-03-30 08:25:29 +00:00
|
|
|
|
'custom_dir': os.path.join(os.path.dirname(__file__), '..', args.theme_dir),
|
2018-07-09 19:59:07 +00:00
|
|
|
|
'language': lang,
|
2018-09-06 10:22:06 +00:00
|
|
|
|
'direction': 'rtl' if lang == 'fa' else 'ltr',
|
2020-03-30 08:25:29 +00:00
|
|
|
|
# TODO: cleanup
|
2018-07-09 19:59:07 +00:00
|
|
|
|
'feature': {
|
|
|
|
|
'tabs': False
|
|
|
|
|
},
|
|
|
|
|
'palette': {
|
|
|
|
|
'primary': 'white',
|
|
|
|
|
'accent': 'white'
|
|
|
|
|
},
|
|
|
|
|
'font': False,
|
|
|
|
|
'logo': 'images/logo.svg',
|
|
|
|
|
'favicon': 'assets/images/favicon.ico',
|
|
|
|
|
'static_templates': ['404.html'],
|
|
|
|
|
'extra': {
|
2020-02-18 14:19:44 +00:00
|
|
|
|
'now': int(time.mktime(datetime.datetime.now().timetuple())) # TODO better way to avoid caching
|
2018-07-09 19:59:07 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-08-10 14:44:49 +00:00
|
|
|
|
|
2020-03-30 13:07:08 +00:00
|
|
|
|
# the following list of languages is sorted according to
|
|
|
|
|
# https://en.wikipedia.org/wiki/List_of_languages_by_total_number_of_speakers
|
2020-03-30 08:25:29 +00:00
|
|
|
|
languages = {
|
|
|
|
|
'en': 'English',
|
|
|
|
|
'zh': '中文',
|
|
|
|
|
'es': 'Español',
|
2020-03-30 12:48:55 +00:00
|
|
|
|
'fr': 'Français',
|
2020-03-30 08:25:29 +00:00
|
|
|
|
'ru': 'Русский',
|
|
|
|
|
'ja': '日本語',
|
2020-04-15 13:56:49 +00:00
|
|
|
|
'tr': 'Türkçe',
|
2020-03-30 08:25:29 +00:00
|
|
|
|
'fa': 'فارسی'
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-30 13:07:08 +00:00
|
|
|
|
site_names = {
|
|
|
|
|
'en': 'ClickHouse %s Documentation',
|
2020-04-08 09:09:59 +00:00
|
|
|
|
'zh': 'ClickHouse文档 %s',
|
2020-03-30 13:07:08 +00:00
|
|
|
|
'es': 'Documentación de ClickHouse %s',
|
|
|
|
|
'fr': 'Documentation ClickHouse %s',
|
|
|
|
|
'ru': 'Документация ClickHouse %s',
|
|
|
|
|
'ja': 'ClickHouseドキュメント %s',
|
2020-04-15 13:56:49 +00:00
|
|
|
|
'tr': 'ClickHouse Belgeleri %s',
|
2020-03-30 13:07:08 +00:00
|
|
|
|
'fa': 'مستندات %sClickHouse'
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-30 08:25:29 +00:00
|
|
|
|
assert len(site_names) == len(languages)
|
|
|
|
|
|
2019-04-08 16:01:54 +00:00
|
|
|
|
if args.version_prefix:
|
|
|
|
|
site_dir = os.path.join(args.docs_output_dir, args.version_prefix, lang)
|
|
|
|
|
else:
|
|
|
|
|
site_dir = os.path.join(args.docs_output_dir, lang)
|
2020-02-18 14:19:44 +00:00
|
|
|
|
|
2020-03-30 08:25:29 +00:00
|
|
|
|
markdown_extensions = [
|
|
|
|
|
'mdx_clickhouse',
|
|
|
|
|
'admonition',
|
|
|
|
|
'attr_list',
|
|
|
|
|
'codehilite',
|
|
|
|
|
'nl2br',
|
|
|
|
|
'sane_lists',
|
2020-04-16 18:03:52 +00:00
|
|
|
|
'pymdownx.details',
|
2020-03-30 08:25:29 +00:00
|
|
|
|
'pymdownx.magiclink',
|
|
|
|
|
'pymdownx.superfences',
|
|
|
|
|
'extra',
|
|
|
|
|
{
|
|
|
|
|
'toc': {
|
|
|
|
|
'permalink': True,
|
|
|
|
|
'slugify': mdx_clickhouse.slugify
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
plugins = ['macros']
|
2020-03-18 13:02:32 +00:00
|
|
|
|
if args.htmlproofer:
|
|
|
|
|
plugins.append('htmlproofer')
|
|
|
|
|
|
2020-04-30 15:49:48 +00:00
|
|
|
|
website_url = 'https://clickhouse.tech'
|
2020-04-22 12:40:30 +00:00
|
|
|
|
site_name = site_names.get(lang, site_names['en']) % args.version_prefix
|
|
|
|
|
site_name = site_name.replace(' ', ' ')
|
2020-03-30 08:25:29 +00:00
|
|
|
|
raw_config = dict(
|
2020-04-22 12:40:30 +00:00
|
|
|
|
site_name=site_name,
|
2020-04-30 15:49:48 +00:00
|
|
|
|
site_url=f'{website_url}/docs/{lang}/',
|
2018-07-09 19:59:07 +00:00
|
|
|
|
docs_dir=os.path.join(args.docs_dir, lang),
|
2019-04-08 16:01:54 +00:00
|
|
|
|
site_dir=site_dir,
|
|
|
|
|
strict=not args.version_prefix,
|
2018-07-09 19:59:07 +00:00
|
|
|
|
theme=theme_cfg,
|
2020-01-30 14:00:45 +00:00
|
|
|
|
copyright='©2016–2020 Yandex LLC',
|
2018-07-09 19:59:07 +00:00
|
|
|
|
use_directory_urls=True,
|
2019-11-08 14:26:25 +00:00
|
|
|
|
repo_name='ClickHouse/ClickHouse',
|
|
|
|
|
repo_url='https://github.com/ClickHouse/ClickHouse/',
|
2020-03-22 12:12:53 +00:00
|
|
|
|
edit_uri=f'edit/master/docs/{lang}',
|
2020-03-30 08:25:29 +00:00
|
|
|
|
markdown_extensions=markdown_extensions,
|
2020-03-18 13:02:32 +00:00
|
|
|
|
plugins=plugins,
|
2020-05-08 08:04:09 +00:00
|
|
|
|
extra=dict(
|
|
|
|
|
now=datetime.datetime.now().isoformat(),
|
|
|
|
|
stable_releases=args.stable_releases,
|
|
|
|
|
version_prefix=args.version_prefix,
|
|
|
|
|
single_page=False,
|
|
|
|
|
rev=args.rev,
|
|
|
|
|
rev_short=args.rev_short,
|
|
|
|
|
rev_url=args.rev_url,
|
|
|
|
|
website_url=website_url,
|
|
|
|
|
events=args.events,
|
|
|
|
|
languages=languages,
|
|
|
|
|
includes_dir=os.path.join(os.path.dirname(__file__), '..', '_includes'),
|
|
|
|
|
is_amp=False
|
|
|
|
|
)
|
2018-07-09 19:59:07 +00:00
|
|
|
|
)
|
|
|
|
|
|
2020-04-03 13:23:32 +00:00
|
|
|
|
if os.path.exists(config_path):
|
|
|
|
|
raw_config['config_file'] = config_path
|
|
|
|
|
else:
|
2020-04-08 09:09:59 +00:00
|
|
|
|
raw_config['nav'] = nav.build_nav(lang, args)
|
2020-04-03 13:23:32 +00:00
|
|
|
|
|
2020-03-30 08:25:29 +00:00
|
|
|
|
cfg = config.load_config(**raw_config)
|
|
|
|
|
|
2020-05-06 12:54:33 +00:00
|
|
|
|
if not args.skip_multi_page:
|
|
|
|
|
try:
|
2020-05-08 08:04:09 +00:00
|
|
|
|
mkdocs.commands.build.build(cfg)
|
2020-05-06 12:54:33 +00:00
|
|
|
|
except jinja2.exceptions.TemplateError:
|
|
|
|
|
if not args.version_prefix:
|
|
|
|
|
raise
|
|
|
|
|
mdx_clickhouse.PatchedMacrosPlugin.disabled = True
|
2020-05-08 08:04:09 +00:00
|
|
|
|
mkdocs.commands.build.build(cfg)
|
|
|
|
|
|
|
|
|
|
if not (args.skip_amp or args.version_prefix):
|
|
|
|
|
amp.build_amp(lang, args, cfg)
|
2018-07-09 19:59:07 +00:00
|
|
|
|
|
|
|
|
|
if not args.skip_single_page:
|
2020-05-08 08:04:09 +00:00
|
|
|
|
single_page.build_single_page_version(lang, args, raw_config.get('nav'), cfg)
|
2020-03-30 08:25:29 +00:00
|
|
|
|
|
|
|
|
|
mdx_clickhouse.PatchedMacrosPlugin.disabled = False
|
|
|
|
|
|
2020-03-22 15:20:11 +00:00
|
|
|
|
logging.info(f'Finished building {lang} docs')
|
2020-03-22 14:48:36 +00:00
|
|
|
|
|
2018-07-09 19:59:07 +00:00
|
|
|
|
except exceptions.ConfigurationError as e:
|
|
|
|
|
raise SystemExit('\n' + str(e))
|
|
|
|
|
|
|
|
|
|
|
2019-04-08 16:01:54 +00:00
|
|
|
|
def build_docs(args):
|
2020-01-29 13:34:12 +00:00
|
|
|
|
tasks = []
|
2019-04-08 16:01:54 +00:00
|
|
|
|
for lang in args.lang.split(','):
|
2020-02-18 14:19:44 +00:00
|
|
|
|
if lang:
|
|
|
|
|
tasks.append((lang, args,))
|
2020-02-03 08:58:13 +00:00
|
|
|
|
util.run_function_in_parallel(build_for_lang, tasks, threads=False)
|
2020-05-08 08:04:09 +00:00
|
|
|
|
redirects.build_redirects(args)
|
2019-04-08 16:01:54 +00:00
|
|
|
|
|
|
|
|
|
|
2018-07-09 19:59:07 +00:00
|
|
|
|
def build(args):
|
2019-03-26 09:50:28 +00:00
|
|
|
|
if os.path.exists(args.output_dir):
|
|
|
|
|
shutil.rmtree(args.output_dir)
|
|
|
|
|
|
|
|
|
|
if not args.skip_website:
|
2020-03-30 11:39:26 +00:00
|
|
|
|
website.build_website(args)
|
2019-03-26 09:50:28 +00:00
|
|
|
|
|
2020-05-06 13:28:02 +00:00
|
|
|
|
test.test_templates(args.website_dir)
|
|
|
|
|
|
2019-04-08 16:01:54 +00:00
|
|
|
|
build_docs(args)
|
2020-02-18 14:19:44 +00:00
|
|
|
|
|
2019-04-08 16:01:54 +00:00
|
|
|
|
from github import build_releases
|
|
|
|
|
build_releases(args, build_docs)
|
2018-07-09 19:59:07 +00:00
|
|
|
|
|
2019-03-26 09:50:28 +00:00
|
|
|
|
if not args.skip_website:
|
2020-04-22 11:30:33 +00:00
|
|
|
|
website.process_benchmark_results(args)
|
2020-03-30 11:39:26 +00:00
|
|
|
|
website.minify_website(args)
|
2020-05-08 08:04:09 +00:00
|
|
|
|
redirects.build_static_redirects(args)
|
2020-01-29 20:27:36 +00:00
|
|
|
|
|
2019-04-08 16:01:54 +00:00
|
|
|
|
|
2018-07-09 19:59:07 +00:00
|
|
|
|
if __name__ == '__main__':
|
2019-04-08 16:01:54 +00:00
|
|
|
|
os.chdir(os.path.join(os.path.dirname(__file__), '..'))
|
2020-03-30 08:25:29 +00:00
|
|
|
|
website_dir = os.path.join('..', 'website')
|
2018-07-09 19:59:07 +00:00
|
|
|
|
arg_parser = argparse.ArgumentParser()
|
2020-04-15 13:56:49 +00:00
|
|
|
|
arg_parser.add_argument('--lang', default='en,es,fr,ru,zh,ja,tr,fa')
|
2018-08-10 14:44:49 +00:00
|
|
|
|
arg_parser.add_argument('--docs-dir', default='.')
|
2020-03-30 08:25:29 +00:00
|
|
|
|
arg_parser.add_argument('--theme-dir', default=website_dir)
|
|
|
|
|
arg_parser.add_argument('--website-dir', default=website_dir)
|
2018-08-10 14:44:49 +00:00
|
|
|
|
arg_parser.add_argument('--output-dir', default='build')
|
2019-04-08 16:01:54 +00:00
|
|
|
|
arg_parser.add_argument('--enable-stable-releases', action='store_true')
|
2020-04-15 13:35:16 +00:00
|
|
|
|
arg_parser.add_argument('--stable-releases-limit', type=int, default='4')
|
2020-04-16 09:09:04 +00:00
|
|
|
|
arg_parser.add_argument('--lts-releases-limit', type=int, default='2')
|
2020-05-08 08:04:09 +00:00
|
|
|
|
arg_parser.add_argument('--nav-limit', type=int, default='0')
|
2019-04-08 16:01:54 +00:00
|
|
|
|
arg_parser.add_argument('--version-prefix', type=str, default='')
|
2019-12-10 08:17:26 +00:00
|
|
|
|
arg_parser.add_argument('--is-stable-release', action='store_true')
|
2020-05-06 12:54:33 +00:00
|
|
|
|
arg_parser.add_argument('--skip-multi-page', action='store_true')
|
2018-07-09 19:59:07 +00:00
|
|
|
|
arg_parser.add_argument('--skip-single-page', action='store_true')
|
2020-05-08 08:04:09 +00:00
|
|
|
|
arg_parser.add_argument('--skip-amp', action='store_true')
|
2018-12-21 19:40:49 +00:00
|
|
|
|
arg_parser.add_argument('--skip-pdf', action='store_true')
|
2019-03-26 09:50:28 +00:00
|
|
|
|
arg_parser.add_argument('--skip-website', action='store_true')
|
2020-05-06 12:54:33 +00:00
|
|
|
|
arg_parser.add_argument('--test-only', action='store_true')
|
2020-02-14 09:34:57 +00:00
|
|
|
|
arg_parser.add_argument('--minify', action='store_true')
|
2020-03-18 13:02:32 +00:00
|
|
|
|
arg_parser.add_argument('--htmlproofer', action='store_true')
|
2020-03-19 08:31:06 +00:00
|
|
|
|
arg_parser.add_argument('--no-docs-macros', action='store_true')
|
2018-12-18 11:32:08 +00:00
|
|
|
|
arg_parser.add_argument('--save-raw-single-page', type=str)
|
2020-03-13 19:35:03 +00:00
|
|
|
|
arg_parser.add_argument('--livereload', type=int, default='0')
|
2018-07-09 19:59:07 +00:00
|
|
|
|
arg_parser.add_argument('--verbose', action='store_true')
|
|
|
|
|
|
|
|
|
|
args = arg_parser.parse_args()
|
2020-03-19 06:28:58 +00:00
|
|
|
|
|
|
|
|
|
logging.basicConfig(
|
|
|
|
|
level=logging.DEBUG if args.verbose else logging.INFO,
|
|
|
|
|
stream=sys.stderr
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
logging.getLogger('MARKDOWN').setLevel(logging.INFO)
|
|
|
|
|
|
2019-04-08 16:01:54 +00:00
|
|
|
|
args.docs_output_dir = os.path.join(os.path.abspath(args.output_dir), 'docs')
|
2020-02-18 14:19:44 +00:00
|
|
|
|
|
2020-03-13 19:35:03 +00:00
|
|
|
|
from github import choose_latest_releases, get_events
|
2020-03-30 08:25:29 +00:00
|
|
|
|
args.stable_releases = choose_latest_releases(args) if args.enable_stable_releases else []
|
2020-03-18 13:02:32 +00:00
|
|
|
|
args.rev = subprocess.check_output('git rev-parse HEAD', shell=True).decode('utf-8').strip()
|
|
|
|
|
args.rev_short = subprocess.check_output('git rev-parse --short HEAD', shell=True).decode('utf-8').strip()
|
2020-03-22 12:12:53 +00:00
|
|
|
|
args.rev_url = f'https://github.com/ClickHouse/ClickHouse/commit/{args.rev}'
|
2020-03-13 19:35:03 +00:00
|
|
|
|
args.events = get_events(args)
|
2018-07-09 19:59:07 +00:00
|
|
|
|
|
2020-05-06 12:54:33 +00:00
|
|
|
|
if args.test_only:
|
|
|
|
|
args.skip_multi_page = True
|
|
|
|
|
args.skip_website = True
|
|
|
|
|
args.skip_pdf = True
|
2020-05-08 08:04:09 +00:00
|
|
|
|
args.skip_amp = True
|
2020-05-06 12:54:33 +00:00
|
|
|
|
|
2018-07-09 19:59:07 +00:00
|
|
|
|
from build import build
|
|
|
|
|
build(args)
|
2020-04-09 20:50:39 +00:00
|
|
|
|
|
2020-03-13 19:35:03 +00:00
|
|
|
|
if args.livereload:
|
|
|
|
|
new_args = [arg for arg in sys.argv if not arg.startswith('--livereload')]
|
|
|
|
|
new_args = sys.executable + ' ' + ' '.join(new_args)
|
|
|
|
|
|
|
|
|
|
server = livereload.Server()
|
|
|
|
|
server.watch(args.docs_dir + '**/*', livereload.shell(new_args, cwd='tools', shell=True))
|
2020-03-30 08:25:29 +00:00
|
|
|
|
server.watch(args.website_dir + '**/*', livereload.shell(new_args, cwd='tools', shell=True))
|
2020-03-13 19:35:03 +00:00
|
|
|
|
server.serve(
|
|
|
|
|
root=args.output_dir,
|
2020-03-30 08:25:29 +00:00
|
|
|
|
host='0.0.0.0',
|
2020-03-13 19:35:03 +00:00
|
|
|
|
port=args.livereload
|
|
|
|
|
)
|
|
|
|
|
sys.exit(0)
|