Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6290315

Browse files
committed
Moveparse_args() andsetup_logging() aftermain()
1 parent667cd01 commit6290315

File tree

1 file changed

+103
-103
lines changed

1 file changed

+103
-103
lines changed

‎build_docs.py

Lines changed: 103 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -506,109 +506,6 @@ def version_info():
506506
)
507507

508508

509-
defparse_args():
510-
"""Parse command-line arguments."""
511-
512-
parser=ArgumentParser(
513-
description="Runs a build of the Python docs for various branches."
514-
)
515-
parser.add_argument(
516-
"--select-output",
517-
choices=("no-html","only-html","only-html-en"),
518-
help="Choose what outputs to build.",
519-
)
520-
parser.add_argument(
521-
"-q",
522-
"--quick",
523-
action="store_true",
524-
help="Run a quick build (only HTML files).",
525-
)
526-
parser.add_argument(
527-
"-b",
528-
"--branch",
529-
metavar="3.12",
530-
help="Version to build (defaults to all maintained branches).",
531-
)
532-
parser.add_argument(
533-
"-r",
534-
"--build-root",
535-
type=Path,
536-
help="Path to a directory containing a checkout per branch.",
537-
default=Path("/srv/docsbuild"),
538-
)
539-
parser.add_argument(
540-
"-w",
541-
"--www-root",
542-
type=Path,
543-
help="Path where generated files will be copied.",
544-
default=Path("/srv/docs.python.org"),
545-
)
546-
parser.add_argument(
547-
"--skip-cache-invalidation",
548-
help="Skip Fastly cache invalidation.",
549-
action="store_true",
550-
)
551-
parser.add_argument(
552-
"--group",
553-
help="Group files on targets and www-root file should get.",
554-
default="docs",
555-
)
556-
parser.add_argument(
557-
"--log-directory",
558-
type=Path,
559-
help="Directory used to store logs.",
560-
default=Path("/var/log/docsbuild/"),
561-
)
562-
parser.add_argument(
563-
"--languages",
564-
nargs="*",
565-
help="Language translation, as a PEP 545 language tag like"
566-
" 'fr' or 'pt-br'. "
567-
"Builds all available languages by default.",
568-
metavar="fr",
569-
)
570-
parser.add_argument(
571-
"--version",
572-
action="store_true",
573-
help="Get build_docs and dependencies version info",
574-
)
575-
parser.add_argument(
576-
"--theme",
577-
default="python-docs-theme",
578-
help="Python package to use for python-docs-theme: Useful to test branches:"
579-
" --theme git+https://github.com/obulat/python-docs-theme@master",
580-
)
581-
args=parser.parse_args()
582-
ifargs.version:
583-
version_info()
584-
sys.exit(0)
585-
delargs.version
586-
ifargs.log_directory:
587-
args.log_directory=args.log_directory.resolve()
588-
ifargs.build_root:
589-
args.build_root=args.build_root.resolve()
590-
ifargs.www_root:
591-
args.www_root=args.www_root.resolve()
592-
returnargs
593-
594-
595-
defsetup_logging(log_directory:Path,select_output:str|None):
596-
"""Setup logging to stderr if run by a human, or to a file if run from a cron."""
597-
log_format="%(asctime)s %(levelname)s: %(message)s"
598-
ifsys.stderr.isatty():
599-
logging.basicConfig(format=log_format,stream=sys.stderr)
600-
else:
601-
log_directory.mkdir(parents=True,exist_ok=True)
602-
ifselect_outputisNone:
603-
filename=log_directory/"docsbuild.log"
604-
else:
605-
filename=log_directory/f"docsbuild-{select_output}.log"
606-
handler=logging.handlers.WatchedFileHandler(filename)
607-
handler.setFormatter(logging.Formatter(log_format))
608-
logging.getLogger().addHandler(handler)
609-
logging.getLogger().setLevel(logging.DEBUG)
610-
611-
612509
@dataclass
613510
classDocBuilder:
614511
"""Builder for a CPython version and a language."""
@@ -1288,6 +1185,109 @@ def main():
12881185
build_docs_with_lock(args,"build_docs_html_en.lock")
12891186

12901187

1188+
defparse_args():
1189+
"""Parse command-line arguments."""
1190+
1191+
parser=ArgumentParser(
1192+
description="Runs a build of the Python docs for various branches."
1193+
)
1194+
parser.add_argument(
1195+
"--select-output",
1196+
choices=("no-html","only-html","only-html-en"),
1197+
help="Choose what outputs to build.",
1198+
)
1199+
parser.add_argument(
1200+
"-q",
1201+
"--quick",
1202+
action="store_true",
1203+
help="Run a quick build (only HTML files).",
1204+
)
1205+
parser.add_argument(
1206+
"-b",
1207+
"--branch",
1208+
metavar="3.12",
1209+
help="Version to build (defaults to all maintained branches).",
1210+
)
1211+
parser.add_argument(
1212+
"-r",
1213+
"--build-root",
1214+
type=Path,
1215+
help="Path to a directory containing a checkout per branch.",
1216+
default=Path("/srv/docsbuild"),
1217+
)
1218+
parser.add_argument(
1219+
"-w",
1220+
"--www-root",
1221+
type=Path,
1222+
help="Path where generated files will be copied.",
1223+
default=Path("/srv/docs.python.org"),
1224+
)
1225+
parser.add_argument(
1226+
"--skip-cache-invalidation",
1227+
help="Skip Fastly cache invalidation.",
1228+
action="store_true",
1229+
)
1230+
parser.add_argument(
1231+
"--group",
1232+
help="Group files on targets and www-root file should get.",
1233+
default="docs",
1234+
)
1235+
parser.add_argument(
1236+
"--log-directory",
1237+
type=Path,
1238+
help="Directory used to store logs.",
1239+
default=Path("/var/log/docsbuild/"),
1240+
)
1241+
parser.add_argument(
1242+
"--languages",
1243+
nargs="*",
1244+
help="Language translation, as a PEP 545 language tag like"
1245+
" 'fr' or 'pt-br'. "
1246+
"Builds all available languages by default.",
1247+
metavar="fr",
1248+
)
1249+
parser.add_argument(
1250+
"--version",
1251+
action="store_true",
1252+
help="Get build_docs and dependencies version info",
1253+
)
1254+
parser.add_argument(
1255+
"--theme",
1256+
default="python-docs-theme",
1257+
help="Python package to use for python-docs-theme: Useful to test branches:"
1258+
" --theme git+https://github.com/obulat/python-docs-theme@master",
1259+
)
1260+
args=parser.parse_args()
1261+
ifargs.version:
1262+
version_info()
1263+
sys.exit(0)
1264+
delargs.version
1265+
ifargs.log_directory:
1266+
args.log_directory=args.log_directory.resolve()
1267+
ifargs.build_root:
1268+
args.build_root=args.build_root.resolve()
1269+
ifargs.www_root:
1270+
args.www_root=args.www_root.resolve()
1271+
returnargs
1272+
1273+
1274+
defsetup_logging(log_directory:Path,select_output:str|None):
1275+
"""Setup logging to stderr if run by a human, or to a file if run from a cron."""
1276+
log_format="%(asctime)s %(levelname)s: %(message)s"
1277+
ifsys.stderr.isatty():
1278+
logging.basicConfig(format=log_format,stream=sys.stderr)
1279+
else:
1280+
log_directory.mkdir(parents=True,exist_ok=True)
1281+
ifselect_outputisNone:
1282+
filename=log_directory/"docsbuild.log"
1283+
else:
1284+
filename=log_directory/f"docsbuild-{select_output}.log"
1285+
handler=logging.handlers.WatchedFileHandler(filename)
1286+
handler.setFormatter(logging.Formatter(log_format))
1287+
logging.getLogger().addHandler(handler)
1288+
logging.getLogger().setLevel(logging.DEBUG)
1289+
1290+
12911291
defbuild_docs_with_lock(args:Namespace,lockfile_name:str)->int:
12921292
try:
12931293
lock=zc.lockfile.LockFile(HERE/lockfile_name)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp