Skip to main content

PEP-484 python stub generator for Java classes accessed through JPype

Project description

stubgenj

PEP-484 python stub generator for Java modules using the JPype import system. Originally based on mypy stubgenc.

Usage through cmmnbuild-dep-manager

$ python -m cmmnbuild_dep_manager stubgen

Every package registered in cmmnbuild_dep_manager can request stubs to be generated for particular prefixes by defining __stubgen_packages__ next to __cmmnbuild_deps__.

For more details, consult the cmmnbuild_dep_manager docs.

CLI usage

$ python -m stubgenj --help
usage: __main__.py [-h] [--jvmpath JVMPATH] [--classpath CLASSPATH]
                   [--output-dir OUTPUT_DIR] [--convert-strings]
                   [--no-stubs-suffix]
                   prefixes [prefixes ...]

Generate Python Type Stubs for Java classes.

positional arguments:
  prefixes              package prefixes to generate stubs for (e.g.
                        org.myproject)

optional arguments:
  -h, --help            show this help message and exit
  --jvmpath JVMPATH     path to the JVM ("libjvm.so", "jvm.dll", ...)
                        (default: use system default JVM)
  --classpath CLASSPATH
                        java class path to use, separated by ":". glob-like
                        expressions (e.g. dir/*.jar) are supported (default:
                        .)
  --output-dir OUTPUT_DIR
                        path to write stubs to (default: .)
  --convert-strings     convert java.lang.String to python str in return
                        types. consult the JPype documentation on the
                        convertStrings flag for details
  --no-stubs-suffix     do not use PEP-561 "-stubs" suffix for top-level
                        packages

E.g. generate stubs for java packages cern.lsa.* and java.* using the JARs from cmmnbuild-dep-manager:

$ python -m stubgenj --convert-strings --classpath "/path/to/cmmnbuild_dep_manager/lib/*.jar" cern.lsa java

The stubs will be put in the working directory as stub-only packages (PEP-561).

Python API usage

Start up the JVM, enable the JPype import system, then invoke stubgenj.generateJavaStubs.

With plain JPype:

import jpype
import stubgenj

jpype.startJVM(None, convertStrings=True)  # noqa
import jpype.imports  # noqa
import java.util  # noqa

stubgenj.generateJavaStubs([java.util], useStubsSuffix=True)

Through cmmnbuild-dep-manager:

import cmmnbuild_dep_manager
import stubgenj

with cmmnbuild_dep_manager.Manager().imports():
    import java.util  # noqa
    stubgenj.generateJavaStubs([java.util], useStubsSuffix=True)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

stubgenj-0.2.9.tar.gz (23.3 kB view details)

Uploaded Source

Built Distribution

stubgenj-0.2.9-py3-none-any.whl (21.8 kB view details)

Uploaded Python 3

File details

Details for the file stubgenj-0.2.9.tar.gz.

File metadata

  • Download URL: stubgenj-0.2.9.tar.gz
  • Upload date:
  • Size: 23.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.6.0 requests/2.25.1 setuptools/50.3.0.post20201006 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.5

File hashes

Hashes for stubgenj-0.2.9.tar.gz
Algorithm Hash digest
SHA256 2a0c823cd61d4cc1992be06838642383581e8cbeb5a589e47a3d09d4086f2b77
MD5 c8f30d68330f025a5b803642f45345ab
BLAKE2b-256 915ae1bded3c0c34bd9d62b46fe83e21f5f81b33bffe78d6bb88b179dbd9711c

See more details on using hashes here.

Provenance

File details

Details for the file stubgenj-0.2.9-py3-none-any.whl.

File metadata

  • Download URL: stubgenj-0.2.9-py3-none-any.whl
  • Upload date:
  • Size: 21.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.6.0 requests/2.25.1 setuptools/50.3.0.post20201006 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.5

File hashes

Hashes for stubgenj-0.2.9-py3-none-any.whl
Algorithm Hash digest
SHA256 f618b233ba8253a16cfd4e9ed0a14825736ebe06d63e277b01f4699c39b92698
MD5 0b3146bf3e4d84500790a334517d256e
BLAKE2b-256 2c45ebeaecb9288b587cf513e78f6a989cfef9b35111f9dbca4b947713fa4315

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page