Build embeddable python env with App #3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build embeddable python env with App | |
| on: | |
| #push: | |
| # branches: | |
| # - main | |
| # - development | |
| pull_request: | |
| branches: [ "main" ] | |
| workflow_dispatch: | |
| env: | |
| PYTHON_VERSION: 3.10.0 | |
| jobs: | |
| build-executable: | |
| runs-on: windows-2022 | |
| env: | |
| PYTHON_VERSION: 3.10.0 | |
| APP_NAME: OpenMS-NuXLApp | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Set up Python (regular distribution) | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ env.PYTHON_VERSION }} # Use the same version as the embeddable version | |
| - name: Setup python embeddable version | |
| run: | | |
| # Create a directory for the embeddable Python version | |
| mkdir python-${{ env.PYTHON_VERSION }} | |
| # Download and unzip the embeddable Python version | |
| curl -O https://www.python.org/ftp/python/${{ env.PYTHON_VERSION }}/python-${{ env.PYTHON_VERSION }}-embed-amd64.zip | |
| unzip python-${{ env.PYTHON_VERSION }}-embed-amd64.zip -d python-${{ env.PYTHON_VERSION }} | |
| rm python-${{ env.PYTHON_VERSION }}-embed-amd64.zip | |
| # Define paths for the regular Python distribution and the embeddable distribution | |
| $PYTHON_DIR="${{ runner.tool_cache }}/Python/${{ env.PYTHON_VERSION }}/x64" # Path from actions/setup-python | |
| $EMBED_DIR="python-${{ env.PYTHON_VERSION }}" | |
| mkdir -p $EMBED_DIR/Lib/site-packages/tkinter | |
| mkdir -p $EMBED_DIR/tcl | |
| # Copy necessary Tkinter files from the regular Python distribution | |
| cp -r $PYTHON_DIR/Lib/tkinter/* $EMBED_DIR/Lib/site-packages/tkinter/ | |
| cp -r $PYTHON_DIR/tcl/* $EMBED_DIR/tcl/ | |
| cp $PYTHON_DIR/DLLs/_tkinter.pyd $EMBED_DIR/ | |
| cp $PYTHON_DIR/DLLs/tcl86t.dll $EMBED_DIR/ | |
| cp $PYTHON_DIR/DLLs/tk86t.dll $EMBED_DIR/ | |
| - name: Bundle MSVC runtime DLLs | |
| shell: powershell | |
| run: | | |
| $embed = "python-${{ env.PYTHON_VERSION }}" | |
| $dlls = @( | |
| "vcomp140.dll", | |
| "vcruntime140.dll", | |
| "vcruntime140_1.dll", | |
| "msvcp140.dll" | |
| ) | |
| foreach ($dll in $dlls) { | |
| Copy-Item "C:\Windows\System32\$dll" "$embed\$dll" -Force | |
| } | |
| - name: Install pip | |
| run: | | |
| curl -O https://bootstrap.pypa.io/get-pip.py | |
| ./python-${{ env.PYTHON_VERSION }}/python get-pip.py --no-warn-script-location | |
| rm get-pip.py | |
| - name: Uncomment 'import site' in python310._pth file | |
| run: | | |
| sed -i 's/#import site/import site/' python-${{ env.PYTHON_VERSION }}/python310._pth | |
| - name: Install Required Packages | |
| run: .\python-${{ env.PYTHON_VERSION }}\python -m pip install --force-reinstall -r requirements_embd_py310_win.txt --no-warn-script-location | |
| - name: Set to offline deployment | |
| run: | | |
| $content = Get-Content -Raw settings.json | ConvertFrom-Json | |
| $content.online_deployment = $false | |
| $content | ConvertTo-Json -Depth 100 | Set-Content settings.json | |
| - name: Create .bat file | |
| run: | | |
| echo " start /min .\python-${{ env.PYTHON_VERSION }}\python -m streamlit run app.py local" > ${{ env.APP_NAME }}.bat | |
| - name: Create All-in-one executable folder | |
| run: | | |
| if (Test-Path -Path "streamlit_exe") { | |
| Remove-Item -Recurse -Force "streamlit_exe" | |
| } | |
| mkdir streamlit_exe | |
| mv python-${{ env.PYTHON_VERSION }} streamlit_exe | |
| cp -r src streamlit_exe | |
| cp -r content streamlit_exe | |
| cp -r assets streamlit_exe | |
| cp -r example-data streamlit_exe | |
| cp -r .streamlit streamlit_exe | |
| cp app.py streamlit_exe | |
| cp settings.json streamlit_exe | |
| cp ${{ env.APP_NAME }}.bat streamlit_exe | |
| - name: Generate Readme.txt | |
| shell: bash | |
| run: | | |
| cat <<EOF > streamlit_exe/Readme.txt | |
| Welcome to ${{ env.APP_NAME }} app! | |
| To launch the application: | |
| 1. Navigate to the installation directory. | |
| 2. Double-click on the file: ${{ env.APP_NAME }}.bat or ${{ env.APP_NAME }} shortcut. | |
| Additional Information: | |
| - If multiple Streamlit apps are running, you can change the port in the .streamlit/config.toml file. | |
| Example: | |
| [server] | |
| port = 8502 | |
| Reach out to us: | |
| - Join our Discord server for support and community discussions: https://discord.com/invite/4TAGhqJ7s5 | |
| - Contribute or stay updated with the latest OpenMS web app developments on GitHub: https://github.com/OpenMS/streamlit-template | |
| - Checkout the ${{ env.APP_NAME }} on Github: https://github.com/Arslan-Siraj/nuxl-app | |
| - Visit our website for more information: https://openms.de/ | |
| Thanks for using ${{ env.APP_NAME }}! | |
| EOF | |
| - name: Archive build artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: OpenMS_NuXLApp_embedabble_python | |
| path: | | |
| streamlit_exe |