Class AllowPythonClassEnquirer
- All Implemented Interfaces:
ClassEnquirer
A ClassEnquirer that defines specific packages as Python packages.
This implementation takes a delegate ClassEnquirer to delegate all import
determinations as Java or Python except in the cases of the specific Python
package names provided. Imports of the specified packages in the embedded
Python interpreter will use the Python importer and not the Java importer.
This is useful when you have package name conflicts between Java and Python.
Some examples are projects like py4j and tensorflow which have Python package
names matching Java package names. In those cases, using the default
ClassEnquirer of ClassList will lead to the Java packages on the
classpath taking precedence on imports instead of the Python package. That
can be solved by using this ClassEnquirer with a delegate of ClassList's
instance.
- Since:
- 4.2.1
-
Field Summary
Fields inherited from interface jep.ClassEnquirer
RESTRICTED_PKG_NAMES -
Constructor Summary
ConstructorsConstructorDescriptionAllowPythonClassEnquirer(ClassEnquirer delegate, String... pythonPackageNames) Constructor -
Method Summary
Modifier and TypeMethodDescriptionString[]getClassNames(String pkgName) Given a Java package name, gets the fully-qualified classnames available for import in the package.String[]getSubPackages(String pkgName) Given a Java package name, gets the sub-packages available.booleanisJavaPackage(String name) Checks if the name is likely available in Java as a package.
-
Constructor Details
-
AllowPythonClassEnquirer
Constructor- Parameters:
delegate- the ClassEnquirer instance to delegate method calls to except in the case of the specified Python package namespythonPackageNames- the names of Python packages that should not be treated as a potential import from Java and instead should immediately default to being imported by the normal Python importer
-
-
Method Details
-
isJavaPackage
Description copied from interface:ClassEnquirerChecks if the name is likely available in Java as a package. A return value of true implies the name corresponds to a Java package, but does not guarantee that an import will succeed. A return value of false implies that an import from Java would fail, but does not guarantee that an import will fail. Note: A fully-qualified Java class name should return false since it is not a package name and the importer hook is expecting that.- Specified by:
isJavaPackagein interfaceClassEnquirer- Parameters:
name- the name to check, such as java, java.util, java.util.ArrayList- Returns:
- true if it's likely a package supported by Java, false if it's likely a Python module (or a Java class name, or an invalid import)
-
getClassNames
Description copied from interface:ClassEnquirerGiven a Java package name, gets the fully-qualified classnames available for import in the package. This method is primarily used for introspection using Python's dir() method. This method can return null if dir() support is not necessary.- Specified by:
getClassNamesin interfaceClassEnquirer- Parameters:
pkgName- the name of a package the ClassEnquirer supports, such as java.util- Returns:
- the list of classnames in the package, or null
-
getSubPackages
Description copied from interface:ClassEnquirerGiven a Java package name, gets the sub-packages available. For example, a sub-package of package "java" is "util", and a sub-package of package "java.util" is "concurrent". This method is primarily used for introspection using Python's dir() method. This method can return null if dir() support is not necessary.- Specified by:
getSubPackagesin interfaceClassEnquirer- Parameters:
pkgName- the name of a package the ClassEnquirer supports, such as java.util- Returns:
- the list of sub-packages in the package, or null
-