annotate roundup/dist/command/build_doc.py @ 8180:d02ce1d14acd

feat: issue2551068 - Provide way to retrieve file/msg data via rest endpoint. Use Allow header to change format of /binary_content endpoint. If Allow header for endpoint is not application/json, it will be matched against the mime type for the file. */*, text/* are supported and will return the native mime type if present. Changes: move */* mime type from static dict of supported types. It was hardcoded to return json only. Now it can return a matching non-json mime type for the /binary_content endpoint. Edited some errors to explicitly add */* mime type. Cleanups to use ', ' separation in lists of valid mime types rather than just space separated. Remove ETag header when sending raw content. See issue 2551375 for background. Doc added to rest.txt. Small format fix up (add dash) in CHANGES.txt. Make passing an unset/None/False accept_mime_type to format_dispatch_output a 500 error. This used to be the fallback to produce a 406 error after all processing had happened. It should no longer be possible to take that code path as all 406 errors (with valid accept_mime_types) are generated before processing takes place. Make format_dispatch_output handle output other than json/xml so it can send back binary_content data. Removed a spurious client.response_code = 400 that seems to not be used. Tests added for all code paths. Database setup for tests msg and file entry. This required a file upload test to change so it doesn't look for file1 as the link returned by the upload. Download the link and verify the data rather than verifying the link. Multiple formatting changes to error messages to make all lists of valid mime types ', ' an not just space separated.
author John Rouillard <rouilj@ieee.org>
date Sun, 08 Dec 2024 17:22:33 -0500
parents d2ca7b1bfc6b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4033
bca7c59ac400 Enhance documentation generation.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
1 #
bca7c59ac400 Enhance documentation generation.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
2 # Copyright (C) 2009 Stefan Seefeld
bca7c59ac400 Enhance documentation generation.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
3 # All rights reserved.
bca7c59ac400 Enhance documentation generation.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
4 # For license terms see the file COPYING.txt.
bca7c59ac400 Enhance documentation generation.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
5 #
bca7c59ac400 Enhance documentation generation.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
6
bca7c59ac400 Enhance documentation generation.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
7 import os, sys
bca7c59ac400 Enhance documentation generation.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
8 import os.path
bca7c59ac400 Enhance documentation generation.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
9
6647
42bf0a707763 issue2551183 - Replace references to distutils in roundup/dist/command
John Rouillard <rouilj@ieee.org>
parents: 5074
diff changeset
10 try:
42bf0a707763 issue2551183 - Replace references to distutils in roundup/dist/command
John Rouillard <rouilj@ieee.org>
parents: 5074
diff changeset
11 from setuptools.command.install import install as _build_py
42bf0a707763 issue2551183 - Replace references to distutils in roundup/dist/command
John Rouillard <rouilj@ieee.org>
parents: 5074
diff changeset
12 except ImportError:
42bf0a707763 issue2551183 - Replace references to distutils in roundup/dist/command
John Rouillard <rouilj@ieee.org>
parents: 5074
diff changeset
13 from distutils.command.build import build as _build_py # try/except clause
42bf0a707763 issue2551183 - Replace references to distutils in roundup/dist/command
John Rouillard <rouilj@ieee.org>
parents: 5074
diff changeset
14 orig_build = _build_py
4033
bca7c59ac400 Enhance documentation generation.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
15
6647
42bf0a707763 issue2551183 - Replace references to distutils in roundup/dist/command
John Rouillard <rouilj@ieee.org>
parents: 5074
diff changeset
16 try:
42bf0a707763 issue2551183 - Replace references to distutils in roundup/dist/command
John Rouillard <rouilj@ieee.org>
parents: 5074
diff changeset
17 # would be nice to use setuptools.Command.spawn() as it
42bf0a707763 issue2551183 - Replace references to distutils in roundup/dist/command
John Rouillard <rouilj@ieee.org>
parents: 5074
diff changeset
18 # obeys the dry-run flag.
42bf0a707763 issue2551183 - Replace references to distutils in roundup/dist/command
John Rouillard <rouilj@ieee.org>
parents: 5074
diff changeset
19 from subprocess import run as spawn
42bf0a707763 issue2551183 - Replace references to distutils in roundup/dist/command
John Rouillard <rouilj@ieee.org>
parents: 5074
diff changeset
20 except ImportError:
42bf0a707763 issue2551183 - Replace references to distutils in roundup/dist/command
John Rouillard <rouilj@ieee.org>
parents: 5074
diff changeset
21 from distutils.spawn import spawn # try/except: in except for subprocess
42bf0a707763 issue2551183 - Replace references to distutils in roundup/dist/command
John Rouillard <rouilj@ieee.org>
parents: 5074
diff changeset
22
42bf0a707763 issue2551183 - Replace references to distutils in roundup/dist/command
John Rouillard <rouilj@ieee.org>
parents: 5074
diff changeset
23 try:
42bf0a707763 issue2551183 - Replace references to distutils in roundup/dist/command
John Rouillard <rouilj@ieee.org>
parents: 5074
diff changeset
24 from distutils.spawn import find_executable # try/except: in try local find
42bf0a707763 issue2551183 - Replace references to distutils in roundup/dist/command
John Rouillard <rouilj@ieee.org>
parents: 5074
diff changeset
25 except ImportError:
42bf0a707763 issue2551183 - Replace references to distutils in roundup/dist/command
John Rouillard <rouilj@ieee.org>
parents: 5074
diff changeset
26 from roundup.dist.command import find_executable
42bf0a707763 issue2551183 - Replace references to distutils in roundup/dist/command
John Rouillard <rouilj@ieee.org>
parents: 5074
diff changeset
27
42bf0a707763 issue2551183 - Replace references to distutils in roundup/dist/command
John Rouillard <rouilj@ieee.org>
parents: 5074
diff changeset
28 class build_doc(_build_py):
4033
bca7c59ac400 Enhance documentation generation.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
29 """Defines the specific procedure to build roundup's documentation."""
bca7c59ac400 Enhance documentation generation.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
30
bca7c59ac400 Enhance documentation generation.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
31 description = "build documentation"
bca7c59ac400 Enhance documentation generation.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
32
bca7c59ac400 Enhance documentation generation.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
33 def run(self):
bca7c59ac400 Enhance documentation generation.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
34 """Run this command, i.e. do the actual document generation."""
bca7c59ac400 Enhance documentation generation.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
35
bca7c59ac400 Enhance documentation generation.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
36 sphinx = find_executable('sphinx-build')
4810
7b575e1f7368 setup.py build_doc: try Python-installed Sphinx if command
anatoly techtonik <techtonik@gmail.com>
parents: 4033
diff changeset
37 if sphinx:
7b575e1f7368 setup.py build_doc: try Python-installed Sphinx if command
anatoly techtonik <techtonik@gmail.com>
parents: 4033
diff changeset
38 sphinx = [sphinx]
7b575e1f7368 setup.py build_doc: try Python-installed Sphinx if command
anatoly techtonik <techtonik@gmail.com>
parents: 4033
diff changeset
39 else:
7b575e1f7368 setup.py build_doc: try Python-installed Sphinx if command
anatoly techtonik <techtonik@gmail.com>
parents: 4033
diff changeset
40 try: # try to find version installed with Python tools
7b575e1f7368 setup.py build_doc: try Python-installed Sphinx if command
anatoly techtonik <techtonik@gmail.com>
parents: 4033
diff changeset
41 # tested with Sphinx 1.1.3
7b575e1f7368 setup.py build_doc: try Python-installed Sphinx if command
anatoly techtonik <techtonik@gmail.com>
parents: 4033
diff changeset
42 import sphinx as sp
7b575e1f7368 setup.py build_doc: try Python-installed Sphinx if command
anatoly techtonik <techtonik@gmail.com>
parents: 4033
diff changeset
43 except ImportError:
7b575e1f7368 setup.py build_doc: try Python-installed Sphinx if command
anatoly techtonik <techtonik@gmail.com>
parents: 4033
diff changeset
44 pass
7b575e1f7368 setup.py build_doc: try Python-installed Sphinx if command
anatoly techtonik <techtonik@gmail.com>
parents: 4033
diff changeset
45 else:
7b575e1f7368 setup.py build_doc: try Python-installed Sphinx if command
anatoly techtonik <techtonik@gmail.com>
parents: 4033
diff changeset
46 sphinx = [sys.executable, sp.__file__]
7b575e1f7368 setup.py build_doc: try Python-installed Sphinx if command
anatoly techtonik <techtonik@gmail.com>
parents: 4033
diff changeset
47
4033
bca7c59ac400 Enhance documentation generation.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
48 if not sphinx:
bca7c59ac400 Enhance documentation generation.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
49 self.warn("could not find sphinx-build in PATH")
bca7c59ac400 Enhance documentation generation.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
50 self.warn("cannot build documentation")
bca7c59ac400 Enhance documentation generation.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
51 return
bca7c59ac400 Enhance documentation generation.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
52
bca7c59ac400 Enhance documentation generation.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
53 doc_dir = os.path.join('share', 'doc', 'roundup', 'html')
7416
302ce182ffd3 Replace build_temp with build_base
John Rouillard <rouilj@ieee.org>
parents: 7412
diff changeset
54 temp_dir = os.path.join(self.build_base, 'temp.doc')
4810
7b575e1f7368 setup.py build_doc: try Python-installed Sphinx if command
anatoly techtonik <techtonik@gmail.com>
parents: 4033
diff changeset
55 cmd = sphinx + ['-d', temp_dir, 'doc', doc_dir]
4033
bca7c59ac400 Enhance documentation generation.
Stefan Seefeld <stefan@seefeld.name>
parents:
diff changeset
56 spawn(cmd)

Roundup Issue Tracker: http://roundup-tracker.org/