[Distutils] Fwd: setup('postinstall'='my.py')

Jeremy Kloth jeremy.kloth at gmail.com
Wed Feb 3 13:57:43 EST 2016

Resending to list...

---------- Forwarded message ----------
From: Jeremy Kloth <jeremy.kloth at gmail.com>
Date: Wed, Feb 3, 2016 at 10:50 AM
Subject: Re: [Distutils] setup('postinstall'='my.py')
To: AltSheets Dev <altsheets+mailinglists at gmail.com>

It appears that you are using bdist_wininst to create the installer.
So you are in luck!  The bdist_wininst command supports running simple
scripts at a few points in the installation process.

First is at the pre-install phase.  This script doesn't need to be
included in the installed files as it stored in the installer binary
directly.  The next phase is post-install (after all files have been
copied).  This script *does* need to be included in the distribution,
using the 'scripts' setup() argument.  Finally, there is the
pre-uninstall phase.  This script is the same one as the post-install

When run, the scripts have a few additional built-in functions available:
- create_shortcut(path, desc, filename, [arguments, [workingdir,
[iconpath, [iconindex]]]])
- get_special_folder_path(csidl_name)
- get_root_hkey()
- file_created(path)
- directory_created(path)
- message_box(text, caption, flags)

To use an installer script, you need to pass options to the
bdist_wininst command.  '--pre-install-script=<pathname>' for the
pre-install script, where 'pathname' is the path to the script to
include (relative to setup.py or fully-qualified).
'--install-script=<scriptname>' for the post-install/pre-uninstall
script, where 'scriptname' is the name used in the 'scripts' argument.
distutils command options can be passed on the command-line or the
'command_options' argument to setup().

Unfortunately, to add a file to the installation you need to determine
the full install path yourself in the install script.

Here is (an untested) set of additions that should achieve what you
are asking for.


      command_options={'bdist_wininst': {'pre-install-script':


import os, sys

# using functions you have already defined in 'setupCustom.py' but
should be included directly
sitedir = os.path.join(sys.prefix, 'Lib', 'site-packages')
uidfile = os.path.join(sitedir, SUBFOLDER, 'UID.py')
# log the file so the installer removes it on uninstall

Hope this helps!

Jeremy Kloth

More information about the Distutils-SIG mailing list