-
Notifications
You must be signed in to change notification settings - Fork 7
Bundling qbank
If you need a standalone qbank
executable (for running with unplatform, for example), then you can use pyinstaller
to create a bundle. This should work with OS X, Windows, or Linux, whatever pyinstaller
supports. Note that to create a bundle for a platform, you need to run pyinstaller
on that specific platform. You cannot build Windows bundles on OS X.
The bundled package will run on port 8080
unless you manually change main.py
and insert the port before bundling, like:
if (not is_test()) and __name__ == "__main__":
sys.argv.append('9123')
app.run()
This is because pyinstaller
does not allow you to include command line arguments as part of the bundling process.
To bundle a Windows executable, for use with unplatform
, you need to install the following software on a Windows machine or VM (32bit if the field machines are 32bit):
- 32bit Windows VM or machine. (64bit is okay if your target platform supports it)
-
OpenSSL for Windows.
- Be sure to choose the installer that's compatible with your machine and is recommended for software developers. For example: if your virtual machine is running 32-bit Windows, select the 32-bit version of OpenSSL recommended for software developers.
- You might have to modify your system path to use OpenSSL in the command line. To test this, open Command Prompt and type
openssl
. If that command throws an exception, addopenssl
to your path by doing the following:- Close Command Prompt.
- Right click
My Computer
and selectProperties
. - Click
Advanced
. - Click
Environment Variables
. - Edit
Path
inSystem Variables
(notUser Variables
). - Click
New
in the variable window. - Type in
C:\OpenSSL-Win32\bin
, and save that. - Save and exit the
Properties
modal. - Open Command Prompt and type
openssl
and press the return button. If the command path changes toOpenSSL>
, you've successfully installed OpenSSL and configured your system path to use OpenSSL.
-
Python 2.7.
- You might have to modify your system path to use Python in the command line. To test this, open Command Prompt and type
python
. If that command throws an exception, addpython
to your path by doing the following:- Close Command Prompt.
- Right click
My Computer
and selectProperties
. - Click
Advanced
. - Click
Environment Variables
. - Edit
Path
inSystem Variables
(notUser Variables
). - Click
New
in the variable window. - Type in
C:\Python27
, and save that. -
Edit
thePath
again. - Click
New
again. - Type in
C:\Python27\Scripts
, and save that. - Save and exit the
Properties
modal. - Open Command Prompt and type
python
and press the return button. If the command path changes to>>>
, you've successfully installed Python and configured your system path to use Python.
- You might have to modify your system path to use Python in the command line. To test this, open Command Prompt and type
- Git for Windows.
- Virtualenv:
pip install virtualenv
- Depends on Python. Install that first.
-
Virtualenv wrapper.
- Depends on
virtualenv
. Install that first.
- Depends on
-
lxml.
- Depends on
python
. Install that first. - You most likely need the
cp27
andcp27m
32-bit versions, i.e. lxml‑3.7.3‑cp27‑cp27m‑win32.whl. - Download the above wheel, and run
pip install lxml‑3.7.3‑cp27‑cp27m‑win32.whl
. More detailed discussion around this is here.
- Depends on
(once you have all the dependencies installed) In a command prompt window:
- mkvirtualenv qbank
- git clone https://github.com/CLIxIndia-Dev/qbank-lite.git
- cd qbank-lite
- pip install -r requirements.txt
- pyinstaller main.spec
In a command prompt window:
- cd qbank-lite
- workon qbank
- git pull
- pip install -r requirements.txt
- pyinstaller main.spec
The final executable is now located in dist\main.exe
. You can rename this to match the qbank
version, i.e. move dist\main.exe qbank-lite-v3.14.9-32bit-ssl.exe
.
More detailed instructions are below.
In Git bash
or Command Prompt, clone the qbank
repository into a project directory:
git clone https://github.com/CLIxIndia-Dev/qbank-lite.git
Once you have the above software installed, you need to install the python dependencies (preferably into a virtual environment) using the command prompt or git bash:
In Git bash
or Command Prompt, create a virtual environment:
mkvirtualenv qbank
This will automatically create and then activate the virtual environment. Your prompt should show the name of the environment, like:
C:\Users\you> mkvirtualenv qbank-demo
New python executable in C:\Users\you\Envs\qbank-demo\Scripts\python.exe
Installing setuptools, pip, wheel...done.
(qbank-demo) C:\Users\you>
To learn more about virtual environments, you can read more here.
If you've already done the above steps and want to activate / use an existing virtual environment, at the command line you can type:
workon qbank-demo
Your prompt should change to reflect the active environment. Now you can continue building qbank
.
Once you have a virtual environment, you can run this to install / update the project dependencies. You should run this every time you pull from the repository with updated code:
pip install -r requirements.txt
There are many hidden imports in qbank
that need to be declared for pyinstaller
to include them. The best way to create the bundle is using the included spec
file.
pyinstaller main.spec
Once qbank
is bundled for unplatform
, it needs to get included in the unplatform
bundle. This is done by adding the qbank
executable to the qbank bundles repository.
- Clone / pull that repository.
- Add a directory with the
qbank
version. - Copy in the
qbank
executable to the new directory, renaming the file toqbank-lite-v#.#.#-32bit-ssl.exe
. - Commit and push those changes to
master
. - Checkout
release
branch. - Copy the
qbank
executable into therelease/
directory, renaming the file toqbank-lite-v#.#.#-32bit-ssl.exe
. - Remove the old
exe
file. - Commit and push those changes to
release
.
For example:
$ git pull
$ mkdir v3.14.4
$ cp ~/projects/qbank-lite/dist/main.exe v3.14.4/qbank-lite-v3.14.4-32bit-ssl.exe
$ git add .
$ git commit -m 'with qbank 3.14.4 bundle for windows'
$ git push
$ git checkout release
$ cp ~/projects/qbank-lite/dist/main.exe release/qbank-lite-v3.14.4-32bit-ssl.exe
$ git rm release/qbank-lite-v3.7.7-32bit-ssl.exe
$ git add .
$ git commit -m 'update released windows version'
$ git push