eSim Installer (Ubuntu OS)
====


It contains all the documenation for making eSim executable (using PyInstaller), eSim Installation Script and packaging eSim with and without eSim executable (through source) on Ubuntu 16.04 and above.


## eSim Executable:

> Note: pip tool corresponds to Python-3.5.2 on Ubuntu 16.04 and Python-3.6.9 on Ubuntu 18.04

1. Download `virtualenv` package and create virtual environment as:

	    $ pip install virtualenv
	    $ virtualenv -p /usr/bin/python3 eSim

			OR
		
	    $ sudo apt install -y python3-venv
	    $ python3 -m venv eSim

2. Activate the virtual environment as:
	
		$ source eSim/bin/activate

3. Install all Python dependencies for eSim within the virtual environment as:

		$ pip install wheel
		$ pip install pyinstaller
		$ pip install --upgrade 'matplotlib==3.0.3'
		$ pip install tornado
		$ pip install --upgrade 'setuptools<45.0.0'
		$ sudo apt install build-essential python3-dev libqt4-dev qt4-dev-tools
		$ mkdir eSim/build
		$ cd eSim/build/
		$ wget http://sourceforge.net/projects/pyqt/files/PyQt4/PyQt-4.12.3/PyQt4_gpl_x11-4.12.3.tar.gz
		$ wget https://www.riverbankcomputing.com/static/Downloads/sip/4.19.21/sip-4.19.21.tar.gz
		$ tar -xzvf sip-4.19.21.tar.gz
		$ tar -xvzf PyQt4_gpl_x11-4.12.3.tar.gz
		$ cd sip-4.19.21/
		$ python configure.py --sip-module PyQt4.sip
		$ make
		$ make install
		$ cd ../PyQt4_gpl_x11-4.12.3/
		$ python configure.py
		$ make
		$ make install

4. Test whether only eSim dependencies are available or not:

		$ pip freeze

> Note : Following dependencies should be available -
>	- PyQt4
>	- matplotlib
>	- numpy
>	- dateutil
>	- pyparsing
>	- six
>	- cycler.py

5. Download eSim Manual from eSim website, add it to `library/browser/User-Manual/` and update the file name of Manual in `src/browser/UserManual.py` accordingly.

6. Create spec file as:

		$ pyi-makespec --onefile -n eSim <path_to_eSim>/src/frontEnd/Application.py

7. Add `PyQt4.sip` as hiddenimports in the generated spec file.

8. Create onefile executable using pyinstaller as:
		
		$ pyinstaller -F --clean eSim.spec

9. Verify whether all eSim `src` files (`*.py`) have been included in `Analysis-00.toc` file under the build folder generated by PyInstaller.


## Fully-Static Bundling of eSim Executable:

1. To create a [fully-static bundled version](https://github.com/pyinstaller/pyinstaller/wiki/FAQ#GNULinux) of eSim (through PyInstaller), use a tool like [StaticX](https://github.com/JonathonReinhart/staticx/).

2. To create fully-static eSim :

	- Activate the virtual environment as:
	
			$ source eSim/bin/activate

	- Install StaticX as:

			$ pip install staticx
			$ pip install patchelf-wrapper

	- Create static eSim as:

			$ staticx /path/to/executable/eSim /path/to/output/executable/eSim

3. To verify if all dynamic libraries are removed :
	
	- Type following command in a terminal :

			$ ldd path/to/output/executable/eSim

	- Output of above command should be similar to `	not a dynamic executable`


## Without eSim Executable (through source):

Update following files by changing the relative paths before packaging the `src` folder with the release.

	- `browser\UserManual.py` 				--> 	path to manual
	- `browser\Welcome.py`					--> 	path to library
	- `configuration\Appconfig.py`			--> 	path to library
    - `frontEnd\Application.py`				--> 	path to library, pathmagic and images
    - `frontEnd\ProjectExplorer.py`			--> 	path to images
    - `frontEnd\Workspace.py`				--> 	path to images
    - `kicadtoNgspice\DeviceModel.py` 		--> 	path to library
    - `kicadtoNgspice\Processing.py` 		--> 	path to library
    - `kicadtoNgspice\SubcircuitTab.py` 	--> 	path to library
    - `modelEditor\ModelEditor.py`			--> 	path to library
    - `subcircuit\newSub.py`				--> 	path to library
    - `subcircuit\openSub.py`				--> 	path to library
    - `subcircuit\uploadSub.py`				--> 	path to library


## How to package eSim?

1. Update `VERSION` file to this release number.

2. Add the installer file in `eSim-<version>` folder.

3. Add the eSim executable file in `eSim-<version>` folder (only if it is made available). Also, remove following files from the folder:
	- `.git` folder
	- `code` folder
	- `src` folder (Applicable only if eSim executable is made)
	- conf.py
	- setup.py
	- index.rst
	- requirement.txt
	- .gitignore
	- .travis.yml

4. Add the zip file of `NGHDL` (`nghdl-master.zip`) in the eSim folder.

5. Compress `kicadLibrary` folder to a `tar.xz` format.

6. Compress `eSim-<version>` to a zip format for distribution.