1616import os
1717import sys
1818import os .path as osp
19+ import subprocess
20+ import shutil
21+ import atexit
1922
2023import setuptools # analysis:ignore
2124from distutils .core import setup
@@ -63,7 +66,6 @@ def get_package_data(name, extlist):
6366 flist .append (osp .join (dirpath , fname )[offset :])
6467 return flist
6568
66-
6769def get_subpackages (name ):
6870 """Return subpackages of package *name*"""
6971 splist = []
@@ -72,12 +74,47 @@ def get_subpackages(name):
7274 splist .append ("." .join (dirpath .split (os .sep )))
7375 return splist
7476
77+ def build_chm_doc (libname ):
78+ """Return CHM documentation file (on Windows only), which is copied under
79+ {PythonInstallDir}\Doc, hence allowing Spyder to add an entry for opening
80+ package documentation in "Help" menu. This has no effect on a source
81+ distribution."""
82+ args = '' .join (sys .argv )
83+ if os .name == 'nt' and ('bdist' in args or 'build' in args ):
84+ try :
85+ import sphinx # analysis:ignore
86+ except ImportError :
87+ print ('Warning: `sphinx` is required to build documentation' ,
88+ file = sys .stderr )
89+ return
90+ hhc_base = r'C:\Program Files%s\HTML Help Workshop\hhc.exe'
91+ for hhc_exe in (hhc_base % '' , hhc_base % ' (x86)' ):
92+ if osp .isfile (hhc_exe ):
93+ break
94+ else :
95+ print ('Warning: `HTML Help Workshop` is required to build CHM ' \
96+ 'documentation file' , file = sys .stderr )
97+ return
98+ doctmp_dir = 'doctmp'
99+ subprocess .call ('sphinx-build -b htmlhelp doc %s' % doctmp_dir ,
100+ shell = True )
101+ atexit .register (shutil .rmtree , osp .abspath (doctmp_dir ))
102+ fname = osp .abspath (osp .join (doctmp_dir , '%s.chm' % libname ))
103+ subprocess .call ('"%s" %s' % (hhc_exe , fname ), shell = True )
104+ if osp .isfile (fname ):
105+ return fname
106+ else :
107+ print ('Warning: CHM building process failed' , file = sys .stderr )
108+
109+ CHM_DOC = build_chm_doc (LIBNAME )
110+
75111
76112setup (name = LIBNAME , version = version ,
77113 description = DESCRIPTION , long_description = LONG_DESCRIPTION ,
78114 packages = get_subpackages (PACKAGE_NAME ),
79115 package_data = {PACKAGE_NAME :
80116 get_package_data (PACKAGE_NAME , ('.png' , '.svg' , '.mo' ))},
117+ data_files = [(r'Doc' , [CHM_DOC ])] if CHM_DOC else [],
81118 install_requires = ["NumPy>=1.3" ],
82119 extras_require = {
83120 'Doc' : ["Sphinx>=1.1" ],
0 commit comments