From 372a9e51b30c458277e785addc18fcedcce2eb34 Mon Sep 17 00:00:00 2001 From: Dan Joseph Date: Fri, 12 Nov 2021 16:26:15 -0500 Subject: [PATCH] update makefile and change argument file generation --- Makefile | 47 +++++++++++++++++++----------- scripts/arguments.arg.template.rst | 2 +- scripts/arguments.template.rst | 4 +-- scripts/extract_odm_strings.py | 19 +++++++----- 4 files changed, 44 insertions(+), 28 deletions(-) diff --git a/Makefile b/Makefile index 5a6e18dba..dd3588665 100644 --- a/Makefile +++ b/Makefile @@ -14,28 +14,41 @@ help: .PHONY: help Makefile +# this is for testing, it will only build the EN version of the docs +livehtml: + sphinx-autobuild --open-browser --host 0.0.0.0 -b dirhtml "$(SOURCEDIR)" "$(BUILDDIR)/html" + # this will update `arguments.rst` to match arguments in the ODM code +# add any individual file for an arguement missing from `source/arguments_edit/` +# update the files in `source/arguments/` including adding in +# all user contributed content from files in `source/arguments_edit/` autogenerate: python scripts/extract_odm_strings.py https://raw.githubusercontent.com/OpenDroneMap/ODM/master/opendm/config.py -pushlang: - @$(SPHINXBUILD) -b gettext "$(SOURCEDIR)" "source/locale/en/pot" - tx push --source -pulllang: - tx pull --language "sw,ar,es,fr,te,fil" +# update main EN pot files that serve as the source for translation process +updatepot: + @$(SPHINXBUILD) -b gettext "$(SOURCEDIR)" "source/locale/pot" -livehtml: - sphinx-autobuild --open-browser --host 0.0.0.0 -b dirhtml "$(SOURCEDIR)" "$(BUILDDIR)" +# update the po files for each target language from the EN pot files +updatelangpo: + sphinx-intl update --pot-dir "source/locale/pot" --language sw,ar,es,fr,te,fil + +# push new and changed strings to Transifex +pushlang: + tx push --source + +# push translated strings from Transifex +pulllang: + tx pull --language "sw,ar,es,fr,te,fil" build: @$(SPHINXBUILD) -b dirhtml "$(SOURCEDIR)" "$(BUILDDIR)/html" -nW - @$(SPHINXBUILD) -b dirhtml -D language='sw' "$(SOURCEDIR)" "$(BUILDDIR)/html/sw" -nW - @$(SPHINXBUILD) -b dirhtml -D language='ar' "$(SOURCEDIR)" "$(BUILDDIR)/html/ar" -nW + @$(SPHINXBUILD) -b dirhtml -D language='sw' "$(SOURCEDIR)" "$(BUILDDIR)/html/sw" -nW + @$(SPHINXBUILD) -b dirhtml -D language='ar' "$(SOURCEDIR)" "$(BUILDDIR)/html/ar" -nW @$(SPHINXBUILD) -b dirhtml -D language='es' "$(SOURCEDIR)" "$(BUILDDIR)/html/es" -nW @$(SPHINXBUILD) -b dirhtml -D language='fr' "$(SOURCEDIR)" "$(BUILDDIR)/html/fr" -nW @$(SPHINXBUILD) -b dirhtml -D language='te' "$(SOURCEDIR)" "$(BUILDDIR)/html/te" -nW @$(SPHINXBUILD) -b dirhtml -D language='fil' "$(SOURCEDIR)" "$(BUILDDIR)/html/fil" -nW - echo "docs.opendronemap.org" > ./_build/html/CNAME # -n Run in nit-picky mode. Currently, this generates warnings for all missing references. # -W Turn warnings into errors that stop the build. # for more details about the options see https://www.sphinx-doc.org/en/1.8/man/sphinx-build.html#options @@ -43,13 +56,13 @@ build: # `allerr` runs without nit-picky mode, so that an error doesn't halt the build # it will log all errors that need to be fixed in the translations (generally syntax errors) allerr: - @$(SPHINXBUILD) -b dirhtml "$(SOURCEDIR)" "$(BUILDDIR)/html" - @$(SPHINXBUILD) -b dirhtml -D language='sw' "$(SOURCEDIR)" "$(BUILDDIR)/html/sw" - @$(SPHINXBUILD) -b dirhtml -D language='ar' "$(SOURCEDIR)" "$(BUILDDIR)/html/ar" - @$(SPHINXBUILD) -b dirhtml -D language='es' "$(SOURCEDIR)" "$(BUILDDIR)/html/es" - @$(SPHINXBUILD) -b dirhtml -D language='fr' "$(SOURCEDIR)" "$(BUILDDIR)/html/fr" - @$(SPHINXBUILD) -b dirhtml -D language='te' "$(SOURCEDIR)" "$(BUILDDIR)/html/te" - @$(SPHINXBUILD) -b dirhtml -D language='fil' "$(SOURCEDIR)" "$(BUILDDIR)/html/fil" + @$(SPHINXBUILD) -v -b dirhtml "$(SOURCEDIR)" "$(BUILDDIR)/html" + @$(SPHINXBUILD) -v -b dirhtml -D language='sw' "$(SOURCEDIR)" "$(BUILDDIR)/html/sw" + @$(SPHINXBUILD) -v -b dirhtml -D language='ar' "$(SOURCEDIR)" "$(BUILDDIR)/html/ar" + @$(SPHINXBUILD) -v -b dirhtml -D language='es' "$(SOURCEDIR)" "$(BUILDDIR)/html/es" + @$(SPHINXBUILD) -v -b dirhtml -D language='fr' "$(SOURCEDIR)" "$(BUILDDIR)/html/fr" + @$(SPHINXBUILD) -v -b dirhtml -D language='te' "$(SOURCEDIR)" "$(BUILDDIR)/html/te" + @$(SPHINXBUILD) -v -b dirhtml -D language='fil' "$(SOURCEDIR)" "$(BUILDDIR)/html/fil" # Catch-all target: route all unknown targets to Sphinx using the new # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). diff --git a/scripts/arguments.arg.template.rst b/scripts/arguments.arg.template.rst index edbfe8399..6b29a7c3e 100644 --- a/scripts/arguments.arg.template.rst +++ b/scripts/arguments.arg.template.rst @@ -1,6 +1,6 @@ .. AUTO-GENERATED by extract_odm_strings.py! DO NOT EDIT! - If you want to add more details to a command, create a + If you want to add more details to a command, edit a .rst file in arguments_edit/.rst .. _$opt: diff --git a/scripts/arguments.template.rst b/scripts/arguments.template.rst index c52ba5f37..bb1e3fa68 100644 --- a/scripts/arguments.template.rst +++ b/scripts/arguments.template.rst @@ -4,10 +4,10 @@ Options and Flags $arguments -`Learn to edit `_ and help improve `this page `_! +If you want to add more details to a command, `learn to edit `_ and help improve the matching file in the ``arguments_edit`` `project folder `_! .. toctree:: :maxdepth: 1 :glob: - arguments/* \ No newline at end of file + arguments/* diff --git a/scripts/extract_odm_strings.py b/scripts/extract_odm_strings.py index 22a8e3933..27ba384de 100644 --- a/scripts/extract_odm_strings.py +++ b/scripts/extract_odm_strings.py @@ -2,6 +2,7 @@ import argparse, os, urllib.request, ast, sys from io import StringIO +from pathlib import Path from string import Template parser = argparse.ArgumentParser(description='Extract ODM strings.') @@ -31,13 +32,13 @@ class ArgumentParserStub(argparse.ArgumentParser): for name, value in kwargs.items(): options[args[0]][str(name)] = str(value) - + def add_mutually_exclusive_group(self): return ArgumentParserStub() # Voodoo! :) # ( parse AST, extract "def config()" function, set module to only -# contain that function, execute module in current scope, +# contain that function, execute module in current scope, # run config function) root = ast.parse(config_file) new_body = [] @@ -56,7 +57,7 @@ exec(compile(root, filename="", mode="exec")) # Misc variables needed to get config to run __version__ = '?' -class context: +class context: root_path = '' num_cores = 4 class io: @@ -88,7 +89,7 @@ if len(options) > 0: keys = list(options.keys()) keys.sort(key=lambda a: a.replace("-", "")) - + with open(argstmplfile) as f: argstmpl = Template(f.read()) @@ -99,10 +100,10 @@ if len(options) > 0: # Use longest name opt_name = max(arg_map + (opt_name, ), key=len) return opt_name.replace("--", "") - + def get_opt_descr(opt): return options[opt].get('help', '').replace("*", "\*") - + def get_opt_choices(opt): return options[opt].get('choices', options[opt].get('metavar', '')).replace('[', '').replace(']', '').replace(',', ' | ').replace('\'', '') @@ -115,12 +116,14 @@ if len(options) > 0: f.write("\n") print("Wrote %s" % include_file) + argument_edit = Path(include_file).read_text() + kwargs = { 'opt': opt_name, 'ticks': '`' * len(opt_name), 'descr': get_opt_descr(opt), 'parameter': "**Options:** *%s*" % get_opt_choices(opt) if get_opt_choices(opt) else "", - 'include': ".. include:: ../arguments_edit/%s" % os.path.basename(include_file), + 'include': argument_edit, 'editfile': os.path.join("arguments_edit", os.path.basename(include_file)), } @@ -148,4 +151,4 @@ if len(options) > 0: else: - print("No strings found") \ No newline at end of file + print("No strings found")