cx_Freeze icon indicating copy to clipboard operation
cx_Freeze copied to clipboard

install-script option from distutils for bdist_msi not found

Open AlexEshoo opened this issue 6 years ago • 1 comments

I am trying to use cx_Freeze to create an MSI file formy program. I have successfully built one with the package with the following options configured:

build_exe_options = {"packages": ["myPackages"],
                     "include_files": ["myFiles"]}

msi_options = {"upgrade_code": myCode,
               "add_to_path": True,
               "target_name": "myTarget"}

setup(name="myApplication",
      version=app_version,
      description="myDescription",
      options={"build_exe": build_exe_options,
               "bdist_msi": msi_options},
      executables=[Executable("my_python_script.py", base=None,
                              targetName="myExecutable.exe")])

Now I would like to add functionality that when the MSI file is run, a script (bat file) runs before or after (or both) the installation is completed. I found here in the distutils.command.bdist_msi.bdist_msi class inherited by cx_freeze's own bdist_msi that there is an option called install-script which claims to run after installation and before uninstallation:

cpython/Lib/distutils/command/bdist_msi.py

class bdist_msi(Command):

    description = "create a Microsoft Installer (.msi) binary distribution"

    user_options = [('bdist-dir=', None,
                     "temporary directory for creating the distribution"),
                    ('plat-name=', 'p',
                     "platform name to embed in generated filenames "
                     "(default: %s)" % get_platform()),
                    ('keep-temp', 'k',
                     "keep the pseudo-installation tree around after " +
                     "creating the distribution archive"),
                    ('target-version=', None,
                     "require a specific python version" +
                     " on the target system"),
                    ('no-target-compile', 'c',
                     "do not compile .py to .pyc on the target system"),
                    ('no-target-optimize', 'o',
                     "do not compile .py to .pyo (optimized)"
                     "on the target system"),
                    ('dist-dir=', 'd',
                     "directory to put final built distributions in"),
                    ('skip-build', None,
                     "skip rebuilding everything (for testing/debugging)"),
                    ('install-script=', None,
                     "basename of installation script to be run after"
                     "installation or before deinstallation"),
                    ('pre-install-script=', None,
                     "Fully qualified filename of a script to be run before "
                     "any files are installed.  This script need not be in the "
                     "distribution"),
                   ]

It looks like in the bdist_msi class from cx_freeze, that these options are inherited:

cx_Freeze/windist.py

class bdist_msi(distutils.command.bdist_msi.bdist_msi):
    user_options = distutils.command.bdist_msi.bdist_msi.user_options + [
        ('add-to-path=', None, 'add target dir to PATH environment variable'),
        ('upgrade-code=', None, 'upgrade code to use'),
        ('initial-target-dir=', None, 'initial target directory'),
        ('target-name=', None, 'name of the file to create'),
        ('directories=', None, 'list of 3-tuples of directories to create'),
        ('environment-variables=', None, 'list of environment variables'),
        ('data=', None, 'dictionary of data indexed by table name'),
        ('product-code=', None, 'product code to use'),
        ('install-icon=', None, 'icon path to add/remove programs ')
    ]

However when I add the install-script option to the msi_options dict and run python setup.py bdist_msi I get an error: error: error in setup script: command 'bdist_msi' has no such option 'install-script'. I also tried with the similar option pre-install-script and this also did not work.

What could be the cause and how can I achieve what I am trying to do?

AlexEshoo avatar Oct 16 '18 18:10 AlexEshoo

In the setup command you need to pass a parameter scripts = ["your_script_name.ext", ], this stops the error for me but doesn't necessarily get the script to execute.

GadgetSteve avatar May 19 '20 06:05 GadgetSteve