11import subprocess
2+ from argparse import ArgumentParser , Namespace
23from pathlib import Path
34from tempfile import TemporaryDirectory
45
1819# translated site in a given language.
1920
2021
21- def markdown_to_pot (docs_path : Path , working_path : Path ) -> None :
22+ def parse_args () -> Namespace :
23+ parser = ArgumentParser ()
24+ parser .add_argument ("-d" , "--docs-directory" , type = Path , default = "docs" )
25+ args = parser .parse_args ()
26+
27+ return args
28+
29+
30+ def markdown_to_pot (docs : Path , working_path : Path ) -> None :
2231 """
2332 Run `md2po` with provided input and output directories, with `--pot` flag to
2433 generate PO template (POT) files.
@@ -30,21 +39,20 @@ def markdown_to_pot(docs_path: Path, working_path: Path) -> None:
3039 * `--timestamp` ensures that new files are only generated when there is new
3140 content.
3241
33- :param docs_path: A directory fragment, relative to the project root,
34- containing the `en` Markdown content and `locales` translation files
35- directories.
42+ :param docs: The directory fragment, relative to the root path, containing
43+ the `en` Markdown content and `locales` translation files directories.
3644 :param working_path: The directory considered `/` for the input file call.
3745 This ensures that the location strings are accurate in the POT and PO
3846 files.
3947 """
4048 # Ensure the output directory exists
41- output_path = Path .cwd () / docs_path / "locales/template"
49+ output_path = Path .cwd () / docs / "locales/template"
4250 output_path .mkdir (parents = True , exist_ok = True )
4351
4452 subprocess .run (
4553 [
4654 "md2po" ,
47- f"--input={ docs_path / 'en' } " ,
55+ f"--input={ docs / 'en' } " ,
4856 f"--output={ output_path / 'translations.pot' } " ,
4957 "--pot" ,
5058 "--timestamp" ,
@@ -56,40 +64,39 @@ def markdown_to_pot(docs_path: Path, working_path: Path) -> None:
5664 )
5765
5866
59- def generate_pot_files (docs_path : Path ) -> None :
67+ def generate_pot_files (docs : Path ) -> None :
6068 """
6169 Generate the PO template (POT) files for the content in the provided
6270 directory.
6371
64- :param docs_path: A directory fragment, relative to the project root,
65- containing the `en` Markdown content and `locales` translation files
66- directories. This will become the msg* string location prefix in the
67- generated POT files.
72+ :param docs: The directory fragment, relative to the root path, containing
73+ the `en` Markdown content and `locales` translation files directories.
74+ This will become the msg* string location prefix in the generated POT
75+ files.
6876 """
6977 with TemporaryDirectory () as temp_working_directory :
7078 temp_working_path = Path (temp_working_directory )
7179
72- (temp_working_path / docs_path ).parent .mkdir (parents = True , exist_ok = True )
80+ (temp_working_path / docs ).parent .mkdir (parents = True , exist_ok = True )
7381
7482 try :
75- (temp_working_path / docs_path ).symlink_to (
76- Path .cwd () / docs_path ,
83+ (temp_working_path / docs ).symlink_to (
84+ Path .cwd () / docs ,
7785 target_is_directory = True ,
7886 )
7987 except FileExistsError :
8088 pass
8189
8290 markdown_to_pot (
83- docs_path = docs_path ,
91+ docs = docs ,
8492 working_path = temp_working_path ,
8593 )
8694
8795
8896def main ():
89- # Generate primary content POT files.
90- generate_pot_files (Path ("docs" ))
91- # # Generate shared content POT files.
92- generate_pot_files (Path ("src/beeware_docs_tools/shared_content" ))
97+ args = parse_args ()
98+ # Generate POT files.
99+ generate_pot_files (args .docs_directory )
93100
94101
95102if __name__ == "__main__" :
0 commit comments