Skip to content

Commit

Permalink
Merge pull request #877 from altendky/pyinstaller_hook
Browse files Browse the repository at this point in the history
Add PyInstaller hook
  • Loading branch information
marscher committed Nov 16, 2020
2 parents 7256261 + 28ad4aa commit 39ae320
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 2 deletions.
8 changes: 8 additions & 0 deletions .azure/scripts/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ steps:
python -m pytest -v --junit-xml=build/test/test.xml test/jpypetest --checkjni
displayName: 'Test JDK 11'

# presence of jpype/ seems to confuse entry_points so `cd` elsewhere
- script: |
pip install .
mkdir empty
cd empty
python -m PyInstaller.utils.run_tests --include_only jpype._pyinstaller.
displayName: 'Test PyInstaller result'

- task: PublishTestResults@2
condition: succeededOrFailed()
inputs:
Expand Down
9 changes: 9 additions & 0 deletions doc/userguide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3285,3 +3285,12 @@ resulting in unusual behavior with certain windows calls. The path
separator for Cygwin does not match that of the Java DLL, thus specification
of class paths must account for this. Threading between the Cygwin libraries
and the JVM was often unstable.
.. _freezing:
Freezing
========
JPype supports freezing and deployment with
`PyInstaller <https://pyinstaller.readthedocs.io/>`_. The hook is included
with JPype installations and no extra configuration should be needed.
16 changes: 16 additions & 0 deletions jpype/_pyinstaller/entry_points.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import os
from pathlib import Path


fspath = getattr(os, 'fspath', str)


_pyinstaller_path = Path(__file__).parent


def get_hook_dirs():
return [fspath(_pyinstaller_path)]


def get_PyInstaller_tests():
return [fspath(_pyinstaller_path)]
5 changes: 5 additions & 0 deletions jpype/_pyinstaller/example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import jpype

print('+++ about to start JVM')
jpype.startJVM()
print('+++ JVM started')
11 changes: 11 additions & 0 deletions jpype/_pyinstaller/hook-jpype.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import os
from pathlib import Path

import jpype


fspath = getattr(os, 'fspath', str)

jar_path = Path(jpype.__file__).parent.parent.joinpath('org.jpype.jar')

datas = [[fspath(jar_path), '.']]
31 changes: 31 additions & 0 deletions jpype/_pyinstaller/test_jpype_pyinstaller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import os
from pathlib import Path
from subprocess import run

import jpype
import PyInstaller.__main__


fspath = getattr(os, 'fspath', str)


example_path = Path(__file__).parent.joinpath('example.py')


def test_start_and_stop(tmp_path):
name = 'e'
dist = tmp_path.joinpath('dist')
work = tmp_path.joinpath('build')
result = dist.joinpath(name, name)

PyInstaller.__main__.run([
'--name',
name,
'--distpath',
fspath(dist),
'--workpath',
fspath(work),
fspath(example_path),
])

run([fspath(result)], check=True, cwd=fspath(tmp_path))
4 changes: 3 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ test=pytest

[tool:pytest]
addopts = --verbose
testpaths = test
testpaths =
test
jpype/_pyinstaller
8 changes: 7 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
'Topic :: Software Development',
'Topic :: Scientific/Engineering',
],
packages=['jpype'],
packages=['jpype', 'jpype._pyinstaller'],
package_dir={'jpype': 'jpype', },
install_requires=['typing_extensions ; python_version< "3.8"'],
tests_require=['pytest'],
Expand All @@ -90,5 +90,11 @@
zip_safe=False,
ext_modules=[jpypeJar, jpypeLib, ],
distclass=setupext.dist.Distribution,
entry_points={
'pyinstaller40': [
'hook-dirs = jpype._pyinstaller.entry_points:get_hook_dirs',
'tests = jpype._pyinstaller.entry_points:get_PyInstaller_tests',
],
},
)

1 change: 1 addition & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pytest==4.6.9
pyinstaller==4.0
jedi==0.17.0

0 comments on commit 39ae320

Please sign in to comment.