xref: /petsc/doc/build_manpages_c2html.py (revision 6edbc3c8692527c96faed8c6adc9f71d1f7e8b83)
1c6267af9SBarry Smith#!/usr/bin/env python3
2c6267af9SBarry Smith""" Configure PETSc and build and place the generated manual pages (as .md files) and html source (as .html files)"""
3c6267af9SBarry Smith
4c6267af9SBarry Smithimport os
5c6267af9SBarry Smithimport errno
6c6267af9SBarry Smithimport subprocess
7c6267af9SBarry Smithimport shutil
8c6267af9SBarry Smithimport argparse
9c6267af9SBarry Smithimport re
10c6267af9SBarry Smith
11c6267af9SBarry Smithrawhtml = ['include', 'src']
12c6267af9SBarry Smithpetsc_arch = 'arch-docs'
13c6267af9SBarry Smith
14*7f019730SBarry Smithdef main(stage,petsc_dir,build_dir,outdir):
15c6267af9SBarry Smith    """ Operations to provide data for PETSc manual pages and c2html files. """
16c6267af9SBarry Smith    import time
17*7f019730SBarry Smith
18c6267af9SBarry Smith    if stage == "pre":
19c6267af9SBarry Smith      if 'PETSC_ARCH' in os.environ: del os.environ['PETSC_ARCH']
20c6267af9SBarry Smith      if 'MAKEFLAGS' in os.environ: del os.environ['MAKEFLAGS']
21c6267af9SBarry Smith      command = ['./configure',
22c6267af9SBarry Smith                 '--with-coverage-exec=0',
23c6267af9SBarry Smith                 '--with-mpi=0',
24c6267af9SBarry Smith                 '--with-cxx=0',
25c6267af9SBarry Smith                 '--with-syclc=0',
26c6267af9SBarry Smith                 '--with-hipc=0',
27c6267af9SBarry Smith                 '--with-cudac=0',
28c6267af9SBarry Smith                 '--with-x=0',
29c6267af9SBarry Smith                 '--with-bison=0',
30c6267af9SBarry Smith                 '--with-cmake=0',
31c6267af9SBarry Smith                 '--with-pthread=0',
32c6267af9SBarry Smith                 '--with-mkl_sparse_optimize=0',
33c6267af9SBarry Smith                 '--with-mkl_sparse=0',
34c6267af9SBarry Smith                 '--with-debugging=0',
3507f25ad1SSatish Balay                 '--download-sowing=1',
36c6267af9SBarry Smith                 'COPTFLAS=-O0',
37c6267af9SBarry Smith                 '--with-petsc4py',
38c6267af9SBarry Smith                 'PETSC_ARCH=' + petsc_arch,
39c6267af9SBarry Smith                ]
40c6267af9SBarry Smith      if 'PETSCBUIDTARBALL' in os.environ:
41c6267af9SBarry Smith        command.append('--download-c2html')
42c6267af9SBarry Smith        command.append('--download-sowing')
43c6267af9SBarry Smith        c2html = None
44c6267af9SBarry Smith        doctext = None
45c6267af9SBarry Smith      else:
46c6267af9SBarry Smith        command.append('--with-fc=0')
47c6267af9SBarry Smith        c2html = shutil.which('c2html')
48c6267af9SBarry Smith        if c2html: command.append('--with-c2html')
49c6267af9SBarry Smith        else:  command.append('--download-c2html')
50c6267af9SBarry Smith        doctext = shutil.which('doctext')
51c6267af9SBarry Smith        if doctext: command.append('--with-sowing')
52c6267af9SBarry Smith        else:  command.append('--download-sowing')
53c6267af9SBarry Smith
54c6267af9SBarry Smith      x = time.clock_gettime(time.CLOCK_REALTIME)
55c6267af9SBarry Smith      print('==================================================================')
56c6267af9SBarry Smith      print('Running configure')
57c6267af9SBarry Smith      subprocess.run(command, cwd=petsc_dir, check=True)
58c6267af9SBarry Smith      print("Time: "+str(time.clock_gettime(time.CLOCK_REALTIME) - x))
59c6267af9SBarry Smith      print('==================================================================')
60c6267af9SBarry Smith      if not doctext:
61c6267af9SBarry Smith        with open(os.path.join(petsc_dir,petsc_arch,'lib','petsc','conf','petscvariables')) as f:
62c6267af9SBarry Smith          doctext = [line for line in f if line.find('DOCTEXT ') > -1]
63c6267af9SBarry Smith          doctext = re.sub('[ ]*DOCTEXT[ ]*=[ ]*','',doctext[0]).strip('\n').strip()
64c6267af9SBarry Smith      print('Using DOCTEXT:', doctext)
65c6267af9SBarry Smith
66c6267af9SBarry Smith      import build_man_pages
67c6267af9SBarry Smith      x = time.clock_gettime(time.CLOCK_REALTIME)
68c6267af9SBarry Smith      print('============================================')
69c6267af9SBarry Smith      print('Building all manual pages')
70*7f019730SBarry Smith      build_man_pages.main(petsc_dir,build_dir,doctext)
71c6267af9SBarry Smith      print("Time: "+str(time.clock_gettime(time.CLOCK_REALTIME) - x))
72c6267af9SBarry Smith      print('============================================')
73c6267af9SBarry Smith
74c6267af9SBarry Smith      import build_man_examples_links
75c6267af9SBarry Smith      x = time.clock_gettime(time.CLOCK_REALTIME)
76c6267af9SBarry Smith      print('============================================')
77c6267af9SBarry Smith      print('Building manual page links to tutorials')
78*7f019730SBarry Smith      build_man_examples_links.main(petsc_dir,build_dir)
79c6267af9SBarry Smith      print("Time: "+str(time.clock_gettime(time.CLOCK_REALTIME) - x))
80c6267af9SBarry Smith      print('============================================')
81c6267af9SBarry Smith
82c6267af9SBarry Smith      import build_man_impls_links
83c6267af9SBarry Smith      x = time.clock_gettime(time.CLOCK_REALTIME)
84c6267af9SBarry Smith      print('============================================')
85c6267af9SBarry Smith      print('Building manual page links to implementations')
86*7f019730SBarry Smith      build_man_impls_links.main(petsc_dir,build_dir)
87c6267af9SBarry Smith      print("Time: "+str(time.clock_gettime(time.CLOCK_REALTIME) - x))
88c6267af9SBarry Smith      print('============================================')
89c6267af9SBarry Smith
90c6267af9SBarry Smith      import build_man_index
91c6267af9SBarry Smith      x = time.clock_gettime(time.CLOCK_REALTIME)
92c6267af9SBarry Smith      print('============================================')
93c6267af9SBarry Smith      print('Building manual page indices')
94*7f019730SBarry Smith      build_man_index.main(petsc_dir,build_dir)
95c6267af9SBarry Smith      print("Time: "+str(time.clock_gettime(time.CLOCK_REALTIME) - x))
96c6267af9SBarry Smith      print('============================================')
97c6267af9SBarry Smith    else:
98c6267af9SBarry Smith      if not os.path.isfile(os.path.join(petsc_dir, "configure.log")): raise Exception("Expected PETSc configuration not found")
99c6267af9SBarry Smith      c2html = shutil.which('c2html')
100c6267af9SBarry Smith      if not c2html:
101c6267af9SBarry Smith        with open(os.path.join(petsc_dir,petsc_arch,'lib','petsc','conf','petscvariables')) as f:
102c6267af9SBarry Smith          c2html = [line for line in f if line.find('C2HTML ') > -1]
103c6267af9SBarry Smith          c2html = re.sub('[ ]*C2HTML[ ]*=[ ]*','',c2html[0]).strip('\n').strip()
104c6267af9SBarry Smith      print('Using C2HTML:', c2html)
105c6267af9SBarry Smith      mapnames = shutil.which('mapnames')
106c6267af9SBarry Smith      if not mapnames:
107c6267af9SBarry Smith        with open(os.path.join(petsc_dir,petsc_arch,'lib','petsc','conf','petscvariables')) as f:
108c6267af9SBarry Smith          mapnames = [line for line in f if line.find('MAPNAMES ') > -1]
109c6267af9SBarry Smith          mapnames = re.sub('[ ]*MAPNAMES[ ]*=[ ]*','',mapnames[0]).strip('\n').strip()
110c6267af9SBarry Smith      print('Using MAPNAMES:', mapnames)
111c6267af9SBarry Smith      import build_c2html
112c6267af9SBarry Smith      x = time.clock_gettime(time.CLOCK_REALTIME)
113c6267af9SBarry Smith      print('============================================')
114c6267af9SBarry Smith      print('Building c2html')
115*7f019730SBarry Smith      build_c2html.main(petsc_dir,build_dir,outdir,c2html,mapnames)
116c6267af9SBarry Smith      print("Time: "+str(time.clock_gettime(time.CLOCK_REALTIME) - x))
117c6267af9SBarry Smith      print('============================================')
118