Skip to content

Commit 17c0356

Browse files
committed
Add Python support on the configurator side
This completes the work started in 0fca9c6.
1 parent c8e86f9 commit 17c0356

File tree

14 files changed

+572
-26
lines changed

14 files changed

+572
-26
lines changed

app/jaunch/jy.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ jaunch-version = 1
1212

1313
program-name = 'Jy'
1414

15+
directives = ['JVM']
16+
1517
jvm.version-min = '8'
1618
#jvm.version-max = '21'
1719

app/jaunch/parsy.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ jaunch-version = 1
1212

1313
program-name = 'Parsy'
1414

15+
directives = ['JVM']
16+
1517
jvm.version-min = '8'
1618
#java-version-max = '21'
1719

app/jaunch/paunch.toml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# *** Welcome to the Paunch configuration file! ***
2+
#
3+
# Paunch is a Python launcher built on Jaunch (https://github.com/scijava/jaunch).
4+
#
5+
# One advantage of Paunch over the normal python launcher is that on macOS,
6+
# Paunch starts Python on a separate pthread, and starts the AppKit event loop
7+
# on the main thread, so that GUIs (especially Java-based AWT/Swing GUIs) can
8+
# successfully operate without hanging.
9+
#
10+
# There is a general layer of launcher configuration in the jaunch.toml file.
11+
# The contents below define Paunch's particular launcher behavior and features,
12+
# on top of Paunch's "sensible default" functionality.
13+
#
14+
# See that jaunch.toml file for more details about Jaunch configuration.
15+
16+
jaunch-version = 1
17+
18+
program-name = 'Paunch'
19+
20+
directives = ['PYTHON']
21+
22+
python.version-min = '3.8'

bin/app.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ do (
1111
srcDir=${l%/launcher*}
1212
suffix=${l#*/launcher}
1313
set -x
14+
cp "$l" "$srcDir/paunch$suffix"
1415
cp "$l" "$srcDir/jy$suffix"
1516
mv "$l" "$srcDir/parsy$suffix"
1617
) done

configs/fiji.toml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,16 @@ modes = [
8282
]
8383

8484
directives = [
85-
'--print-ij-dir|print-app-dir', # For backwards compatibility.
85+
'--print-ij-dir|print-app-dir,STOP', # For backwards compatibility.
86+
'JVM',
8687
]
8788

89+
# /============================================================================\
90+
# | PYTHON CONFIG |
91+
# \============================================================================/
92+
93+
# TODO
94+
8895
# /============================================================================\
8996
# | JAVA CONFIG |
9097
# \============================================================================/

configs/icy.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ jaunch-version = 1
1212

1313
program-name = 'Icy'
1414

15+
directives = ['JVM']
16+
1517
jvm.version-min = '8'
1618

1719
jvm.classpath = [

configs/imagej.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ jaunch-version = 1
1212

1313
program-name = 'ImageJ'
1414

15+
directives = ['JVM']
16+
1517
jvm.root-paths = [
1618
'${app-dir}',
1719
]

configs/qupath.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ jaunch-version = 1
1212

1313
program-name = 'QuPath'
1414

15+
directives = ['JVM']
16+
1517
jvm.version-min = '21'
1618

1719
jvm.classpath = [

jaunch.toml

Lines changed: 176 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# ==============================================================================
44
#
55
# This jaunch.toml file contains useful general-purpose, non-application-specific
6-
# configuration that defines some sensible defaults for typical Java-based launchers.
6+
# configuration that defines some sensible defaults for typical launchers.
77
# You can of course edit it to customize Jaunch's behavior however you like.
88
#
99
# Each application will typically have its own extensions to the general configuration
@@ -12,11 +12,9 @@
1212
# FizzBuzz application, you would also write a fizzbuzz.toml companion file that
1313
# overrides or augments this configuration with fizzbuzz-specific settings.
1414
#
15-
# Minimally, such application-specific configuration will include the `program-name`
16-
# and `main-class` fields, and typically a `classpath`
17-
# for needed JAR files. But it may also add application-specific options via the
18-
# `supported-options` field, as well as constraints such as `version-min` and
19-
# `version-max` to restrict which Javas are compatible with the application.
15+
# For simple examples of application-specific configuration, see:
16+
# - app/config/paunch.toml for a Jaunch-based Python launcher
17+
# - app/config/jy.toml for a Jaunch-based Jython launcher
2018
#
2119
# Alternately, if you would like to keep all configuration together in one file
2220
# for simplicity, you can write a single TOML file with everything, and name it
@@ -30,12 +28,14 @@
3028
jaunch-version = 1
3129

3230
# ==============================================================================
33-
# The name of your program! This name will appear in the usage text.
31+
# The name of your program! This name will appear in usage text and dialog boxes.
3432
#program-name = 'FizzBuzz'
3533

3634
# ==============================================================================
3735
# The list of command line options supported by Jaunch out of the box.
3836
#
37+
# TODO: Update this section to be unspecific to JVM programs.
38+
#
3939
# These are arguments that Jaunch will interpret, transforming them in various ways
4040
# into arguments to the Java Virtual Machine (JVM) and/or main class that is launched.
4141
#
@@ -91,6 +91,9 @@ supported-options = [
9191
'--java-home=<path>|specify JAVA_HOME explicitly',
9292
'--print-java-home|print path to the selected Java',
9393
'--print-java-info|print information about the selected Java',
94+
'--python-home=<path>|specify PYTHON_HOME explicitly',
95+
'--print-python-home|print path to the selected Python',
96+
'--print-python-info|print information about the selected Python',
9497
'--print-app-dir|print directory where the application is located',
9598
'--headless|run in text mode',
9699
"--heap,--mem,--memory=<amount>|set Java's heap size to <amount> (e.g. 512M)",
@@ -122,6 +125,8 @@ arch-aliases = [
122125
# ==============================================================================
123126
# List of additional hints to enable or disable based on other hints.
124127
#
128+
# TODO: Rework this section to introduce hints, rather than referring to below.
129+
#
125130
# See "jvm.root-paths" below for an overview of hints.
126131
#
127132
# With modes, you can set a single hint in response to several different other hints,
@@ -151,6 +156,8 @@ modes = []
151156
# ==============================================================================
152157
# Commands that control Jaunch's launching behavior.
153158
#
159+
# TODO: Rewrite this section to be nicer and more up to date.
160+
#
154161
# Each one runs at a particular (hardcoded) time during configuration.
155162
# Directives unsupported by the configurator program are ignored.
156163
#
@@ -171,6 +178,12 @@ modes = []
171178
# * print-app-dir - Print out the path to the application. Typically, this will be
172179
# the folder containing the launcher.
173180

181+
# * PYTHON - Launches the program using the Python interpreter.
182+
# * print-python-home - Print out the path to the chosen Python installation.
183+
# * print-python-info - Print out all the details of the chosen Python installation,
184+
# including not only its path, but also the distro, version,
185+
# operating system, CPU architecture, and other metadata fields.
186+
174187
# * JVM - Launches the program using the Java Virtual Machine.
175188
# * print-java-home - Print out the path to the chosen Java installation.
176189
# * print-java-info - Print out all the details of the chosen Java installation,
@@ -190,11 +203,12 @@ directives = [
190203
'-h|help,STOP', # global
191204
'--print-app-dir|print-app-dir', # global
192205
'--print-config-dir|print-config-dir', # global
193-
'--dry-run|dry-run,STOP', # jvm
206+
'--dry-run|dry-run,STOP', # python, jvm
207+
'--print-python-home|print-python-home', # python
208+
'--print-python-info|print-python-info', # python
194209
'--print-classpath|print-classpath', # jvm
195210
'--print-java-home|print-java-home', # jvm
196211
'--print-java-info|print-java-info', # jvm
197-
'JVM',
198212
]
199213

200214
# ==============================================================================
@@ -232,8 +246,161 @@ directives = [
232246
# supported options. In such cases, this option is here for you.
233247
allow-unrecognized-args = false
234248

249+
# ==============================================================================
250+
# Here begins the fields for controlling the launch of Python-based programs.
251+
# For JVM-specific fields, skip to the `jvm` section below.
252+
# ==============================================================================
253+
254+
python.recognized-args = [
255+
'-b', '-bb',
256+
'-B',
257+
'-c cmd',
258+
'-d',
259+
'-E',
260+
'-h', '-?', # --help is reserved for Jaunch
261+
'-i',
262+
'-I',
263+
'-m mod',
264+
'-O',
265+
'-OO',
266+
'-q',
267+
'-s',
268+
'-S',
269+
'-u',
270+
'-v',
271+
'-V', # --version is reserved for Jaunch
272+
'-W arg',
273+
'-x',
274+
'-X opt',
275+
'--check-hash-based-pycs always|default|never',
276+
]
277+
278+
# ==============================================================================
279+
# Paths to check for Python installations.
280+
#
281+
# This is a list of directories where Jaunch might hope to find a Python installation.
282+
# Directories are checked sequentially until one is found that matches all criteria.
283+
#
284+
# This is also the first field where we see Jaunch's hints/rules system in action.
285+
# Each entry on the root-dirs list may be prefixed with string separated by pipes.
286+
# Each segment is a *hint* for Jaunch regarding a flag that must be set for that
287+
# particular line to be considered. Jaunch sets hint flags based on a few sources:
288+
#
289+
# * Active operating system: OS:LINUX, OS:MACOSX, OS:WINDOWS,
290+
# OS:IOS, OS:ANDROID, OS:WASM, OS:TVOS, OS:WATCHOS, or OS:UNKNOWN.
291+
#
292+
# * Active CPU architecture: ARCH:ARM32, ARCH:ARM64, ARCH:X86, ARCH:X64,
293+
# ARCH:MIPS32, ARCH:MIPSEL32, ARCH:WASM32, or ARCH:UNKNOWN.
294+
295+
# * Option hints, set from arguments passed to Jaunch, each of which sets a matching
296+
# hint. For example, passing the --headless option will set a hint '--headless'.
297+
#
298+
# * Mode hints, set from evaluation of the modes field (see below).
299+
#
300+
# * Python hints, based on the Python installation selected:
301+
# - PYTHON:3.9 if the selected Python installation is version 3.9.
302+
# - PYTHON:3.9+ if the selected Python installation is version 3.9 or later.
303+
# - PYTHON:3.10 if the selected Python installation is version 3.10.
304+
# - PYTHON:3.10+ if the selected Python installation is version 3.10 or later.
305+
# - and so on.
306+
# Of course, Python hints will only be set after a Python installation matches,
307+
# so they won't work here in python.root-paths, nor in python.lib-suffixes.
308+
# But they can be useful in the python.runtime-args section to ensure Jaunch
309+
# passes runtime args only to those versions of Python that support them,
310+
# such as the -P flag which was introduced in Python 3.11.
311+
#
312+
# Finally, a segment prefixed by a bang symbol (!) negates the hint,
313+
# making that line match only when that particular hint is *not* set.
314+
#
315+
# For example, consider the following python.root-paths line:
316+
#
317+
# '!--system|OS:LINUX|ARCH:X64|python/linux64',
318+
#
319+
# The applicable hints are !--system, OS:LINUX, and ARCH:X64, so the root path
320+
# of python/linux64 will only be considered on 64-bit Linux systems, and only
321+
# when the --system option was *not* given as part of the launcher invocation.
322+
#
323+
# This is also the first field where we see Jaunch's variables in use:
324+
#
325+
# '--python-home|${python-home}'
326+
#
327+
# Thanks to the above line, when the user passes '--python-home=/best', the
328+
# --python-home hint will be set, and the python-home variable will be set to /best.
329+
# So not only will the line match, but the root path to check will become /best.
330+
python.root-paths = [
331+
'--python-home|${python-home}',
332+
'${PYTHON_HOME}',
333+
'~/miniforge3/envs/*',
334+
'~/mambaforge/envs/*',
335+
'${app-dir}/python',
336+
'${app-dir}/lib/runtime',
337+
]
338+
339+
# TODO: Verify this list for all platforms.
340+
python.lib-suffixes = [
341+
'OS:LINUX|lib/libpython3.so',
342+
'OS:MACOSX|lib/libpython3.dylib',
343+
'OS:WINDOWS|lib\libpython3.dll',
344+
]
345+
346+
# ==============================================================================
347+
# Acceptable range of Python versions to match.
348+
#
349+
# These two fields let you constrain the minimum and maximum Python versions
350+
# respectively that your application supports. This information will be used when
351+
# searching the system for appropriate Python installations. If a Python installation
352+
# is successfully discovered, but then found to be outside these constraints, it is
353+
# discarded and the search continues.
354+
#
355+
# The most common use of these fields is to specify a major.minor version pair
356+
# (e.g. `python.version-min = '3.9'`), but Jaunch does compare version strings digit by
357+
# digit, so you could write `python.version-min = '3.8.5' if you need to be specific.
358+
python.version-min = '3.8'
359+
#python.version-max = '3.12'
360+
361+
# ==============================================================================
362+
# Packages that must be present in the Python installation.
363+
#
364+
# TODO
365+
python.packages = []
366+
367+
# ==============================================================================
368+
# Arguments to pass to Python.
369+
#
370+
# This is the magic sauce where Jaunch options and other criteria get translated
371+
# into Python arguments. See 'python.root-paths' above for a thorough explanation.
372+
python.runtime-args = []
373+
374+
# ==============================================================================
375+
# A list of paths to candidate main scripts, one of which will get launched.
376+
#
377+
# Jaunch evaluates the rules attached to each candidate main script. The first
378+
# line with matching rules becomes the main script, with subsequent lines ignored.
379+
#
380+
# This field is useful if you want to launch a different main script depending on
381+
# criteria such as OS, CPU architecture, or which options are given on the CLI.
382+
#python.main-script = [
383+
# '--fizzbuzz|fizzbuzz.py'
384+
# '--main-script|${main-script}',
385+
# 'main.py', # default behavior
386+
#]
387+
388+
# ==============================================================================
389+
# Arguments to pass to the main class on the Python side.
390+
#
391+
# This is the other half of the magic sauce, along with python.runtime-args above:
392+
# Options and other criteria get translated into main arguments here.
393+
# See the 'python.root-paths' section above for a thorough explanation.
394+
#python.main-args = [
395+
# '!--fizz|!--buzz|--mode=number',
396+
# '--fizz|!--buzz|--mode=fizz',
397+
# '--buzz|!--fizz|--mode=buzz',
398+
# '--fizz|--buzz|--mode=fizzbuzz',
399+
#]
400+
235401
# ==============================================================================
236402
# Now come the fields for controlling the launch of JVM-based programs.
403+
# For Python-specific fields, jump back up to the `python` section above.
237404
# ==============================================================================
238405

239406
# ==============================================================================

0 commit comments

Comments
 (0)