Skip to content

allenyllee/DataTag_helper

Repository files navigation

DataTag Helper

Open in Visual Studio Code


Read Latest Documentation - Browse GitHub Code Repository


Screenshot-of-DataTag_helper

How to Build

Method 1: Use Remote Container

Step 1: Clone into container

If you have installed VSCode and Docker, just click Open in Visual Studio Code and choose "Clone repo in container volume", it'll open a new container with building environments.

Step 2: Build

Building linux executable:

pyinstaller -F --windowed build-win.spec

Building Windows executable:

wine pyinstaller -F --windowed build-win.spec

Step 3: Generate API docs

Hosing in local

portray server

Push to github pages

portray on_github_pages

We use portary to generate docs, and you can add Pymdown Extensions to extend Markdown format. For example, you can add "pymdownx.arithmatex" into extra_markdown_extensions list which under the section [tool.portray] of pyproject.toml to have the ability to parse LaTeX math equations.

Step 4: test pre-commit hook before commit

test for a file:

pre-commit run --files ./DataTag_helper.py

test for all files:

pre-commit run --all-files

If you want to commit without pre-commit checks, just run

git commit -m "some messages" --no-verify

Method 2: Manually Setup Environments

Step 1: Install Anaconda

https://www.anaconda.com/products/individual

Step 2: Install dependencies

Navigating to the directory of this repo.

cd /workspace/DataTag_helper

Create conda env

conda create --name DataTag_helper python=3.6

conda activate DataTag_helper

If conda install has permission error, excute:

sudo chown 1000:1000 -R /opt/conda/

This will change the owner of conda folder.

If conda activation failed, just execute:

conda init bash

to init bash env

Install packages

conda install wxpython
conda install -c conda-forge gooey

pip install -r project_requirements.txt
pip install -r requirements.txt

must first install wxpython before Gooey to avoid strange error

Installation via pip fails needing pathlib2 · Issue #474 · chriskiehl/Gooey

Step 3: Execute

python DataTag_helper.py

you should see the GUI window popup.

Step 4: Install pyinstaller

Gooey/Packaging-Gooey.md at master · chriskiehl/Gooey

Packing Gooey into a standalone executable is super straight forward thanks to PyInstaller. It is the only dependency you'll need and can be installed via the following.

pip install pyinstaller==3.5

Step 5: Building linux excutable with .spec file

From the command line, run

pyinstaller -F --windowed build-win.spec
  • -F tells PyInstaller to create a single bundled output file
  • --windowed disables the terminal which would otherwise launch when you opened your app.

And that's it. Inside of the dist/ directory, you'll find a beautiful stand-alone executable that you can distribute to your users.

If you encounter an error:

FileNotFoundError: [Errno 2] No such file or directory: 'objcopy': 'objcopy'

you should install dependenies

sudo apt update
sudo apt install -y binutils libc6

see: FileNotFoundError: [Errno 2] No such file or directory: 'objcopy': 'objcopy' · Issue #3815 · pyinstaller/pyinstaller

Step 6: Install wine

  1. add wine apt repository

    For Ubuntu - WineHQ Wiki:

    sudo dpkg --add-architecture i386
    
    wget -O - https://dl.winehq.org/wine-builds/winehq.key | sudo apt-key add -
    
    sudo add-apt-repository 'deb https://dl.winehq.org/wine-builds/ubuntu/ bionic main'

    Install unmet dependence: faudio (only needed for unbuntu18.04, because higher version already has libfaudio0 in repository)

    sudo add-apt-repository ppa:cybermax-dexter/sdl2-backport
    sudo apt update

    For debian 10:

    sudo dpkg --add-architecture i386
    
    wget -qO - https://dl.winehq.org/wine-builds/winehq.key | sudo apt-key add -
    
    sudo apt-add-repository https://dl.winehq.org/wine-builds/debian/
    
    wget -O- -q https://download.opensuse.org/repositories/Emulators:/Wine:/Debian/Debian_10/Release.key | sudo apt-key add -
    
    echo "deb http://download.opensuse.org/repositories/Emulators:/Wine:/Debian/Debian_10 ./" | sudo tee /etc/apt/sources.list.d/wine-obs.list
    

    update:

    sudo apt update
    

    Notes:

    check linux distribution:

    cat /etc/*-release
    

    see: https://www.cyberciti.biz/faq/find-linux-distribution-name-version-number/

    If you encounter an error:

    sudo: apt-add-repository: command not found
    

    install

    sudo apt -y install software-properties-common
    
  2. Install latest wine

    How to Install Wine Devel 4.8 in Ubuntu 19.04 / 18.04 | UbuntuHandbook

    sudo apt install --install-recommends winehq-devel
  3. install python in wine

    python - compiling .py into windows AND mac executables on Ubuntu - Stack Overflow

    wine --version
    winecfg
    
    wget https://www.python.org/ftp/python/3.6.8/python-3.6.8-amd64.exe
    wine python-3.6.8-amd64.exe

    headless install:

    install xvfb:

    sudo apt-get install --fix-missing -y xvfb
    

    cerate virtual frame buffer:

    Xvfb :0 -screen 0 1024x768x16 &
    

    execute python installer:

    DISPLAY=:0.0 wine python-3.6.8-amd64.exe /quiet InstallAllUsers=1 PrependPath=1
    

    see: xorg - Run wine totally headless - Super User

  4. install wxpython, gooey, pyinstaller and other requirements

    wine pip install wxpython
    wine pip install gooey
    wine pip install -r project_requirements.txt
    wine pip install pyinstaller==3.5
  5. activate upx compression (optional):

    Releases · upx/upx

    wget https://github.com/upx/upx/releases/download/v3.96/upx-3.96-win64.zip
    unzip -j "upx-3.96-win64.zip" "upx-3.96-win64/upx.exe" -d "./"

    note: upx may cause dll corruption, you may want to disable UPX, see:

Step 7: Building Windows Executable from Linux

wine pyinstaller -F --windowed build-win.spec

debug mode

Using PyInstaller — PyInstaller 3.6 documentation

wine pyinstaller -F --windowed build-win.spec -d bootloader

Step 8: Running Windows Executable through wine

wine ./dist/DataTag_helper.exe

Run test

Run test

pytest

Run test with print messages

pytest -s

Run single test function

pytest -s tests/test_DataTag_helper.py::test_json_to_excel_1

How to test with cli? see: Build and Test a Command Line Interface with Poetry, Python's argparse, and pytest - DEV Community 👩‍💻👨‍💻

References

Gooey

Gooey Options

examples

mutually_exclusive_group

widget example

FileChooser, DirChooser, FileSaver, MultiFileChooser, DateChooser, TimeChooser

dynamic update