Skip to content

Commit

Permalink
Add deb package creation logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
pdelboca committed Jan 17, 2025
1 parent a8c6b4b commit 09aa363
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ data/
__pycache__
build/
dist/
tmp/

# Astro
node_modules/
Expand Down
22 changes: 22 additions & 0 deletions build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import PyInstaller.__main__
import subprocess


def build_application():
"""Build an executable file for the Application."""

print("[server] Creating linux executable file for Open Data Editor")
PyInstaller.__main__.run([
'ode/main.py',
'--collect-all', 'frictionless', # Frictionless depends on data files
'--collect-all', 'ode', # Collect all assets from Open Data Editor
'--log-level', 'WARN',
'--name', 'opendataeditor',
'--noconfirm',
])
# Clean the spec file generated by PyInstaller
subprocess.run(['rm', 'opendataeditor.spec'])


if __name__ == "__main__":
build_application()
45 changes: 45 additions & 0 deletions create-deb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/sh
# Script to create a PyQT deb package using fpm
#
# This script will create a folder structure that will be used as input
# for the fpm command and copy into it all the distributable files generated by
# pyinstaller.
# We will create a folder with the same structure Linux systems expects:
# - /opt for our executable and associated files (a.k.a our dist/ folder)
# - /usr/share/applications (for the .desktop file)
# - /usr/share/icons/hicolor/scalable/apps for our svg icons (only svg in scalable folder)
#
# More info:
# - https://www.pythonguis.com/tutorials/packaging-pyqt5-applications-linux-pyinstaller/
# - https://fpm.readthedocs.io/en/latest/packages/dir.html#dir-local-files
#
# Create folders
[ -e package ] && rm -r tmp
mkdir -p tmp/opt
mkdir -p tmp/usr/share/applications
mkdir -p tmp/usr/share/icons/hicolor/scalable/apps

# Build the project
[ -e build ] && rm -r build
[ -e dist ] && rm -r dist
python build.py

# Copy files
cp -r dist/opendataeditor tmp/opt/opendataeditor
cp ./packaging/linux/icon.svg tmp/usr/share/icons/hicolor/scalable/apps/org.okfn.opendataeditor.svg
cp ./packaging/linux/opendataeditor.desktop tmp/usr/share/applications

# Change permissions
# Packages retain the permissions of installed files from when they were packaged,
# but will be installed by root. In order for ordinary users to be able to run the
# application, we need to change the permissions.
find tmp/opt/opendataeditor -type f -exec chmod 644 -- {} +
find tmp/opt/opendataeditor -type d -exec chmod 755 -- {} +
find tmp/usr/share -type f -exec chmod 644 -- {} +
chmod +x tmp/opt/opendataeditor/opendataeditor

# Create the deb package
VERSION=$(python -c "import ode; print(ode.__version__)")
FILENAME=opendataeditor-linux-$VERSION.deb
[ -e $FILENAME ] && rm $FILENAME
fpm -C tmp -s dir -t deb -n "opendataeditor" -v $VERSION -p dist/$FILENAME
1 change: 1 addition & 0 deletions ode/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# Required for PyInstaller to collect all assets
__version__ = "1.3.0"
3 changes: 3 additions & 0 deletions ode/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import collections
import sys
import shutil
import ode

from PySide6.QtWidgets import (
QApplication, QMainWindow, QWidget, QVBoxLayout, QHBoxLayout,
Expand Down Expand Up @@ -335,6 +336,8 @@ def open_report_issue(self):

if __name__ == "__main__":
app = QApplication(sys.argv)
app.setApplicationName("Open Data Editor")
app.setApplicationVersion(ode.__version__)
window = MainWindow()
window.show()
sys.exit(app.exec())
25 changes: 25 additions & 0 deletions packaging/linux/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions packaging/linux/opendataeditor.desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[Desktop Entry]

# The type of the thing this desktop file refers to
Type=Application

# The Application Name
Name=Open Data Editor

# Tooltip comment to show in menus
Comment=Data management for humans.

# The path (folder) in which the executable is run
Path=/opt/opendataeditor

# The executable (can include arguments)
Exec=/opt/opendataeditor/opendataeditor

# The icon we install for the application, use the target filesystem path
Icon=org.okfn.opendataeditor
File renamed without changes.

0 comments on commit 09aa363

Please sign in to comment.