Skip to content

Commit

Permalink
Variant script for stuffing docs in wheel
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanDunfield committed Nov 27, 2024
1 parent e78590a commit 44c0e0f
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions doc_src/build_doc_add_to_wheel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""
Builds the docs with the current Python and adds them to the given wheel.
"""

import subprocess
import sys
import os
import tempfile
import glob
import shutil

wheel_path = os.path.abspath(sys.argv[1])

if not wheel_path.endswith('.whl'):
raise ValueError('Usage: python build_doc_add_to_wheel.py snappy.whl')

python = sys.executable
tmp_dir = tempfile.mkdtemp()
subprocess.check_call([python, '-m', 'sphinx', '-b', 'html', '-E',
'-d', tmp_dir + '/doctrees', '.', tmp_dir + '/doc'])
subprocess.check_call([python, '-m', 'wheel', 'unpack', '--dest', tmp_dir, wheel_path])
pkg, version = os.path.basename(wheel_path).split('-')[:2]
wheel_dir = os.path.join(tmp_dir, pkg + '-' + version)
target = os.path.join(wheel_dir, pkg)
target_doc_dir = os.path.join(target, 'doc')
if os.path.exists(target_doc_dir):
print('Deleting existing docs...')
shutil.rmtree(target_doc_dir)
print('Moving docs.')
shutil.move(tmp_dir + '/doc', target_doc_dir)
subprocess.check_call([python, '-m', 'wheel', 'pack', '--dest', tmp_dir, wheel_dir])
new_whl = glob.glob(os.path.join(tmp_dir, pkg + '-' + version + '*.whl'))[0]
if os.path.basename(new_whl) != os.path.basename(wheel_path):
raise ValueError(f'Wheel tag changed, see {tmp_dir}')
subprocess.check_call(['cp', new_whl, wheel_path])
print(f'Added docs to {os.path.basename(wheel_path)} in-place')




0 comments on commit 44c0e0f

Please sign in to comment.