Skip to content

Commit d4ff421

Browse files
author
stonebig
committed
re-add this because of winpython wheel creation
1 parent 154cdaa commit d4ff421

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

winpython/utils.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,64 @@ def get_source_package_infos(fname):
492492
if match is not None:
493493
return match.groups()[:2]
494494

495+
def build_wininst(root, python_exe=None, copy_to=None,
496+
architecture=None, verbose=False, installer='bdist_wininst'):
497+
"""Build wininst installer from Python package located in *root*
498+
and eventually copy it to *copy_to* folder.
499+
Return wininst installer full path."""
500+
if python_exe is None:
501+
python_exe = sys.executable
502+
assert osp.isfile(python_exe)
503+
cmd = [python_exe, 'setup.py', 'build']
504+
if architecture is not None:
505+
archstr = 'win32' if architecture == 32 else 'win-amd64'
506+
cmd += ['--plat-name=%s' % archstr]
507+
cmd += [installer]
508+
# root = a tmp dir in windows\tmp,
509+
if verbose:
510+
subprocess.call(cmd, cwd=root)
511+
else:
512+
p = subprocess.Popen(cmd, cwd=root, stdout=subprocess.PIPE,
513+
stderr=subprocess.PIPE)
514+
p.communicate()
515+
p.stdout.close()
516+
p.stderr.close()
517+
distdir = osp.join(root, 'dist')
518+
if not osp.isdir(distdir):
519+
raise RuntimeError("Build failed: see package README file for further"
520+
" details regarding installation requirements.\n\n"
521+
"For more concrete debugging infos, please try to build "
522+
"the package from the command line:\n"
523+
"1. Open a WinPython command prompt\n"
524+
"2. Change working directory to the appropriate folder\n"
525+
"3. Type `python setup.py build install`")
526+
pattern = WININST_PATTERN.replace(r'(win32|win\-amd64)', archstr)
527+
for distname in os.listdir(distdir):
528+
match = re.match(pattern, distname)
529+
if match is not None:
530+
break
531+
# for wheels (winpython here)
532+
match = re.match(SOURCE_PATTERN, distname)
533+
if match is not None:
534+
break
535+
match = re.match(WHEELBIN_PATTERN, distname)
536+
if match is not None:
537+
break
538+
else:
539+
raise RuntimeError("Build failed: not a pure Python package? %s" %
540+
distdir)
541+
src_fname = osp.join(distdir, distname)
542+
if copy_to is None:
543+
return src_fname
544+
else:
545+
dst_fname = osp.join(copy_to, distname)
546+
shutil.move(src_fname, dst_fname)
547+
if verbose:
548+
print(("Move: %s --> %s" % (src_fname, (dst_fname))))
549+
# remove tempo dir 'root' no more needed
550+
shutil.rmtree(root, onerror=onerror)
551+
return dst_fname
552+
495553

496554
def direct_pip_install(fname, python_exe=None, architecture=None,
497555
verbose=False, install_options=None):

0 commit comments

Comments
 (0)