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
|
2020-06-16 06:31:00 +00:00
|
|
|
|
import blog
|
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
|
|
|
|
|
2020-09-19 16:42:36 +00:00
|
|
|
|
from cmake_in_clickhouse_generator import generate_cmake_flags_files
|
2018-07-09 19:59:07 +00:00
|
|
|
|
|
2022-03-22 16:39:58 +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:
|
2022-03-22 16:39:58 +00:00
|
|
|
|
if "<!--hide-->" not in line:
|
2018-10-16 10:47:17 +00:00
|
|
|
|
yield line
|
|
|
|
|
|
|
|
|
|
def extendMarkdown(self, md):
|
2022-03-22 16:39:58 +00:00
|
|
|
|
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):
|
2022-03-22 16:39:58 +00:00
|
|
|
|
logging.info(f"Building {lang} docs")
|
|
|
|
|
os.environ["SINGLE_PAGE"] = "0"
|
2018-07-09 19:59:07 +00:00
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
theme_cfg = {
|
2022-03-22 16:39:58 +00:00
|
|
|
|
"name": None,
|
|
|
|
|
"custom_dir": os.path.join(os.path.dirname(__file__), "..", args.theme_dir),
|
|
|
|
|
"language": lang,
|
|
|
|
|
"direction": "rtl" if lang == "fa" else "ltr",
|
|
|
|
|
"static_templates": ["404.html"],
|
|
|
|
|
"extra": {
|
|
|
|
|
"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
|
2022-03-22 16:39:58 +00:00
|
|
|
|
languages = {"en": "English", "zh": "中文", "ru": "Русский", "ja": "日本語"}
|
2020-03-30 08:25:29 +00:00
|
|
|
|
|
2020-03-30 13:07:08 +00:00
|
|
|
|
site_names = {
|
2022-03-22 16:39:58 +00:00
|
|
|
|
"en": "ClickHouse %s Documentation",
|
|
|
|
|
"zh": "ClickHouse文档 %s",
|
|
|
|
|
"ru": "Документация ClickHouse %s",
|
|
|
|
|
"ja": "ClickHouseドキュメント %s",
|
2020-03-30 13:07:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-30 08:25:29 +00:00
|
|
|
|
assert len(site_names) == len(languages)
|
|
|
|
|
|
2020-12-21 20:04:22 +00:00
|
|
|
|
site_dir = os.path.join(args.docs_output_dir, lang)
|
2020-02-18 14:19:44 +00:00
|
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
|
plugins = ["macros"]
|
2020-03-18 13:02:32 +00:00
|
|
|
|
if args.htmlproofer:
|
2022-03-22 16:39:58 +00:00
|
|
|
|
plugins.append("htmlproofer")
|
2020-03-18 13:02:32 +00:00
|
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
|
website_url = "https://clickhouse.com"
|
|
|
|
|
site_name = site_names.get(lang, site_names["en"]) % ""
|
|
|
|
|
site_name = site_name.replace(" ", " ")
|
2021-06-24 13:52:08 +00:00
|
|
|
|
|
2020-03-30 08:25:29 +00:00
|
|
|
|
raw_config = dict(
|
2020-04-22 12:40:30 +00:00
|
|
|
|
site_name=site_name,
|
2022-03-22 16:39:58 +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,
|
2021-09-23 14:25:39 +00:00
|
|
|
|
strict=True,
|
2018-07-09 19:59:07 +00:00
|
|
|
|
theme=theme_cfg,
|
2022-03-22 16:39:58 +00:00
|
|
|
|
copyright="©2016–2022 ClickHouse, Inc.",
|
2018-07-09 19:59:07 +00:00
|
|
|
|
use_directory_urls=True,
|
2022-03-22 16:39:58 +00:00
|
|
|
|
repo_name="ClickHouse/ClickHouse",
|
|
|
|
|
repo_url="https://github.com/ClickHouse/ClickHouse/",
|
|
|
|
|
edit_uri=f"edit/master/docs/{lang}",
|
2020-06-16 06:31:00 +00:00
|
|
|
|
markdown_extensions=mdx_clickhouse.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(),
|
|
|
|
|
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,
|
2022-03-22 16:39:58 +00:00
|
|
|
|
includes_dir=os.path.join(os.path.dirname(__file__), "..", "_includes"),
|
2020-06-16 06:31:00 +00:00
|
|
|
|
is_amp=False,
|
2022-03-22 16:39:58 +00:00
|
|
|
|
is_blog=False,
|
|
|
|
|
),
|
2018-07-09 19:59:07 +00:00
|
|
|
|
)
|
|
|
|
|
|
2021-11-06 09:54:19 +00:00
|
|
|
|
# Clean to be safe if last build finished abnormally
|
2021-11-12 20:25:55 +00:00
|
|
|
|
single_page.remove_temporary_files(lang, args)
|
2021-11-06 09:54:19 +00:00
|
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
|
raw_config["nav"] = nav.build_docs_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:
|
2020-12-21 20:04:22 +00:00
|
|
|
|
mkdocs.commands.build.build(cfg)
|
|
|
|
|
|
|
|
|
|
if not args.skip_amp:
|
2020-05-08 08:04:09 +00:00
|
|
|
|
amp.build_amp(lang, args, cfg)
|
2018-07-09 19:59:07 +00:00
|
|
|
|
|
|
|
|
|
if not args.skip_single_page:
|
2022-03-22 16:39:58 +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
|
|
|
|
|
|
2022-03-22 16:39:58 +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:
|
2022-03-22 16:39:58 +00:00
|
|
|
|
raise SystemExit("\n" + str(e))
|
2018-07-09 19:59:07 +00:00
|
|
|
|
|
|
|
|
|
|
2019-04-08 16:01:54 +00:00
|
|
|
|
def build_docs(args):
|
2020-01-29 13:34:12 +00:00
|
|
|
|
tasks = []
|
2022-03-22 16:39:58 +00:00
|
|
|
|
for lang in args.lang.split(","):
|
2020-02-18 14:19:44 +00:00
|
|
|
|
if lang:
|
2022-03-22 16:39:58 +00:00
|
|
|
|
tasks.append(
|
|
|
|
|
(
|
|
|
|
|
lang,
|
|
|
|
|
args,
|
|
|
|
|
)
|
|
|
|
|
)
|
2020-02-03 08:58:13 +00:00
|
|
|
|
util.run_function_in_parallel(build_for_lang, tasks, threads=False)
|
2020-12-21 20:04:22 +00:00
|
|
|
|
redirects.build_docs_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-09-03 20:37:45 +00:00
|
|
|
|
if not args.skip_docs:
|
2020-09-28 12:47:10 +00:00
|
|
|
|
generate_cmake_flags_files()
|
2020-09-19 16:42:36 +00:00
|
|
|
|
|
2020-09-03 20:37:45 +00:00
|
|
|
|
build_docs(args)
|
2018-07-09 19:59:07 +00:00
|
|
|
|
|
2020-06-16 06:31:00 +00:00
|
|
|
|
if not args.skip_blog:
|
|
|
|
|
blog.build_blog(args)
|
|
|
|
|
|
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
|
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
os.chdir(os.path.join(os.path.dirname(__file__), ".."))
|
2020-11-28 06:20:06 +00:00
|
|
|
|
|
|
|
|
|
# A root path to ClickHouse source code.
|
2022-03-22 16:39:58 +00:00
|
|
|
|
src_dir = ".."
|
2020-11-28 06:20:06 +00:00
|
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
|
website_dir = os.path.join(src_dir, "website")
|
2020-09-19 22:27:36 +00:00
|
|
|
|
|
2018-07-09 19:59:07 +00:00
|
|
|
|
arg_parser = argparse.ArgumentParser()
|
2022-03-22 16:39:58 +00:00
|
|
|
|
arg_parser.add_argument("--lang", default="en,ru,zh,ja")
|
|
|
|
|
arg_parser.add_argument("--blog-lang", default="en")
|
|
|
|
|
arg_parser.add_argument("--docs-dir", default=".")
|
|
|
|
|
arg_parser.add_argument("--theme-dir", default=website_dir)
|
|
|
|
|
arg_parser.add_argument("--website-dir", default=website_dir)
|
|
|
|
|
arg_parser.add_argument("--src-dir", default=src_dir)
|
|
|
|
|
arg_parser.add_argument("--blog-dir", default=os.path.join(website_dir, "blog"))
|
|
|
|
|
arg_parser.add_argument("--output-dir", default="build")
|
|
|
|
|
arg_parser.add_argument("--nav-limit", type=int, default="0")
|
|
|
|
|
arg_parser.add_argument("--skip-multi-page", action="store_true")
|
|
|
|
|
arg_parser.add_argument("--skip-single-page", action="store_true")
|
|
|
|
|
arg_parser.add_argument("--skip-amp", action="store_true")
|
|
|
|
|
arg_parser.add_argument("--skip-website", action="store_true")
|
|
|
|
|
arg_parser.add_argument("--skip-blog", action="store_true")
|
|
|
|
|
arg_parser.add_argument("--skip-git-log", action="store_true")
|
|
|
|
|
arg_parser.add_argument("--skip-docs", action="store_true")
|
|
|
|
|
arg_parser.add_argument("--test-only", action="store_true")
|
|
|
|
|
arg_parser.add_argument("--minify", action="store_true")
|
|
|
|
|
arg_parser.add_argument("--htmlproofer", action="store_true")
|
|
|
|
|
arg_parser.add_argument("--no-docs-macros", action="store_true")
|
|
|
|
|
arg_parser.add_argument("--save-raw-single-page", type=str)
|
|
|
|
|
arg_parser.add_argument("--livereload", type=int, default="0")
|
|
|
|
|
arg_parser.add_argument("--verbose", action="store_true")
|
2018-07-09 19:59:07 +00:00
|
|
|
|
|
|
|
|
|
args = arg_parser.parse_args()
|
2021-09-20 17:52:25 +00:00
|
|
|
|
args.minify = False # TODO remove
|
2020-03-19 06:28:58 +00:00
|
|
|
|
|
|
|
|
|
logging.basicConfig(
|
2022-03-22 16:39:58 +00:00
|
|
|
|
level=logging.DEBUG if args.verbose else logging.INFO, stream=sys.stderr
|
2020-03-19 06:28:58 +00:00
|
|
|
|
)
|
|
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
|
logging.getLogger("MARKDOWN").setLevel(logging.INFO)
|
2020-03-19 06:28:58 +00:00
|
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
|
args.docs_output_dir = os.path.join(os.path.abspath(args.output_dir), "docs")
|
|
|
|
|
args.blog_output_dir = os.path.join(os.path.abspath(args.output_dir), "blog")
|
2020-02-18 14:19:44 +00:00
|
|
|
|
|
2020-12-21 20:04:22 +00:00
|
|
|
|
from github import get_events
|
2022-03-22 16:39:58 +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()
|
|
|
|
|
)
|
|
|
|
|
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
|
2020-06-16 06:31:00 +00:00
|
|
|
|
args.skip_blog = True
|
2020-05-06 12:54:33 +00:00
|
|
|
|
args.skip_website = True
|
2020-05-08 08:04:09 +00:00
|
|
|
|
args.skip_amp = True
|
2020-05-06 12:54:33 +00:00
|
|
|
|
|
2020-05-12 14:09:36 +00:00
|
|
|
|
if args.skip_git_log or args.skip_amp:
|
|
|
|
|
mdx_clickhouse.PatchedMacrosPlugin.skip_git_log = True
|
|
|
|
|
|
2018-07-09 19:59:07 +00:00
|
|
|
|
from build import build
|
2022-03-22 16:39:58 +00:00
|
|
|
|
|
2018-07-09 19:59:07 +00:00
|
|
|
|
build(args)
|
2020-04-09 20:50:39 +00:00
|
|
|
|
|
2020-03-13 19:35:03 +00:00
|
|
|
|
if args.livereload:
|
2022-03-22 16:39:58 +00:00
|
|
|
|
new_args = [arg for arg in sys.argv if not arg.startswith("--livereload")]
|
|
|
|
|
new_args = sys.executable + " " + " ".join(new_args)
|
2020-03-13 19:35:03 +00:00
|
|
|
|
|
|
|
|
|
server = livereload.Server()
|
2022-03-22 16:39:58 +00:00
|
|
|
|
server.watch(
|
|
|
|
|
args.docs_dir + "**/*", livereload.shell(new_args, cwd="tools", shell=True)
|
|
|
|
|
)
|
|
|
|
|
server.watch(
|
|
|
|
|
args.website_dir + "**/*",
|
|
|
|
|
livereload.shell(new_args, cwd="tools", shell=True),
|
2020-03-13 19:35:03 +00:00
|
|
|
|
)
|
2022-03-22 16:39:58 +00:00
|
|
|
|
server.serve(root=args.output_dir, host="0.0.0.0", port=args.livereload)
|
2020-03-13 19:35:03 +00:00
|
|
|
|
sys.exit(0)
|