Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make use of pyproject.toml for static project metadata #1133

Merged
merged 4 commits into from
Feb 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions .azure/scripts/coverage.yml
Original file line number Diff line number Diff line change
@@ -10,13 +10,12 @@ steps:

- script: |
python setup.py test_java
pip install gcovr pytest-cov jedi
pip install -r test-requirements.txt
pip install numpy typing_extensions
pip install gcovr pytest-cov -r test-requirements.txt
pip install numpy
displayName: 'Install requirements'

- script: |
python setup.py --enable-coverage --enable-build-jar build_ext --inplace
python setup.py develop --enable-coverage --enable-build-jar
displayName: 'Build'

- script: |
3 changes: 1 addition & 2 deletions .azure/scripts/debug.yml
Original file line number Diff line number Diff line change
@@ -7,8 +7,7 @@ steps:

- script: |
sudo apt install gdb
python setup.py sdist
pip install dist/*
pip install ./
displayName: 'Build module'

- script: python -c "import jpype"
4 changes: 2 additions & 2 deletions .azure/scripts/sdist.yml
Original file line number Diff line number Diff line change
@@ -3,8 +3,8 @@ steps:
inputs:
versionSpec: '3.8'
- script: |
python -m pip install setuptools
python setup.py sdist
python -m pip install build
python -m build ./ --sdist
displayName: Build sdist
- task: PublishPipelineArtifact@0
inputs:
2 changes: 1 addition & 1 deletion .azure/scripts/tracing.yml
Original file line number Diff line number Diff line change
@@ -4,6 +4,6 @@ steps:
inputs:
versionSpec: '3.8'
- script: |
python setup.py --enable-tracing --enable-build-jar build_ext --inplace
python setup.py develop --enable-tracing --enable-build-jar
displayName: 'Build'

15 changes: 15 additions & 0 deletions doc/CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -4,7 +4,20 @@ Changelog
This changelog *only* contains changes from the *first* pypi release (0.5.4.3) onwards.

Latest Changes:

- **1.5.1_dev0 - 2023-12-15**
- Use PEP-518 and PEP-660 configuration for the package, allowing editable and
configurable builds using modern Python packaging tooling.
Where before ``python setup.py --enable-tracing develop``, now can be done with
``pip install --editable ./ --config-setting="--install-option=--enable-tracing"``.
The old setup.py usage remains, but is discouraged, and the arguments are now passed
after the command (previously they were specified before).

- Use PEP-518 configuration for the package, allowing
configurable builds using more up-to-date Python packaging tooling.
For editable installs, ``python setup.py --enable-tracing develop``
must now be done with ``python setup.py develop --enable-tracing``.

- **1.5.0 - 2023-04-03**

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

- **1.4.2_dev0 - 2022-10-26**

- Fixed crash when calling subscript on JArray.

- Fixed direct byte buffers not reporting nbytes correctly when cast to
10 changes: 9 additions & 1 deletion doc/develguide.rst
Original file line number Diff line number Diff line change
@@ -943,7 +943,7 @@ must be enabled with a compiler switch to activate. To active the logger, touch
one of the cpp files in the native directory to mark the build as dirty, then
compile the ``jpype`` module with: ::

python setup.py --enable-tracing develop
python setup.py develop --enable-tracing

Once built run a short test program that demonstrates the problem and capture the
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... ::
python -m trace --trace myscript.py


Coverage
--------
Some of the tests require additional instrumentation to run, this can be enabled
with the ``enable-coverage`` option::

python setup.py develop --enable-coverage


Debugging issues
----------------

23 changes: 14 additions & 9 deletions doc/install.rst
Original file line number Diff line number Diff line change
@@ -83,27 +83,32 @@ from `PyPi <http://pypi.python.org/pypi/JPype1>`__.

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

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

python setup.py build
python -m build /path/to/source

The setup script recognizes several arguments.
A number of additional argument may be provided.

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

For example::

python -m build /path/to/source -C--global-option=build_ext -C--global-option="--enable-tracing"

After building, JPype can be tested using the test bench. The test
bench requires JDK to build.

**3. Test JPype with (optional):** ::
**3. Install the built wheel with:** ::

python setup.py test
pip install /path/to/wheel

**4. Install JPype with:** ::
**4. Test JPype with (optional):** ::

python setup.py test

python setup.py install


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

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

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

sudo apt-get install g++ python-dev python3-dev
sudo apt-get install g++ python3-dev

Windows
:::::::
58 changes: 57 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,60 @@
[build-system]
requires = [
"setuptools",
]
build-backend = "setuptools.build_meta"


[project]
name = "JPype1"
version = '1.5.0.dev0'
authors = [
{name = "Steve Menard", email = "[email protected]"},
]
maintainers = [
{name = "Luis Nell", email = "[email protected]"},
]
description = "A Python to Java bridge"
readme = "README.rst"
requires-python = ">=3.7"
license = {text = "License :: OSI Approved :: Apache Software License"}
classifiers = [
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Topic :: Software Development',
'Topic :: Scientific/Engineering',
]
dependencies = [
'packaging',
'typing_extensions ; python_version< "3.8"',
]


[project.optional-dependencies]

docs = [
'readthedocs-sphinx-ext',
'sphinx',
'sphinx-rtd-theme',
]
tests = [
"pytest",
]


[project.entry-points.pyinstaller40]
"hook-dirs" = "jpype._pyinstaller.entry_points:get_hook_dirs"
"tests" = "jpype._pyinstaller.entry_points:get_PyInstaller_tests"


[project.urls]
homepage = "https://github.com/jpype-project/jpype"


[[tool.mypy.overrides]]
module = [
"_jpype",
@@ -9,4 +66,3 @@ module = [
"jedi.access",
]
ignore_missing_imports = true

55 changes: 12 additions & 43 deletions setup.py
Original file line number Diff line number Diff line change
@@ -23,6 +23,8 @@
from setuptools import Extension
from setuptools import setup

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

if '--android' in sys.argv:
@@ -36,9 +38,12 @@
include_dirs=[Path('native', 'common', 'include'),
Path('native', 'python', 'include'),
Path('native', 'embedded', 'include')],
sources=sorted(map(str, list(Path('native', 'common').glob('*.cpp')) +
list(Path('native', 'python').glob('*.cpp')) +
list(Path('native', 'embedded').glob('*.cpp')))), platform=platform,
sources=sorted(
list(Path('native', 'common').glob('*.cpp')) +
list(Path('native', 'python').glob('*.cpp')) +
list(Path('native', 'embedded').glob('*.cpp'))
),
platform=platform,
))
jpypeJar = Extension(name="org.jpype",
sources=sorted(map(str, Path("native", "java").glob("**/*.java"))),
@@ -48,61 +53,25 @@


setup(
name='JPype1',
version='1.5.1_dev0',
description='A Python to Java bridge.',
long_description=open('README.rst').read(),
license='License :: OSI Approved :: Apache Software License',
author='Steve Menard',
author_email='[email protected]',
maintainer='Luis Nell',
maintainer_email='[email protected]',
python_requires=">=3.7",
url='https://github.com/jpype-project/jpype',
# Non-standard, and extension behaviour of setup() - project information
# should be put in pyproject.toml wherever possible. See also:
# https://setuptools.pypa.io/en/latest/userguide/pyproject_config.html#setuptools-specific-configuration
platforms=[
'Operating System :: Microsoft :: Windows',
'Operating System :: POSIX',
'Operating System :: Unix',
'Operating System :: MacOS',
],
classifiers=[
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Topic :: Software Development',
'Topic :: Scientific/Engineering',
],
packages=['jpype', 'jpype._pyinstaller'],
package_dir={'jpype': 'jpype', },
package_data={'jpype': ['*.pyi']},
install_requires=['typing_extensions ; python_version< "3.8"',
'packaging'],
tests_require=['pytest'],
extras_require={
'tests': [
'pytest',
],
'docs': [
'readthedocs-sphinx-ext',
'sphinx',
'sphinx-rtd-theme',
],
},
cmdclass={
'build_ext': setupext.build_ext.BuildExtCommand,
'develop': setupext.develop.Develop,
'test_java': setupext.test_java.TestJavaCommand,
'sdist': setupext.sdist.BuildSourceDistribution,
'test': setupext.pytester.PyTest,
},
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',
],
},
)
3 changes: 1 addition & 2 deletions setupext/__init__.py
Original file line number Diff line number Diff line change
@@ -16,10 +16,9 @@
#
# *****************************************************************************

from . import utils
from . import dist
from . import platform
from . import build_ext
from . import develop
from . import test_java
from . import sdist
from . import pytester
34 changes: 17 additions & 17 deletions setupext/build_ext.py
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@
# See NOTICE file for details.
#
# *****************************************************************************

import distutils.cmd
import distutils.log
import glob
@@ -43,7 +44,7 @@ class FeatureNotice(Warning):
""" indicate notices about features """


class Makefile(object):
class Makefile:
compiler_type = "unix"

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

user_options = build_ext.user_options + [
('enable-build-jar', None, 'Build the java jar portion'),
('enable-tracing', None, 'Set for tracing for debugging'),
('enable-coverage', None, 'Instrument c++ code for code coverage measuring'),

('android', None, 'configure for android'),
('makefile', None, 'Build a makefile for extensions'),
('jar', None, 'Build the jar only'),
]

def initialize_options(self, *args):
"""omit -Wstrict-prototypes from CFLAGS since its only valid for C code."""
self.enable_tracing = False
self.enable_build_jar = False
self.enable_coverage = False

self.android = False
self.makefile = False
self.jar = False
@@ -195,8 +204,7 @@ def initialize_options(self, *args):
continue

args = v.split()
for r in remove_args:
args = list(filter(r.__ne__, args))
args = [arg for arg in args if arg not in remove_args]

cfg_vars[k] = " ".join(args)
super().initialize_options()
@@ -205,12 +213,12 @@ def _set_cflags(self):
# set compiler flags
c = self.compiler.compiler_type
jpypeLib = [i for i in self.extensions if i.name == '_jpype'][0]
if c == 'unix' and self.distribution.enable_coverage:
if c == 'unix' and self.enable_coverage:
jpypeLib.extra_compile_args.extend(
['-ggdb', '--coverage', '-ftest-coverage'])
jpypeLib.extra_compile_args = ['-O0' if x == '-O2' else x for x in jpypeLib.extra_compile_args]
jpypeLib.extra_link_args.extend(['--coverage'])
if c == 'unix' and self.distribution.enable_tracing:
if c == 'unix' and self.enable_tracing:
jpypeLib.extra_compile_args = ['-O0' if x == '-O2' else x for x in jpypeLib.extra_compile_args]

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

jpypeLib = [i for i in self.extensions if i.name == '_jpype'][0]
tracing = self.distribution.enable_tracing
self._set_cflags()
if tracing:
if self.enable_tracing:
jpypeLib.define_macros.append(('JP_TRACING_ENABLE', 1))
coverage = self.distribution.enable_coverage
if coverage:
if self.enable_coverage:
jpypeLib.define_macros.append(('JP_INSTRUMENTATION', 1))

# has to be last call
print("Call build extensions")
super().build_extensions()

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

def build_java_ext(self, ext):
"""Run command."""
java = self.distribution.enable_build_jar
java = self.enable_build_jar

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

coverage = self.distribution.enable_coverage

target_version = "1.8"
# build the jar
try:
@@ -309,9 +311,7 @@ def build_java_ext(self, ext):
cmd1 = shlex.split('%s -cp "%s" -d "%s" -g:none -source %s -target %s -encoding UTF-8' %
(javac, classpath, build_dir, target_version, target_version))
cmd1.extend(ext.sources)
debug = "-g:none"
if coverage:
debug = "-g:lines,vars,source"

os.makedirs("build/classes", exist_ok=True)
self.announce(" %s" % " ".join(cmd1), level=distutils.log.INFO)
subprocess.check_call(cmd1)
22 changes: 14 additions & 8 deletions setupext/dist.py → setupext/develop.py
Original file line number Diff line number Diff line change
@@ -16,21 +16,27 @@
# See NOTICE file for details.
#
# *****************************************************************************
from setuptools.dist import Distribution as _Distribution

# Add a new global option to the setup.py script.
from setuptools.command.develop import develop as develop_cmd


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

] + _Distribution.global_options

def parse_command_line(self):
def initialize_options(self, *args):
self.enable_tracing = False
self.enable_build_jar = False
self.enable_coverage = False
return _Distribution.parse_command_line(self)
super().initialize_options()

def reinitialize_command(self, command, reinit_subcommands=0, **kw):
cmd = super().reinitialize_command(command, reinit_subcommands=reinit_subcommands, **kw)
build_ext_command = self.distribution.get_command_obj("build_ext")
build_ext_command.enable_tracing = self.enable_tracing
build_ext_command.enable_build_jar = self.enable_build_jar
build_ext_command.enable_coverage = self.enable_coverage
return cmd
36 changes: 10 additions & 26 deletions setupext/platform.py
Original file line number Diff line number Diff line change
@@ -18,22 +18,20 @@
# *****************************************************************************
import setupext
import os
from pathlib import Path
import sys
import sysconfig
import typing
import distutils.log

# This handles all of the work to make our platform specific extension options.
# This handles all the work to make our platform specific extension options.


def Platform(include_dirs=None, sources=None, platform=sys.platform):
if include_dirs is None:
include_dirs = []
if sources is None:
sources = []

def Platform(*, include_dirs: typing.Sequence[Path], sources: typing.Sequence[Path], platform: str):
sources = [str(pth) for pth in sources]
platform_specific = {
'include_dirs': include_dirs,
'sources': setupext.utils.find_sources(sources),
'sources': sources,
}

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

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

Check notice

Code scanning / CodeQL

Commented-out code

This comment appears to contain commented-out code.

if found_jni:
distutils.log.info("Add JNI directory %s" % os.path.join(java_home, 'include', jni_md_platform))
platform_specific['include_dirs'] += \
[os.path.join(java_home, 'include', jni_md_platform)]
return platform_specific


# include this stolen from FindJNI.cmake
"""
FIND_PATH(JAVA_INCLUDE_PATH2 jni_md.h
${JAVA_INCLUDE_PATH}
${JAVA_INCLUDE_PATH}/win32
${JAVA_INCLUDE_PATH}/linux
${JAVA_INCLUDE_PATH}/freebsd
${JAVA_INCLUDE_PATH}/openbsd
${JAVA_INCLUDE_PATH}/solaris
${JAVA_INCLUDE_PATH}/hp-ux
${JAVA_INCLUDE_PATH}/alpha
)"""
1 change: 0 additions & 1 deletion setupext/test_java.py
Original file line number Diff line number Diff line change
@@ -16,7 +16,6 @@
# See NOTICE file for details.
#
# *****************************************************************************
import sys
import os
import subprocess
import distutils.cmd
34 changes: 0 additions & 34 deletions setupext/utils.py

This file was deleted.