scyjava 1.9.0__tar.gz → 1.10.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- scyjava-1.10.0/MANIFEST.in +19 -0
- scyjava-1.10.0/Makefile +29 -0
- {scyjava-1.9.0/src/scyjava.egg-info → scyjava-1.10.0}/PKG-INFO +135 -41
- scyjava-1.9.0/PKG-INFO → scyjava-1.10.0/README.md +117 -71
- scyjava-1.10.0/UNLICENSE +24 -0
- scyjava-1.10.0/bin/check.sh +10 -0
- scyjava-1.10.0/bin/clean.sh +9 -0
- scyjava-1.10.0/bin/lint.sh +15 -0
- scyjava-1.10.0/bin/setup.sh +6 -0
- scyjava-1.10.0/bin/test.sh +102 -0
- scyjava-1.10.0/dev-environment.yml +46 -0
- scyjava-1.10.0/environment.yml +31 -0
- {scyjava-1.9.0 → scyjava-1.10.0}/pyproject.toml +13 -3
- scyjava-1.10.0/setup.cfg +4 -0
- {scyjava-1.9.0 → scyjava-1.10.0}/src/scyjava/__init__.py +26 -20
- {scyjava-1.9.0 → scyjava-1.10.0}/src/scyjava/_convert.py +114 -77
- scyjava-1.9.0/src/scyjava/_java.py → scyjava-1.10.0/src/scyjava/_jvm.py +93 -250
- {scyjava-1.9.0 → scyjava-1.10.0}/src/scyjava/_script.py +39 -36
- scyjava-1.10.0/src/scyjava/_types.py +335 -0
- {scyjava-1.9.0 → scyjava-1.10.0}/src/scyjava/_versions.py +4 -16
- {scyjava-1.9.0 → scyjava-1.10.0}/src/scyjava/config.py +69 -0
- scyjava-1.9.0/README.md → scyjava-1.10.0/src/scyjava.egg-info/PKG-INFO +165 -38
- {scyjava-1.9.0 → scyjava-1.10.0}/src/scyjava.egg-info/SOURCES.txt +19 -4
- {scyjava-1.9.0 → scyjava-1.10.0}/src/scyjava.egg-info/requires.txt +2 -0
- scyjava-1.10.0/tests/it/awt.py +29 -0
- scyjava-1.10.0/tests/it/headless.py +19 -0
- scyjava-1.10.0/tests/it/java_heap.py +34 -0
- scyjava-1.10.0/tests/it/jvm_version.py +22 -0
- scyjava-1.10.0/tests/it/scripting.py +59 -0
- {scyjava-1.9.0 → scyjava-1.10.0}/tests/test_basics.py +5 -5
- {scyjava-1.9.0 → scyjava-1.10.0}/tests/test_convert.py +10 -2
- {scyjava-1.9.0 → scyjava-1.10.0}/tests/test_pandas.py +7 -7
- scyjava-1.10.0/tests/test_types.py +32 -0
- scyjava-1.9.0/setup.cfg +0 -9
- scyjava-1.9.0/tests/test_jvm.py +0 -27
- {scyjava-1.9.0 → scyjava-1.10.0}/src/scyjava/_arrays.py +0 -0
- {scyjava-1.9.0 → scyjava-1.10.0}/src/scyjava.egg-info/dependency_links.txt +0 -0
- {scyjava-1.9.0 → scyjava-1.10.0}/src/scyjava.egg-info/top_level.txt +0 -0
- {scyjava-1.9.0 → scyjava-1.10.0}/tests/test_arrays.py +0 -0
- {scyjava-1.9.0 → scyjava-1.10.0}/tests/test_version.py +0 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Metadata
|
|
2
|
+
include MANIFEST.in
|
|
3
|
+
include Makefile
|
|
4
|
+
include README.md
|
|
5
|
+
include UNLICENSE
|
|
6
|
+
include pyproject.toml
|
|
7
|
+
|
|
8
|
+
# Conda Environment Files
|
|
9
|
+
include environment.yml
|
|
10
|
+
include dev-environment.yml
|
|
11
|
+
|
|
12
|
+
# Directory inclusion
|
|
13
|
+
graft src
|
|
14
|
+
graft tests
|
|
15
|
+
graft bin
|
|
16
|
+
|
|
17
|
+
# File exclusion
|
|
18
|
+
global-exclude __pycache__
|
|
19
|
+
global-exclude *.py[doc]
|
scyjava-1.10.0/Makefile
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
help:
|
|
2
|
+
@echo "Available targets:\n\
|
|
3
|
+
clean - remove build files and directories\n\
|
|
4
|
+
setup - create mamba developer environment\n\
|
|
5
|
+
lint - run code formatters and linters\n\
|
|
6
|
+
test - run automated test suite\n\
|
|
7
|
+
dist - generate release archives\n\
|
|
8
|
+
\n\
|
|
9
|
+
Remember to 'mamba activate scyjava-dev' first!"
|
|
10
|
+
|
|
11
|
+
clean:
|
|
12
|
+
bin/clean.sh
|
|
13
|
+
|
|
14
|
+
setup:
|
|
15
|
+
bin/setup.sh
|
|
16
|
+
|
|
17
|
+
check:
|
|
18
|
+
@bin/check.sh
|
|
19
|
+
|
|
20
|
+
lint: check
|
|
21
|
+
bin/lint.sh
|
|
22
|
+
|
|
23
|
+
test: check
|
|
24
|
+
bin/test.sh
|
|
25
|
+
|
|
26
|
+
dist: check clean
|
|
27
|
+
python -m build
|
|
28
|
+
|
|
29
|
+
.PHONY: test
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: scyjava
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.10.0
|
|
4
4
|
Summary: Supercharged Java access from Python
|
|
5
5
|
Author-email: SciJava developers <ctrueden@wisc.edu>
|
|
6
6
|
License: The Unlicense
|
|
@@ -15,7 +15,6 @@ Classifier: Intended Audience :: Developers
|
|
|
15
15
|
Classifier: Intended Audience :: Education
|
|
16
16
|
Classifier: Intended Audience :: Science/Research
|
|
17
17
|
Classifier: Programming Language :: Python :: 3 :: Only
|
|
18
|
-
Classifier: Programming Language :: Python :: 3.7
|
|
19
18
|
Classifier: Programming Language :: Python :: 3.8
|
|
20
19
|
Classifier: Programming Language :: Python :: 3.9
|
|
21
20
|
Classifier: Programming Language :: Python :: 3.10
|
|
@@ -27,9 +26,25 @@ Classifier: Topic :: Scientific/Engineering
|
|
|
27
26
|
Classifier: Topic :: Software Development :: Libraries :: Java Libraries
|
|
28
27
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
29
28
|
Classifier: Topic :: Utilities
|
|
30
|
-
Requires-Python: >=3.
|
|
29
|
+
Requires-Python: >=3.8
|
|
31
30
|
Description-Content-Type: text/markdown
|
|
31
|
+
Requires-Dist: jpype1>=1.3.0
|
|
32
|
+
Requires-Dist: jgo
|
|
32
33
|
Provides-Extra: dev
|
|
34
|
+
Requires-Dist: autopep8; extra == "dev"
|
|
35
|
+
Requires-Dist: black; extra == "dev"
|
|
36
|
+
Requires-Dist: build; extra == "dev"
|
|
37
|
+
Requires-Dist: flake8; extra == "dev"
|
|
38
|
+
Requires-Dist: flake8-pyproject; extra == "dev"
|
|
39
|
+
Requires-Dist: flake8-typing-imports; extra == "dev"
|
|
40
|
+
Requires-Dist: isort; extra == "dev"
|
|
41
|
+
Requires-Dist: jep; extra == "dev"
|
|
42
|
+
Requires-Dist: pytest; extra == "dev"
|
|
43
|
+
Requires-Dist: pytest-cov; extra == "dev"
|
|
44
|
+
Requires-Dist: numpy; extra == "dev"
|
|
45
|
+
Requires-Dist: pandas; extra == "dev"
|
|
46
|
+
Requires-Dist: toml; extra == "dev"
|
|
47
|
+
Requires-Dist: validate-pyproject[all]; extra == "dev"
|
|
33
48
|
|
|
34
49
|
[](https://github.com/scijava/scyjava/actions/workflows/build.yml)
|
|
35
50
|
[](https://codecov.io/gh/scijava/scyjava)
|
|
@@ -88,7 +103,7 @@ u'1.8.0_152-release'
|
|
|
88
103
|
|
|
89
104
|
```python
|
|
90
105
|
>>> from scyjava import config, jimport
|
|
91
|
-
>>> config.
|
|
106
|
+
>>> config.enable_headless_mode()
|
|
92
107
|
>>> config.add_repositories({'scijava.public': 'https://maven.scijava.org/content/groups/public'})
|
|
93
108
|
>>> config.endpoints.append('net.imagej:imagej:2.1.0')
|
|
94
109
|
>>> ImageJ = jimport('net.imagej.ImageJ')
|
|
@@ -191,6 +206,15 @@ FUNCTIONS
|
|
|
191
206
|
Add a converter to the list used by to_python.
|
|
192
207
|
:param converter: A Converter from java to python
|
|
193
208
|
|
|
209
|
+
available_processors() -> int
|
|
210
|
+
Get the number of processors available to the JVM.
|
|
211
|
+
|
|
212
|
+
This function is a shortcut for Java's
|
|
213
|
+
Runtime.getRuntime().availableProcessors().
|
|
214
|
+
|
|
215
|
+
:return: The number of available processors.
|
|
216
|
+
:raise RuntimeError: if the JVM has not yet been started.
|
|
217
|
+
|
|
194
218
|
enable_python_scripting(context)
|
|
195
219
|
Adds a Python script runner object to the ObjectService of the given
|
|
196
220
|
SciJava context. Intended for use in conjunction with
|
|
@@ -199,6 +223,13 @@ FUNCTIONS
|
|
|
199
223
|
:param context: The org.scijava.Context containing the ObjectService
|
|
200
224
|
where the PythonScriptRunner should be injected.
|
|
201
225
|
|
|
226
|
+
gc() -> None
|
|
227
|
+
Do a round of Java garbage collection.
|
|
228
|
+
|
|
229
|
+
This function is a shortcut for Java's System.gc().
|
|
230
|
+
|
|
231
|
+
:raise RuntimeError: If the JVM has not started yet.
|
|
232
|
+
|
|
202
233
|
get_version(java_class_or_python_package) -> str
|
|
203
234
|
Return the version of a Java class or Python package.
|
|
204
235
|
|
|
@@ -230,13 +261,13 @@ FUNCTIONS
|
|
|
230
261
|
those actions via the jpype.setupGuiEnvironment wrapper function;
|
|
231
262
|
see the Troubleshooting section of the scyjava README for details.
|
|
232
263
|
|
|
233
|
-
is_jarray(data) -> bool
|
|
264
|
+
is_jarray(data: Any) -> bool
|
|
234
265
|
Return whether the given data object is a Java array.
|
|
235
266
|
|
|
236
267
|
is_jvm_headless() -> bool
|
|
237
268
|
Return true iff Java is running in headless mode.
|
|
238
269
|
|
|
239
|
-
:
|
|
270
|
+
:raise RuntimeError: If the JVM has not started yet.
|
|
240
271
|
|
|
241
272
|
is_memoryarraylike(arr: Any) -> bool
|
|
242
273
|
Return True iff the object is memoryarraylike:
|
|
@@ -282,33 +313,43 @@ FUNCTIONS
|
|
|
282
313
|
:param lengths: List of lengths for the array. For example:
|
|
283
314
|
`jarray('z', [3, 7])` is the equivalent of `new boolean[3][7]` in Java.
|
|
284
315
|
You can pass a single integer to make a 1-dimensional array of that length.
|
|
285
|
-
:
|
|
316
|
+
:return: The newly allocated array
|
|
286
317
|
|
|
287
318
|
jclass(data)
|
|
288
319
|
Obtain a Java class object.
|
|
289
320
|
|
|
290
|
-
:param data: The object from which to glean the class.
|
|
291
321
|
Supported types include:
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
322
|
+
|
|
323
|
+
A. Name of a class to look up -- e.g. "java.lang.String" --
|
|
324
|
+
which returns the equivalent of Class.forName("java.lang.String").
|
|
325
|
+
|
|
326
|
+
B. A static-style class reference -- e.g. String --
|
|
327
|
+
which returns the equivalent of String.class.
|
|
328
|
+
|
|
329
|
+
C. A Java object -- e.g. foo --
|
|
330
|
+
which returns the equivalent of foo.getClass().
|
|
331
|
+
|
|
332
|
+
Note that if you pass a java.lang.Class object, you will get back Class.class,
|
|
333
|
+
i.e. the Java class for the Class class. :-)
|
|
334
|
+
|
|
335
|
+
:param data: The object from which to glean the class.
|
|
336
|
+
:return: A java.lang.Class object, suitable for use with reflection.
|
|
337
|
+
:raise TypeError: if the argument is not one of the aforementioned types.
|
|
298
338
|
|
|
299
339
|
jimport(class_name: str)
|
|
300
340
|
Import a class from Java to Python.
|
|
301
341
|
|
|
302
342
|
:param class_name: Name of the class to import.
|
|
303
|
-
:
|
|
304
|
-
|
|
343
|
+
:return:
|
|
344
|
+
A pointer to the class, which can be used to
|
|
345
|
+
e.g. instantiate objects of that class.
|
|
305
346
|
|
|
306
347
|
jinstance(obj, jtype) -> bool
|
|
307
348
|
Test if the given object is an instance of a particular Java type.
|
|
308
349
|
|
|
309
350
|
:param obj: The object to check.
|
|
310
351
|
:param jtype: The Java type, as either a jimported class or as a string.
|
|
311
|
-
:
|
|
352
|
+
:return: True iff the object is an instance of that Java type.
|
|
312
353
|
|
|
313
354
|
jstacktrace(exc) -> str
|
|
314
355
|
Extract the Java-side stack trace from a Java exception.
|
|
@@ -323,37 +364,82 @@ FUNCTIONS
|
|
|
323
364
|
print(jstacktrace(exc))
|
|
324
365
|
|
|
325
366
|
:param exc: The Java Throwable from which to extract the stack trace.
|
|
326
|
-
:
|
|
367
|
+
:return: A multi-line string containing the stack trace, or empty string
|
|
327
368
|
if no stack trace could be extracted.
|
|
328
369
|
|
|
329
370
|
jvm_started() -> bool
|
|
330
371
|
Return true iff a Java virtual machine (JVM) has been started.
|
|
331
372
|
|
|
332
373
|
jvm_version() -> str
|
|
333
|
-
Gets the version of the JVM as a tuple,
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
numbers and dots are ignored, in line
|
|
337
|
-
with the java.version system property.
|
|
374
|
+
Gets the version of the JVM as a tuple, with each dot-separated digit
|
|
375
|
+
as one element. Characters in the version string beyond only numbers
|
|
376
|
+
and dots are ignored, in line with the java.version system property.
|
|
338
377
|
|
|
339
378
|
Examples:
|
|
340
379
|
* OpenJDK 17.0.1 -> [17, 0, 1]
|
|
341
380
|
* OpenJDK 11.0.9.1-internal -> [11, 0, 9, 1]
|
|
342
381
|
* OpenJDK 1.8.0_312 -> [1, 8, 0]
|
|
343
382
|
|
|
344
|
-
If the JVM is already started,
|
|
345
|
-
this function should return the equivalent of:
|
|
383
|
+
If the JVM is already started, this function returns the equivalent of:
|
|
346
384
|
jimport('java.lang.System')
|
|
347
385
|
.getProperty('java.version')
|
|
348
386
|
.split('.')
|
|
349
387
|
|
|
350
|
-
In case the JVM is not started yet,a best effort is made to deduce
|
|
388
|
+
In case the JVM is not started yet, a best effort is made to deduce
|
|
351
389
|
the version from the environment without actually starting up the
|
|
352
390
|
JVM in-process. If the version cannot be deduced, a RuntimeError
|
|
353
391
|
with the cause is raised.
|
|
354
392
|
|
|
393
|
+
memory_max() -> int
|
|
394
|
+
Get the maximum amount of memory that the JVM will attempt to use.
|
|
395
|
+
|
|
396
|
+
This number will always be greater than or equal to memory_total().
|
|
397
|
+
|
|
398
|
+
In case the JVM was configured with -Xmx flag upon startup (e.g. using
|
|
399
|
+
the scyjava.config.set_heap_max function), the value will typically
|
|
400
|
+
correspond approximately, but not exactly, to the configured value.
|
|
401
|
+
|
|
402
|
+
This function is a shortcut for Java's Runtime.getRuntime().maxMemory().
|
|
403
|
+
|
|
404
|
+
:return: The maximum memory in bytes.
|
|
405
|
+
:raise RuntimeError: if the JVM has not yet been started.
|
|
406
|
+
|
|
407
|
+
memory_total() -> int
|
|
408
|
+
Get the total amount of memory currently reserved by the JVM.
|
|
409
|
+
|
|
410
|
+
This number will always be less than or equal to memory_max().
|
|
411
|
+
|
|
412
|
+
In case the JVM was configured with -Xms flag upon startup (e.g. using
|
|
413
|
+
the scyjava.config.set_heap_min function), the initial value will typically
|
|
414
|
+
correspond approximately, but not exactly, to the configured value,
|
|
415
|
+
although it is likely to grow over time as more Java objects are allocated.
|
|
416
|
+
|
|
417
|
+
This function is a shortcut for Java's Runtime.getRuntime().totalMemory().
|
|
418
|
+
|
|
419
|
+
:return: The total memory in bytes.
|
|
420
|
+
:raise RuntimeError: if the JVM has not yet been started.
|
|
421
|
+
|
|
422
|
+
memory_used() -> int
|
|
423
|
+
Get the amount of memory currently in use by the JVM.
|
|
424
|
+
|
|
425
|
+
This function is a shortcut for
|
|
426
|
+
Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory().
|
|
427
|
+
|
|
428
|
+
:return: The used memory in bytes.
|
|
429
|
+
:raise RuntimeError: if the JVM has not yet been started.
|
|
430
|
+
|
|
431
|
+
numeric_bounds(the_type: type) -> Union[Tuple[int, int], Tuple[float, float], Tuple[NoneType, NoneType]]
|
|
432
|
+
Get the minimum and maximum values for the given numeric type.
|
|
433
|
+
For example, a Java long returns (int(Long.MIN_VALUE), int(Long.MAX_VALUE)),
|
|
434
|
+
whereas a Java double returns (float(-Double.MAX_VALUE), float(Double.MAX_VALUE)).
|
|
435
|
+
|
|
436
|
+
:param the_type: The type whose minimum and maximum values are needed.
|
|
437
|
+
:return:
|
|
438
|
+
The minimum and maximum values as a two-element tuple of int or float,
|
|
439
|
+
or a two-element tuple of None if no known bounds.
|
|
440
|
+
|
|
355
441
|
shutdown_jvm() -> None
|
|
356
|
-
|
|
442
|
+
Shut down the JVM.
|
|
357
443
|
|
|
358
444
|
This function makes a best effort to clean up Java resources first.
|
|
359
445
|
In particular, shutdown hooks registered with scyjava.when_jvm_stops
|
|
@@ -371,6 +457,8 @@ FUNCTIONS
|
|
|
371
457
|
Note that if the JVM is not already running, then this function does
|
|
372
458
|
nothing! In particular, shutdown hooks are skipped in this situation.
|
|
373
459
|
|
|
460
|
+
:raise RuntimeError: if this method is called while in Jep mode.
|
|
461
|
+
|
|
374
462
|
start_jvm(options=None) -> None
|
|
375
463
|
Explicitly connect to the Java virtual machine (JVM). Only one JVM can
|
|
376
464
|
be active; does nothing if the JVM has already been started. Calling
|
|
@@ -378,8 +466,9 @@ FUNCTIONS
|
|
|
378
466
|
time a scyjava function needing a JVM is invoked, one is started on the
|
|
379
467
|
fly with the configuration specified via the scijava.config mechanism.
|
|
380
468
|
|
|
381
|
-
:param options:
|
|
382
|
-
|
|
469
|
+
:param options:
|
|
470
|
+
List of options to pass to the JVM.
|
|
471
|
+
For example: ['-Dfoo=bar', '-XX:+UnlockExperimentalVMOptions']
|
|
383
472
|
|
|
384
473
|
to_java(obj: Any, **hints: Dict) -> Any
|
|
385
474
|
Recursively convert a Python object to a Java object.
|
|
@@ -422,11 +511,13 @@ FUNCTIONS
|
|
|
422
511
|
* float values in Double range but outside float range convert to Double
|
|
423
512
|
* float values outside double range convert to BigDecimal
|
|
424
513
|
|
|
425
|
-
:param obj:
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
514
|
+
:param obj:
|
|
515
|
+
The Python object to convert.
|
|
516
|
+
:param hints:
|
|
517
|
+
An optional dictionary of hints, to help scyjava
|
|
518
|
+
make decisions about how to do the conversion.
|
|
519
|
+
:return: A corresponding Java object with the same contents.
|
|
520
|
+
:raise TypeError: if the argument is not one of the aforementioned types.
|
|
430
521
|
|
|
431
522
|
to_python(data: Any, gentle: bool = False) -> Any
|
|
432
523
|
Recursively convert a Java object to a Python object.
|
|
@@ -443,12 +534,15 @@ FUNCTIONS
|
|
|
443
534
|
* Iterable -> collections.abc.Iterable
|
|
444
535
|
* Iterator -> collections.abc.Iterator
|
|
445
536
|
|
|
446
|
-
:param data:
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
537
|
+
:param data:
|
|
538
|
+
The Java object to convert.
|
|
539
|
+
:param gentle:
|
|
540
|
+
If set, and the type cannot be converted, leaves
|
|
541
|
+
the data alone rather than raising a TypeError.
|
|
542
|
+
:return: A corresponding Python object with the same contents.
|
|
543
|
+
:raise TypeError:
|
|
544
|
+
if the argument is not one of the aforementioned types,
|
|
545
|
+
and the gentle flag is not set.
|
|
452
546
|
|
|
453
547
|
when_jvm_starts(f) -> None
|
|
454
548
|
Registers a function to be called when the JVM starts (or immediately).
|
|
@@ -477,7 +571,7 @@ unless you do one of two things:
|
|
|
477
571
|
|
|
478
572
|
```python
|
|
479
573
|
from scyjava import config, jimport
|
|
480
|
-
config.
|
|
574
|
+
config.enable_headless_mode()
|
|
481
575
|
```
|
|
482
576
|
|
|
483
577
|
In which case, you'll get `java.awt.HeadlessException` instead of a
|
|
@@ -1,36 +1,3 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: scyjava
|
|
3
|
-
Version: 1.9.0
|
|
4
|
-
Summary: Supercharged Java access from Python
|
|
5
|
-
Author-email: SciJava developers <ctrueden@wisc.edu>
|
|
6
|
-
License: The Unlicense
|
|
7
|
-
Project-URL: homepage, https://github.com/scijava/scyjava
|
|
8
|
-
Project-URL: documentation, https://github.com/scijava/scyjava/blob/main/README.md
|
|
9
|
-
Project-URL: source, https://github.com/scijava/scyjava
|
|
10
|
-
Project-URL: download, https://pypi.org/project/scyjava/
|
|
11
|
-
Project-URL: tracker, https://github.com/scijava/scyjava/issues
|
|
12
|
-
Keywords: java,maven,cross-language
|
|
13
|
-
Classifier: Development Status :: 5 - Production/Stable
|
|
14
|
-
Classifier: Intended Audience :: Developers
|
|
15
|
-
Classifier: Intended Audience :: Education
|
|
16
|
-
Classifier: Intended Audience :: Science/Research
|
|
17
|
-
Classifier: Programming Language :: Python :: 3 :: Only
|
|
18
|
-
Classifier: Programming Language :: Python :: 3.7
|
|
19
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
20
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
21
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
22
|
-
Classifier: License :: OSI Approved :: The Unlicense (Unlicense)
|
|
23
|
-
Classifier: Operating System :: Microsoft :: Windows
|
|
24
|
-
Classifier: Operating System :: Unix
|
|
25
|
-
Classifier: Operating System :: MacOS
|
|
26
|
-
Classifier: Topic :: Scientific/Engineering
|
|
27
|
-
Classifier: Topic :: Software Development :: Libraries :: Java Libraries
|
|
28
|
-
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
29
|
-
Classifier: Topic :: Utilities
|
|
30
|
-
Requires-Python: >=3.7
|
|
31
|
-
Description-Content-Type: text/markdown
|
|
32
|
-
Provides-Extra: dev
|
|
33
|
-
|
|
34
1
|
[](https://github.com/scijava/scyjava/actions/workflows/build.yml)
|
|
35
2
|
[](https://codecov.io/gh/scijava/scyjava)
|
|
36
3
|
|
|
@@ -88,7 +55,7 @@ u'1.8.0_152-release'
|
|
|
88
55
|
|
|
89
56
|
```python
|
|
90
57
|
>>> from scyjava import config, jimport
|
|
91
|
-
>>> config.
|
|
58
|
+
>>> config.enable_headless_mode()
|
|
92
59
|
>>> config.add_repositories({'scijava.public': 'https://maven.scijava.org/content/groups/public'})
|
|
93
60
|
>>> config.endpoints.append('net.imagej:imagej:2.1.0')
|
|
94
61
|
>>> ImageJ = jimport('net.imagej.ImageJ')
|
|
@@ -191,6 +158,15 @@ FUNCTIONS
|
|
|
191
158
|
Add a converter to the list used by to_python.
|
|
192
159
|
:param converter: A Converter from java to python
|
|
193
160
|
|
|
161
|
+
available_processors() -> int
|
|
162
|
+
Get the number of processors available to the JVM.
|
|
163
|
+
|
|
164
|
+
This function is a shortcut for Java's
|
|
165
|
+
Runtime.getRuntime().availableProcessors().
|
|
166
|
+
|
|
167
|
+
:return: The number of available processors.
|
|
168
|
+
:raise RuntimeError: if the JVM has not yet been started.
|
|
169
|
+
|
|
194
170
|
enable_python_scripting(context)
|
|
195
171
|
Adds a Python script runner object to the ObjectService of the given
|
|
196
172
|
SciJava context. Intended for use in conjunction with
|
|
@@ -199,6 +175,13 @@ FUNCTIONS
|
|
|
199
175
|
:param context: The org.scijava.Context containing the ObjectService
|
|
200
176
|
where the PythonScriptRunner should be injected.
|
|
201
177
|
|
|
178
|
+
gc() -> None
|
|
179
|
+
Do a round of Java garbage collection.
|
|
180
|
+
|
|
181
|
+
This function is a shortcut for Java's System.gc().
|
|
182
|
+
|
|
183
|
+
:raise RuntimeError: If the JVM has not started yet.
|
|
184
|
+
|
|
202
185
|
get_version(java_class_or_python_package) -> str
|
|
203
186
|
Return the version of a Java class or Python package.
|
|
204
187
|
|
|
@@ -230,13 +213,13 @@ FUNCTIONS
|
|
|
230
213
|
those actions via the jpype.setupGuiEnvironment wrapper function;
|
|
231
214
|
see the Troubleshooting section of the scyjava README for details.
|
|
232
215
|
|
|
233
|
-
is_jarray(data) -> bool
|
|
216
|
+
is_jarray(data: Any) -> bool
|
|
234
217
|
Return whether the given data object is a Java array.
|
|
235
218
|
|
|
236
219
|
is_jvm_headless() -> bool
|
|
237
220
|
Return true iff Java is running in headless mode.
|
|
238
221
|
|
|
239
|
-
:
|
|
222
|
+
:raise RuntimeError: If the JVM has not started yet.
|
|
240
223
|
|
|
241
224
|
is_memoryarraylike(arr: Any) -> bool
|
|
242
225
|
Return True iff the object is memoryarraylike:
|
|
@@ -282,33 +265,43 @@ FUNCTIONS
|
|
|
282
265
|
:param lengths: List of lengths for the array. For example:
|
|
283
266
|
`jarray('z', [3, 7])` is the equivalent of `new boolean[3][7]` in Java.
|
|
284
267
|
You can pass a single integer to make a 1-dimensional array of that length.
|
|
285
|
-
:
|
|
268
|
+
:return: The newly allocated array
|
|
286
269
|
|
|
287
270
|
jclass(data)
|
|
288
271
|
Obtain a Java class object.
|
|
289
272
|
|
|
290
|
-
:param data: The object from which to glean the class.
|
|
291
273
|
Supported types include:
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
274
|
+
|
|
275
|
+
A. Name of a class to look up -- e.g. "java.lang.String" --
|
|
276
|
+
which returns the equivalent of Class.forName("java.lang.String").
|
|
277
|
+
|
|
278
|
+
B. A static-style class reference -- e.g. String --
|
|
279
|
+
which returns the equivalent of String.class.
|
|
280
|
+
|
|
281
|
+
C. A Java object -- e.g. foo --
|
|
282
|
+
which returns the equivalent of foo.getClass().
|
|
283
|
+
|
|
284
|
+
Note that if you pass a java.lang.Class object, you will get back Class.class,
|
|
285
|
+
i.e. the Java class for the Class class. :-)
|
|
286
|
+
|
|
287
|
+
:param data: The object from which to glean the class.
|
|
288
|
+
:return: A java.lang.Class object, suitable for use with reflection.
|
|
289
|
+
:raise TypeError: if the argument is not one of the aforementioned types.
|
|
298
290
|
|
|
299
291
|
jimport(class_name: str)
|
|
300
292
|
Import a class from Java to Python.
|
|
301
293
|
|
|
302
294
|
:param class_name: Name of the class to import.
|
|
303
|
-
:
|
|
304
|
-
|
|
295
|
+
:return:
|
|
296
|
+
A pointer to the class, which can be used to
|
|
297
|
+
e.g. instantiate objects of that class.
|
|
305
298
|
|
|
306
299
|
jinstance(obj, jtype) -> bool
|
|
307
300
|
Test if the given object is an instance of a particular Java type.
|
|
308
301
|
|
|
309
302
|
:param obj: The object to check.
|
|
310
303
|
:param jtype: The Java type, as either a jimported class or as a string.
|
|
311
|
-
:
|
|
304
|
+
:return: True iff the object is an instance of that Java type.
|
|
312
305
|
|
|
313
306
|
jstacktrace(exc) -> str
|
|
314
307
|
Extract the Java-side stack trace from a Java exception.
|
|
@@ -323,37 +316,82 @@ FUNCTIONS
|
|
|
323
316
|
print(jstacktrace(exc))
|
|
324
317
|
|
|
325
318
|
:param exc: The Java Throwable from which to extract the stack trace.
|
|
326
|
-
:
|
|
319
|
+
:return: A multi-line string containing the stack trace, or empty string
|
|
327
320
|
if no stack trace could be extracted.
|
|
328
321
|
|
|
329
322
|
jvm_started() -> bool
|
|
330
323
|
Return true iff a Java virtual machine (JVM) has been started.
|
|
331
324
|
|
|
332
325
|
jvm_version() -> str
|
|
333
|
-
Gets the version of the JVM as a tuple,
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
numbers and dots are ignored, in line
|
|
337
|
-
with the java.version system property.
|
|
326
|
+
Gets the version of the JVM as a tuple, with each dot-separated digit
|
|
327
|
+
as one element. Characters in the version string beyond only numbers
|
|
328
|
+
and dots are ignored, in line with the java.version system property.
|
|
338
329
|
|
|
339
330
|
Examples:
|
|
340
331
|
* OpenJDK 17.0.1 -> [17, 0, 1]
|
|
341
332
|
* OpenJDK 11.0.9.1-internal -> [11, 0, 9, 1]
|
|
342
333
|
* OpenJDK 1.8.0_312 -> [1, 8, 0]
|
|
343
334
|
|
|
344
|
-
If the JVM is already started,
|
|
345
|
-
this function should return the equivalent of:
|
|
335
|
+
If the JVM is already started, this function returns the equivalent of:
|
|
346
336
|
jimport('java.lang.System')
|
|
347
337
|
.getProperty('java.version')
|
|
348
338
|
.split('.')
|
|
349
339
|
|
|
350
|
-
In case the JVM is not started yet,a best effort is made to deduce
|
|
340
|
+
In case the JVM is not started yet, a best effort is made to deduce
|
|
351
341
|
the version from the environment without actually starting up the
|
|
352
342
|
JVM in-process. If the version cannot be deduced, a RuntimeError
|
|
353
343
|
with the cause is raised.
|
|
354
344
|
|
|
345
|
+
memory_max() -> int
|
|
346
|
+
Get the maximum amount of memory that the JVM will attempt to use.
|
|
347
|
+
|
|
348
|
+
This number will always be greater than or equal to memory_total().
|
|
349
|
+
|
|
350
|
+
In case the JVM was configured with -Xmx flag upon startup (e.g. using
|
|
351
|
+
the scyjava.config.set_heap_max function), the value will typically
|
|
352
|
+
correspond approximately, but not exactly, to the configured value.
|
|
353
|
+
|
|
354
|
+
This function is a shortcut for Java's Runtime.getRuntime().maxMemory().
|
|
355
|
+
|
|
356
|
+
:return: The maximum memory in bytes.
|
|
357
|
+
:raise RuntimeError: if the JVM has not yet been started.
|
|
358
|
+
|
|
359
|
+
memory_total() -> int
|
|
360
|
+
Get the total amount of memory currently reserved by the JVM.
|
|
361
|
+
|
|
362
|
+
This number will always be less than or equal to memory_max().
|
|
363
|
+
|
|
364
|
+
In case the JVM was configured with -Xms flag upon startup (e.g. using
|
|
365
|
+
the scyjava.config.set_heap_min function), the initial value will typically
|
|
366
|
+
correspond approximately, but not exactly, to the configured value,
|
|
367
|
+
although it is likely to grow over time as more Java objects are allocated.
|
|
368
|
+
|
|
369
|
+
This function is a shortcut for Java's Runtime.getRuntime().totalMemory().
|
|
370
|
+
|
|
371
|
+
:return: The total memory in bytes.
|
|
372
|
+
:raise RuntimeError: if the JVM has not yet been started.
|
|
373
|
+
|
|
374
|
+
memory_used() -> int
|
|
375
|
+
Get the amount of memory currently in use by the JVM.
|
|
376
|
+
|
|
377
|
+
This function is a shortcut for
|
|
378
|
+
Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory().
|
|
379
|
+
|
|
380
|
+
:return: The used memory in bytes.
|
|
381
|
+
:raise RuntimeError: if the JVM has not yet been started.
|
|
382
|
+
|
|
383
|
+
numeric_bounds(the_type: type) -> Union[Tuple[int, int], Tuple[float, float], Tuple[NoneType, NoneType]]
|
|
384
|
+
Get the minimum and maximum values for the given numeric type.
|
|
385
|
+
For example, a Java long returns (int(Long.MIN_VALUE), int(Long.MAX_VALUE)),
|
|
386
|
+
whereas a Java double returns (float(-Double.MAX_VALUE), float(Double.MAX_VALUE)).
|
|
387
|
+
|
|
388
|
+
:param the_type: The type whose minimum and maximum values are needed.
|
|
389
|
+
:return:
|
|
390
|
+
The minimum and maximum values as a two-element tuple of int or float,
|
|
391
|
+
or a two-element tuple of None if no known bounds.
|
|
392
|
+
|
|
355
393
|
shutdown_jvm() -> None
|
|
356
|
-
|
|
394
|
+
Shut down the JVM.
|
|
357
395
|
|
|
358
396
|
This function makes a best effort to clean up Java resources first.
|
|
359
397
|
In particular, shutdown hooks registered with scyjava.when_jvm_stops
|
|
@@ -371,6 +409,8 @@ FUNCTIONS
|
|
|
371
409
|
Note that if the JVM is not already running, then this function does
|
|
372
410
|
nothing! In particular, shutdown hooks are skipped in this situation.
|
|
373
411
|
|
|
412
|
+
:raise RuntimeError: if this method is called while in Jep mode.
|
|
413
|
+
|
|
374
414
|
start_jvm(options=None) -> None
|
|
375
415
|
Explicitly connect to the Java virtual machine (JVM). Only one JVM can
|
|
376
416
|
be active; does nothing if the JVM has already been started. Calling
|
|
@@ -378,8 +418,9 @@ FUNCTIONS
|
|
|
378
418
|
time a scyjava function needing a JVM is invoked, one is started on the
|
|
379
419
|
fly with the configuration specified via the scijava.config mechanism.
|
|
380
420
|
|
|
381
|
-
:param options:
|
|
382
|
-
|
|
421
|
+
:param options:
|
|
422
|
+
List of options to pass to the JVM.
|
|
423
|
+
For example: ['-Dfoo=bar', '-XX:+UnlockExperimentalVMOptions']
|
|
383
424
|
|
|
384
425
|
to_java(obj: Any, **hints: Dict) -> Any
|
|
385
426
|
Recursively convert a Python object to a Java object.
|
|
@@ -422,11 +463,13 @@ FUNCTIONS
|
|
|
422
463
|
* float values in Double range but outside float range convert to Double
|
|
423
464
|
* float values outside double range convert to BigDecimal
|
|
424
465
|
|
|
425
|
-
:param obj:
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
466
|
+
:param obj:
|
|
467
|
+
The Python object to convert.
|
|
468
|
+
:param hints:
|
|
469
|
+
An optional dictionary of hints, to help scyjava
|
|
470
|
+
make decisions about how to do the conversion.
|
|
471
|
+
:return: A corresponding Java object with the same contents.
|
|
472
|
+
:raise TypeError: if the argument is not one of the aforementioned types.
|
|
430
473
|
|
|
431
474
|
to_python(data: Any, gentle: bool = False) -> Any
|
|
432
475
|
Recursively convert a Java object to a Python object.
|
|
@@ -443,12 +486,15 @@ FUNCTIONS
|
|
|
443
486
|
* Iterable -> collections.abc.Iterable
|
|
444
487
|
* Iterator -> collections.abc.Iterator
|
|
445
488
|
|
|
446
|
-
:param data:
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
489
|
+
:param data:
|
|
490
|
+
The Java object to convert.
|
|
491
|
+
:param gentle:
|
|
492
|
+
If set, and the type cannot be converted, leaves
|
|
493
|
+
the data alone rather than raising a TypeError.
|
|
494
|
+
:return: A corresponding Python object with the same contents.
|
|
495
|
+
:raise TypeError:
|
|
496
|
+
if the argument is not one of the aforementioned types,
|
|
497
|
+
and the gentle flag is not set.
|
|
452
498
|
|
|
453
499
|
when_jvm_starts(f) -> None
|
|
454
500
|
Registers a function to be called when the JVM starts (or immediately).
|
|
@@ -477,7 +523,7 @@ unless you do one of two things:
|
|
|
477
523
|
|
|
478
524
|
```python
|
|
479
525
|
from scyjava import config, jimport
|
|
480
|
-
config.
|
|
526
|
+
config.enable_headless_mode()
|
|
481
527
|
```
|
|
482
528
|
|
|
483
529
|
In which case, you'll get `java.awt.HeadlessException` instead of a
|