From a9e7fbc39416faa7cbfa94cfd3208849319684b7 Mon Sep 17 00:00:00 2001
From: atse <atse@m-labs.hk>
Date: Mon, 28 Oct 2024 17:52:00 +0800
Subject: [PATCH] pytec GUI: Set up packaging

Co-authored-by: Egor Savkin <es@m-labs.hk>
---
 flake.nix            | 29 ++++++++++++++++++++++++++++-
 pytec/MANIFEST.in    |  4 ++++
 pytec/pyproject.toml | 18 ++++++++++++++++++
 pytec/setup.py       |  6 ++++++
 4 files changed, 56 insertions(+), 1 deletion(-)
 create mode 100644 pytec/MANIFEST.in
 create mode 100644 pytec/pyproject.toml

diff --git a/flake.nix b/flake.nix
index 1964727..74a966f 100644
--- a/flake.nix
+++ b/flake.nix
@@ -72,13 +72,40 @@
           numpy
         ];
       };
+
+      thermostat_gui = pkgs.python3Packages.buildPythonPackage {
+        pname = "thermostat_gui";
+        version = "0.0.0";
+        format = "pyproject";
+        src = "${self}/pytec";
+
+        nativeBuildInputs = [ pkgs.qt6.wrapQtAppsHook ];
+        propagatedBuildInputs =
+          [ pkgs.qt6.qtbase ]
+          ++ (with pkgs.python3Packages; [
+            pyqtgraph
+            pyqt6
+            qasync
+            pglive
+          ]);
+
+        dontWrapQtApps = true;
+        postFixup = ''
+          wrapQtApp "$out/bin/tec_qt"
+        '';
+      };
     in
     {
       packages.x86_64-linux = {
-        inherit thermostat;
+        inherit thermostat thermostat_gui;
         default = thermostat;
       };
 
+      apps.x86_64-linux.thermostat_gui = {
+        type = "app";
+        program = "${self.packages.x86_64-linux.thermostat_gui}/bin/tec_qt";
+      };
+
       hydraJobs = {
         inherit thermostat;
       };
diff --git a/pytec/MANIFEST.in b/pytec/MANIFEST.in
new file mode 100644
index 0000000..5be0b39
--- /dev/null
+++ b/pytec/MANIFEST.in
@@ -0,0 +1,4 @@
+graft examples
+include pytec/gui/resources/artiq.ico
+include pytec/gui/view/param_tree.json
+include pytec/gui/view/tec_qt.ui
diff --git a/pytec/pyproject.toml b/pytec/pyproject.toml
new file mode 100644
index 0000000..4af3992
--- /dev/null
+++ b/pytec/pyproject.toml
@@ -0,0 +1,18 @@
+[build-system]
+requires = ["setuptools"]
+build-backend = "setuptools.build_meta"
+
+[project]
+name = "pytec"
+version = "0.0"
+authors = [{name = "M-Labs"}]
+description = "Control TEC"
+urls.Repository = "https://git.m-labs.hk/M-Labs/thermostat"
+license = {text = "GPLv3"}
+
+[project.gui-scripts]
+tec_qt = "tec_qt:main"
+
+[tool.setuptools]
+packages.find = {}
+py-modules = ["autotune", "plot", "tec_qt"]
diff --git a/pytec/setup.py b/pytec/setup.py
index 3a46a57..7e3828f 100644
--- a/pytec/setup.py
+++ b/pytec/setup.py
@@ -9,4 +9,10 @@ setup(
     license="GPLv3",
     install_requires=["setuptools"],
     packages=find_packages(),
+    entry_points={
+        "gui_scripts": [
+            "tec_qt = tec_qt:main",
+        ]
+    },
+    py_modules=['autotune', 'plot', 'tec_qt'],
 )