From 1a9ece54b319bbc946dbc74f7504ce6d44d1cab1 Mon Sep 17 00:00:00 2001
From: "S. Co1" <sco1.git@gmail.com>
Date: Thu, 5 Sep 2024 13:07:33 -0400
Subject: [PATCH] Add tk installation option

---
 .github/workflows/main.yml | 6 ++++++
 README.md                  | 4 ++++
 action.yml                 | 8 ++++++--
 bin/install-python         | 8 ++++++++
 4 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 3ecefbc..bc2fbf4 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -12,6 +12,7 @@ jobs:
         - {python: '3.7', debug: true, nogil: false}
         - {python: '3.12-dev', debug: false, nogil: false}
         - {python: '3.13-dev', debug: false, nogil: true}
+        - {python: '3.13-dev', debug: false, nogil: false, tk: true}
     steps:
     - uses: actions/checkout@v4
     - uses: ./.
@@ -19,3 +20,8 @@ jobs:
         python-version: ${{ matrix.python }}
         debug: ${{ matrix.debug }}
         nogil: ${{ matrix.nogil }}
+        tk: ${{ matrix.tk }}
+
+    - name: check tk
+      if: matrix.tk
+      run: python -c 'import tkinter'
diff --git a/README.md b/README.md
index 14e4187..1afb254 100644
--- a/README.md
+++ b/README.md
@@ -52,5 +52,9 @@ The `nogil` input can be used instead of `debug` to install an *experimental*
 free-threaded build of the selected Python version, by adding `nogil: true`
 Only available for Python 3.13 and later.
 
+The action's `tk` input can be used to install Tkinter, which is not included
+by default. If `debug` is set then `tk-dbg` will be used. If `nogil` is set
+then `tk-nogil` will be used; only available for Python 3.13 and later.
+
 [available nightly versions]: https://launchpad.net/~deadsnakes/+archive/ubuntu/nightly/+packages
 [available versions]: https://launchpad.net/~deadsnakes/+archive/ubuntu/ppa/+packages
diff --git a/action.yml b/action.yml
index c186ebf..1c057e1 100644
--- a/action.yml
+++ b/action.yml
@@ -12,9 +12,13 @@ inputs:
     description: use free-threaded version of python
     required: false
     default: false
+  tk:
+    description: include Tkinter
+    required: false
+    default: false
 runs:
   using: composite
   steps:
-  - name: add deadsnakes ppa and install ${{ inputs.python-version }} ${{ inputs.debug == 'true' && '(debug)' || '' }}
-    run: ${{ github.action_path }}/bin/install-python ${{ inputs.python-version }} ${{ inputs.debug == 'true' && '--debug' || '' }} ${{ inputs.nogil == 'true' && '--nogil' || '' }}
+  - name: add deadsnakes ppa and install ${{ inputs.python-version }} ${{ inputs.debug == 'true' && '(debug)' || '' }} ${{ inputs.tk == 'true' && '(tk)' || '' }}
+    run: ${{ github.action_path }}/bin/install-python ${{ inputs.python-version }} ${{ inputs.debug == 'true' && '--debug' || '' }} ${{ inputs.nogil == 'true' && '--nogil' || '' }} ${{ inputs.tk == 'true' && '--tk' || '' }}
     shell: bash
diff --git a/bin/install-python b/bin/install-python
index 8d8b901..cd0a372 100755
--- a/bin/install-python
+++ b/bin/install-python
@@ -39,6 +39,7 @@ def main() -> int:
     mut = parser.add_mutually_exclusive_group()
     mut.add_argument('--debug', action='store_true')
     mut.add_argument('--nogil', action='store_true')
+    parser.add_argument('--tk', action='store_true')
     args = parser.parse_args()
 
     if args.version.endswith('-dev'):
@@ -62,6 +63,13 @@ def main() -> int:
         py_executable = f'{py}-nogil'
     else:
         py_executable = py
+    if args.tk:
+        if args.debug:
+            packages.append(f'{py}-tk-dbg')
+        elif args.nogil:
+            packages.append(f'{py}-tk-nogil')
+        else:
+            packages.append(f'{py}-tk')
 
     envdir = os.path.expanduser(f'~/venv-{version}')
     bindir = os.path.join(envdir, 'bin')