Skip to content

Commit 904fc43

Browse files
authoredFeb 13, 2024··
Merge pull request #1133 from pelson/feature/pyproject
Make use of pyproject.toml for static project metadata
2 parents df64941 + b9472a3 commit 904fc43

15 files changed

+156
-151
lines changed
 

‎.azure/scripts/coverage.yml

+3-4
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@ steps:
1010

1111
- script: |
1212
python setup.py test_java
13-
pip install gcovr pytest-cov jedi
14-
pip install -r test-requirements.txt
15-
pip install numpy typing_extensions
13+
pip install gcovr pytest-cov -r test-requirements.txt
14+
pip install numpy
1615
displayName: 'Install requirements'
1716

1817
- script: |
19-
python setup.py --enable-coverage --enable-build-jar build_ext --inplace
18+
python setup.py develop --enable-coverage --enable-build-jar
2019
displayName: 'Build'
2120

2221
- script: |

‎.azure/scripts/debug.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ steps:
77

88
- script: |
99
sudo apt install gdb
10-
python setup.py sdist
11-
pip install dist/*
10+
pip install ./
1211
displayName: 'Build module'
1312

1413
- script: python -c "import jpype"

‎.azure/scripts/sdist.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ steps:
33
inputs:
44
versionSpec: '3.8'
55
- script: |
6-
python -m pip install setuptools
7-
python setup.py sdist
6+
python -m pip install build
7+
python -m build ./ --sdist
88
displayName: Build sdist
99
- task: PublishPipelineArtifact@0
1010
inputs:

‎.azure/scripts/tracing.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ steps:
44
inputs:
55
versionSpec: '3.8'
66
- script: |
7-
python setup.py --enable-tracing --enable-build-jar build_ext --inplace
7+
python setup.py develop --enable-tracing --enable-build-jar
88
displayName: 'Build'
99

‎doc/CHANGELOG.rst

+15
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,20 @@ Changelog
44
This changelog *only* contains changes from the *first* pypi release (0.5.4.3) onwards.
55

66
Latest Changes:
7+
78
- **1.5.1_dev0 - 2023-12-15**
9+
- Use PEP-518 and PEP-660 configuration for the package, allowing editable and
10+
configurable builds using modern Python packaging tooling.
11+
Where before ``python setup.py --enable-tracing develop``, now can be done with
12+
``pip install --editable ./ --config-setting="--install-option=--enable-tracing"``.
13+
The old setup.py usage remains, but is discouraged, and the arguments are now passed
14+
after the command (previously they were specified before).
15+
16+
- Use PEP-518 configuration for the package, allowing
17+
configurable builds using more up-to-date Python packaging tooling.
18+
For editable installs, ``python setup.py --enable-tracing develop``
19+
must now be done with ``python setup.py develop --enable-tracing``.
20+
821
- **1.5.0 - 2023-04-03**
922

1023
- Support for Python 3.12
@@ -18,6 +31,8 @@ Latest Changes:
1831
- Java exceptions that occur in inequality comparisons now map to Python
1932
TypeError.
2033

34+
- **1.4.2_dev0 - 2022-10-26**
35+
2136
- Fixed crash when calling subscript on JArray.
2237

2338
- Fixed direct byte buffers not reporting nbytes correctly when cast to

‎doc/develguide.rst

+9-1
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,7 @@ must be enabled with a compiler switch to activate. To active the logger, touch
943943
one of the cpp files in the native directory to mark the build as dirty, then
944944
compile the ``jpype`` module with: ::
945945

946-
python setup.py --enable-tracing develop
946+
python setup.py develop --enable-tracing
947947

948948
Once built run a short test program that demonstrates the problem and capture the
949949
output of the terminal to a file. This should allow the developer to isolate
@@ -959,6 +959,14 @@ To use the Python tracing, start Python with... ::
959959
python -m trace --trace myscript.py
960960

961961

962+
Coverage
963+
--------
964+
Some of the tests require additional instrumentation to run, this can be enabled
965+
with the ``enable-coverage`` option::
966+
967+
python setup.py develop --enable-coverage
968+
969+
962970
Debugging issues
963971
----------------
964972

‎doc/install.rst

+14-9
Original file line numberDiff line numberDiff line change
@@ -83,27 +83,32 @@ from `PyPi <http://pypi.python.org/pypi/JPype1>`__.
8383

8484
**2. Build the source with desired options**
8585

86-
Compile JPype using the included ``setup.py`` script: ::
86+
Compile JPype using the `build <https://pypi.org/project/build/>` module (this will produce a wheel): ::
8787

88-
python setup.py build
88+
python -m build /path/to/source
8989

90-
The setup script recognizes several arguments.
90+
A number of additional argument may be provided.
9191

9292
--enable-build-jar Force setup to recreate the jar from scratch.
9393
--enable-tracing Build a verison of JPype with full logging to the
9494
console. This can be used to diagnose tricky JNI
9595
issues.
9696

97+
For example::
98+
99+
python -m build /path/to/source -C--global-option=build_ext -C--global-option="--enable-tracing"
100+
97101
After building, JPype can be tested using the test bench. The test
98102
bench requires JDK to build.
99103

100-
**3. Test JPype with (optional):** ::
104+
**3. Install the built wheel with:** ::
101105

102-
python setup.py test
106+
pip install /path/to/wheel
103107

104-
**4. Install JPype with:** ::
108+
**4. Test JPype with (optional):** ::
109+
110+
python setup.py test
105111

106-
python setup.py install
107112

108113

109114
If it fails...
@@ -116,7 +121,7 @@ happens, preform the following steps:
116121
1. Identify the location of your systems JDK installation and explicitly passing
117122
it to setup.py. ::
118123

119-
JAVA_HOME=/usr/lib/java/jdk1.8.0/ python setup.py install
124+
JAVA_HOME=/usr/lib/java/jdk1.8.0/ python -m build .
120125

121126
2. If that setup.py still fails please create an Issue `on
122127
github <https://github.com/jpype-project/jpype/issues?state=open>`__ and
@@ -138,7 +143,7 @@ Debian/Ubuntu
138143
Debian/Ubuntu users will have to install ``g++`` and ``python-dev``.
139144
Use:
140145

141-
sudo apt-get install g++ python-dev python3-dev
146+
sudo apt-get install g++ python3-dev
142147

143148
Windows
144149
:::::::

‎pyproject.toml

+57-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,60 @@
1+
[build-system]
2+
requires = [
3+
"setuptools",
4+
]
5+
build-backend = "setuptools.build_meta"
6+
7+
8+
[project]
9+
name = "JPype1"
10+
version = '1.5.0.dev0'
11+
authors = [
12+
{name = "Steve Menard", email = "devilwolf@users.sourceforge.net"},
13+
]
14+
maintainers = [
15+
{name = "Luis Nell", email = "cooperate@originell.org"},
16+
]
17+
description = "A Python to Java bridge"
18+
readme = "README.rst"
19+
requires-python = ">=3.7"
20+
license = {text = "License :: OSI Approved :: Apache Software License"}
21+
classifiers = [
22+
'Programming Language :: Python :: 3',
23+
'Programming Language :: Python :: 3.7',
24+
'Programming Language :: Python :: 3.8',
25+
'Programming Language :: Python :: 3.9',
26+
'Programming Language :: Python :: 3.10',
27+
'Programming Language :: Python :: 3.11',
28+
'Topic :: Software Development',
29+
'Topic :: Scientific/Engineering',
30+
]
31+
dependencies = [
32+
'packaging',
33+
'typing_extensions ; python_version< "3.8"',
34+
]
35+
36+
37+
[project.optional-dependencies]
38+
39+
docs = [
40+
'readthedocs-sphinx-ext',
41+
'sphinx',
42+
'sphinx-rtd-theme',
43+
]
44+
tests = [
45+
"pytest",
46+
]
47+
48+
49+
[project.entry-points.pyinstaller40]
50+
"hook-dirs" = "jpype._pyinstaller.entry_points:get_hook_dirs"
51+
"tests" = "jpype._pyinstaller.entry_points:get_PyInstaller_tests"
52+
53+
54+
[project.urls]
55+
homepage = "https://github.com/jpype-project/jpype"
56+
57+
158
[[tool.mypy.overrides]]
259
module = [
360
"_jpype",
@@ -9,4 +66,3 @@ module = [
966
"jedi.access",
1067
]
1168
ignore_missing_imports = true
12-

‎setup.py

+12-43
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
from setuptools import Extension
2424
from setuptools import setup
2525

26+
# Add our setupext package to the path, and import it.
27+
sys.path.append(str(Path(__file__).parent))
2628
import setupext
2729

2830
if '--android' in sys.argv:
@@ -36,9 +38,12 @@
3638
include_dirs=[Path('native', 'common', 'include'),
3739
Path('native', 'python', 'include'),
3840
Path('native', 'embedded', 'include')],
39-
sources=sorted(map(str, list(Path('native', 'common').glob('*.cpp')) +
40-
list(Path('native', 'python').glob('*.cpp')) +
41-
list(Path('native', 'embedded').glob('*.cpp')))), platform=platform,
41+
sources=sorted(
42+
list(Path('native', 'common').glob('*.cpp')) +
43+
list(Path('native', 'python').glob('*.cpp')) +
44+
list(Path('native', 'embedded').glob('*.cpp'))
45+
),
46+
platform=platform,
4247
))
4348
jpypeJar = Extension(name="org.jpype",
4449
sources=sorted(map(str, Path("native", "java").glob("**/*.java"))),
@@ -48,61 +53,25 @@
4853

4954

5055
setup(
51-
name='JPype1',
52-
version='1.5.1_dev0',
53-
description='A Python to Java bridge.',
54-
long_description=open('README.rst').read(),
55-
license='License :: OSI Approved :: Apache Software License',
56-
author='Steve Menard',
57-
author_email='devilwolf@users.sourceforge.net',
58-
maintainer='Luis Nell',
59-
maintainer_email='cooperate@originell.org',
60-
python_requires=">=3.7",
61-
url='https://github.com/jpype-project/jpype',
56+
# Non-standard, and extension behaviour of setup() - project information
57+
# should be put in pyproject.toml wherever possible. See also:
58+
# https://setuptools.pypa.io/en/latest/userguide/pyproject_config.html#setuptools-specific-configuration
6259
platforms=[
6360
'Operating System :: Microsoft :: Windows',
6461
'Operating System :: POSIX',
6562
'Operating System :: Unix',
6663
'Operating System :: MacOS',
6764
],
68-
classifiers=[
69-
'Programming Language :: Python :: 3',
70-
'Programming Language :: Python :: 3.7',
71-
'Programming Language :: Python :: 3.8',
72-
'Programming Language :: Python :: 3.9',
73-
'Programming Language :: Python :: 3.10',
74-
'Topic :: Software Development',
75-
'Topic :: Scientific/Engineering',
76-
],
7765
packages=['jpype', 'jpype._pyinstaller'],
7866
package_dir={'jpype': 'jpype', },
7967
package_data={'jpype': ['*.pyi']},
80-
install_requires=['typing_extensions ; python_version< "3.8"',
81-
'packaging'],
82-
tests_require=['pytest'],
83-
extras_require={
84-
'tests': [
85-
'pytest',
86-
],
87-
'docs': [
88-
'readthedocs-sphinx-ext',
89-
'sphinx',
90-
'sphinx-rtd-theme',
91-
],
92-
},
9368
cmdclass={
9469
'build_ext': setupext.build_ext.BuildExtCommand,
70+
'develop': setupext.develop.Develop,
9571
'test_java': setupext.test_java.TestJavaCommand,
9672
'sdist': setupext.sdist.BuildSourceDistribution,
9773
'test': setupext.pytester.PyTest,
9874
},
9975
zip_safe=False,
10076
ext_modules=[jpypeJar, jpypeLib, ],
101-
distclass=setupext.dist.Distribution,
102-
entry_points={
103-
'pyinstaller40': [
104-
'hook-dirs = jpype._pyinstaller.entry_points:get_hook_dirs',
105-
'tests = jpype._pyinstaller.entry_points:get_PyInstaller_tests',
106-
],
107-
},
10877
)

‎setupext/__init__.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@
1616
#
1717
# *****************************************************************************
1818

19-
from . import utils
20-
from . import dist
2119
from . import platform
2220
from . import build_ext
21+
from . import develop
2322
from . import test_java
2423
from . import sdist
2524
from . import pytester

‎setupext/build_ext.py

+17-17
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
# See NOTICE file for details.
1717
#
1818
# *****************************************************************************
19+
1920
import distutils.cmd
2021
import distutils.log
2122
import glob
@@ -43,7 +44,7 @@ class FeatureNotice(Warning):
4344
""" indicate notices about features """
4445

4546

46-
class Makefile(object):
47+
class Makefile:
4748
compiler_type = "unix"
4849

4950
def __init__(self, actual):
@@ -172,13 +173,21 @@ class BuildExtCommand(build_ext):
172173
"""
173174

174175
user_options = build_ext.user_options + [
176+
('enable-build-jar', None, 'Build the java jar portion'),
177+
('enable-tracing', None, 'Set for tracing for debugging'),
178+
('enable-coverage', None, 'Instrument c++ code for code coverage measuring'),
179+
175180
('android', None, 'configure for android'),
176181
('makefile', None, 'Build a makefile for extensions'),
177182
('jar', None, 'Build the jar only'),
178183
]
179184

180185
def initialize_options(self, *args):
181186
"""omit -Wstrict-prototypes from CFLAGS since its only valid for C code."""
187+
self.enable_tracing = False
188+
self.enable_build_jar = False
189+
self.enable_coverage = False
190+
182191
self.android = False
183192
self.makefile = False
184193
self.jar = False
@@ -195,8 +204,7 @@ def initialize_options(self, *args):
195204
continue
196205

197206
args = v.split()
198-
for r in remove_args:
199-
args = list(filter(r.__ne__, args))
207+
args = [arg for arg in args if arg not in remove_args]
200208

201209
cfg_vars[k] = " ".join(args)
202210
super().initialize_options()
@@ -205,12 +213,12 @@ def _set_cflags(self):
205213
# set compiler flags
206214
c = self.compiler.compiler_type
207215
jpypeLib = [i for i in self.extensions if i.name == '_jpype'][0]
208-
if c == 'unix' and self.distribution.enable_coverage:
216+
if c == 'unix' and self.enable_coverage:
209217
jpypeLib.extra_compile_args.extend(
210218
['-ggdb', '--coverage', '-ftest-coverage'])
211219
jpypeLib.extra_compile_args = ['-O0' if x == '-O2' else x for x in jpypeLib.extra_compile_args]
212220
jpypeLib.extra_link_args.extend(['--coverage'])
213-
if c == 'unix' and self.distribution.enable_tracing:
221+
if c == 'unix' and self.enable_tracing:
214222
jpypeLib.extra_compile_args = ['-O0' if x == '-O2' else x for x in jpypeLib.extra_compile_args]
215223

216224
def build_extensions(self):
@@ -219,16 +227,12 @@ def build_extensions(self):
219227
self.force = True
220228

221229
jpypeLib = [i for i in self.extensions if i.name == '_jpype'][0]
222-
tracing = self.distribution.enable_tracing
223230
self._set_cflags()
224-
if tracing:
231+
if self.enable_tracing:
225232
jpypeLib.define_macros.append(('JP_TRACING_ENABLE', 1))
226-
coverage = self.distribution.enable_coverage
227-
if coverage:
233+
if self.enable_coverage:
228234
jpypeLib.define_macros.append(('JP_INSTRUMENTATION', 1))
229235

230-
# has to be last call
231-
print("Call build extensions")
232236
super().build_extensions()
233237

234238
def build_extension(self, ext):
@@ -266,7 +270,7 @@ def copy_extensions_to_source(self):
266270

267271
def build_java_ext(self, ext):
268272
"""Run command."""
269-
java = self.distribution.enable_build_jar
273+
java = self.enable_build_jar
270274

271275
javac = "javac"
272276
try:
@@ -296,8 +300,6 @@ def build_java_ext(self, ext):
296300
distutils.log.info(
297301
"Jar cache is missing, using --enable-build-jar to recreate it.")
298302

299-
coverage = self.distribution.enable_coverage
300-
301303
target_version = "1.8"
302304
# build the jar
303305
try:
@@ -309,9 +311,7 @@ def build_java_ext(self, ext):
309311
cmd1 = shlex.split('%s -cp "%s" -d "%s" -g:none -source %s -target %s -encoding UTF-8' %
310312
(javac, classpath, build_dir, target_version, target_version))
311313
cmd1.extend(ext.sources)
312-
debug = "-g:none"
313-
if coverage:
314-
debug = "-g:lines,vars,source"
314+
315315
os.makedirs("build/classes", exist_ok=True)
316316
self.announce(" %s" % " ".join(cmd1), level=distutils.log.INFO)
317317
subprocess.check_call(cmd1)

‎setupext/dist.py ‎setupext/develop.py

+14-8
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,27 @@
1616
# See NOTICE file for details.
1717
#
1818
# *****************************************************************************
19-
from setuptools.dist import Distribution as _Distribution
2019

21-
# Add a new global option to the setup.py script.
20+
from setuptools.command.develop import develop as develop_cmd
2221

2322

24-
class Distribution(_Distribution):
25-
global_options = [
23+
class Develop(develop_cmd):
24+
user_options = develop_cmd.user_options + [
2625
('enable-build-jar', None, 'Build the java jar portion'),
2726
('enable-tracing', None, 'Set for tracing for debugging'),
2827
('enable-coverage', None, 'Instrument c++ code for code coverage measuring'),
28+
]
2929

30-
] + _Distribution.global_options
31-
32-
def parse_command_line(self):
30+
def initialize_options(self, *args):
3331
self.enable_tracing = False
3432
self.enable_build_jar = False
3533
self.enable_coverage = False
36-
return _Distribution.parse_command_line(self)
34+
super().initialize_options()
35+
36+
def reinitialize_command(self, command, reinit_subcommands=0, **kw):
37+
cmd = super().reinitialize_command(command, reinit_subcommands=reinit_subcommands, **kw)
38+
build_ext_command = self.distribution.get_command_obj("build_ext")
39+
build_ext_command.enable_tracing = self.enable_tracing
40+
build_ext_command.enable_build_jar = self.enable_build_jar
41+
build_ext_command.enable_coverage = self.enable_coverage
42+
return cmd

‎setupext/platform.py

+10-26
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,20 @@
1818
# *****************************************************************************
1919
import setupext
2020
import os
21+
from pathlib import Path
2122
import sys
2223
import sysconfig
24+
import typing
2325
import distutils.log
2426

25-
# This handles all of the work to make our platform specific extension options.
27+
# This handles all the work to make our platform specific extension options.
2628

2729

28-
def Platform(include_dirs=None, sources=None, platform=sys.platform):
29-
if include_dirs is None:
30-
include_dirs = []
31-
if sources is None:
32-
sources = []
33-
30+
def Platform(*, include_dirs: typing.Sequence[Path], sources: typing.Sequence[Path], platform: str):
31+
sources = [str(pth) for pth in sources]
3432
platform_specific = {
3533
'include_dirs': include_dirs,
36-
'sources': setupext.utils.find_sources(sources),
34+
'sources': sources,
3735
}
3836

3937
fallback_jni = os.path.join('native', 'jni_include')
@@ -120,27 +118,13 @@ def Platform(include_dirs=None, sources=None, platform=sys.platform):
120118
distutils.log.warn("Your platform '%s' is not being handled explicitly."
121119
" It may work or not!", platform)
122120

123-
# This code is used to include python library in the build when starting Python from
124-
# within Java. It will be used in the future, but is not currently required.
125-
# if static and sysconfig.get_config_var('BLDLIBRARY') is not None:
126-
# platform_specific['extra_link_args'].append(sysconfig.get_config_var('BLDLIBRARY'))
121+
# This code is used to include python library in the build when starting Python from
122+
# within Java. It will be used in the future, but is not currently required.
123+
# if static and sysconfig.get_config_var('BLDLIBRARY') is not None:
124+
# platform_specific['extra_link_args'].append(sysconfig.get_config_var('BLDLIBRARY'))
127125

128126
if found_jni:
129127
distutils.log.info("Add JNI directory %s" % os.path.join(java_home, 'include', jni_md_platform))
130128
platform_specific['include_dirs'] += \
131129
[os.path.join(java_home, 'include', jni_md_platform)]
132130
return platform_specific
133-
134-
135-
# include this stolen from FindJNI.cmake
136-
"""
137-
FIND_PATH(JAVA_INCLUDE_PATH2 jni_md.h
138-
${JAVA_INCLUDE_PATH}
139-
${JAVA_INCLUDE_PATH}/win32
140-
${JAVA_INCLUDE_PATH}/linux
141-
${JAVA_INCLUDE_PATH}/freebsd
142-
${JAVA_INCLUDE_PATH}/openbsd
143-
${JAVA_INCLUDE_PATH}/solaris
144-
${JAVA_INCLUDE_PATH}/hp-ux
145-
${JAVA_INCLUDE_PATH}/alpha
146-
)"""

‎setupext/test_java.py

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
# See NOTICE file for details.
1717
#
1818
# *****************************************************************************
19-
import sys
2019
import os
2120
import subprocess
2221
import distutils.cmd

‎setupext/utils.py

-34
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.