Reputation: 681
I am working on packaging a series of Python scripts into a bundled EXE. The scripts are using the configparser module to handle SQL connection strings (among other things). I am looking for a way to create three versions of the EXE, one for each environment we elevate to. The only difference between each environment is the SQL server address.
I figured out how to include files, folders, etc. in the spec file and what I would like to do is call pyinstaller and feed it different SPEC files based off which environment I am building. Something like this for an integration SPEC file:
a = Analysis(['normalization_updater.py'],
binaries=[],
datas=[
('*.py', '.'),
('resources/config_int.cfg', 'resources/config.cfg')
],
and for PROD:
a = Analysis(['normalization_updater.py'],
binaries=[],
datas=[
('*.py', '.'),
('resources/config_prod.cfg', 'resources/config.cfg')
],
In other words, I want to rename the config file being bundled into the EXE based off which SPEC file is used via the glob pattern.
Or is there a better way to handle feature toggles with pyinstaller EXE's? Perhaps feeding it a command line switch? If I am reading this right the docs say that's not possible.
You can pass command-line options to the Python interpreter. The interpreter takes a number of command-line options but only the following are supported for a bundled app:
v to write a message to stdout each time a module is initialized.
u for unbuffered stdio.
W and an option to change warning behavior: W ignore or W once or W error.
Upvotes: 1
Views: 2647
Reputation: 136
Not sure it is what you need but here how you can use a single spec file just changing a line in start
env='int'
a = Analysis(['normalization_updater.py'],
binaries=[],
datas=[
('*.py', '.'),
('resources/config_' + env + '.cfg', 'resources/config.cfg')
],
Upvotes: 2