-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Variant script for stuffing docs in wheel
- Loading branch information
1 parent
e78590a
commit 44c0e0f
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
|
||
|
||
|
||
|