RE: AttributeError: 'bool' object has no attribute 'setdefault'
On Thu, 7 May 2020, Chee Yong Teh wrote: Hi Andi, I think I got it working but there is an issue with the class name with '.'. In the jar there are some class name like below public static final class SensitivityProfileIdList.Builder public static final class SRMBreakdown.Builder Yes, these are so-called inner classes. So JCC will wrap this can change the '.' to '$' Which Java exposes to JCC with a '$' in place of the '.' in the name. SensitivityProfileIdList$Builder SRMBreakdown$Builder I cannot really use this classes in python and python flag it up as syntax error. Would it be better to use '_' instead of '$' to replace the '.' in the class name? That's definitely an option. Doing this automatically may then cause a clash with a class that uses _ already. There is a --rename flag that lets you control the name to pick: --rename 'full.package.path.here.SensitivityProfileIdList$Builder=SensitivityProfileIdList_Builder' (you need '' around a string with literal $ in a shell command line) Andi.. Thanks, Chee Yong Chee Yong Teh 27 Bush Lane, London, EC4R 0AN | +44 203 929 3138 OTC Infrastructure Service of the Year & Global Compression Service of the Year -Original Message- From: Andi Vajda Sent: 06 May 2020 00:34 To: Chee Yong Teh Cc: pylucene-dev@lucene.apache.org Subject: Re: AttributeError: 'bool' object has no attribute 'setdefault' On May 5, 2020, at 16:17, Chee Yong Teh wrote: Hi Andi, Ok I have changed the command to python -m jcc --version 7.1.4 --use_full_names --include /home/cheeyong.teh/SMART-API-7.1.4/smart/lib/smart-swapclear-public-release_daru.12. jar --include /home/cheeyong.teh/SMART-API-7.1.4/smart/lib/colt-1.2.0.jar --include /home/cheeyong.teh/SMART-API-7.1.4/smart/lib/commons-math3-3.6.1.jar --include /home/cheeyong .teh/SMART-API-7.1.4/smart/lib/jna-5.2.0.jar --include /home/cheeyong.teh/SMART-API-7.1.4/smart/lib/log4j-1.2.16.jar --include /home/cheeyong.teh/SMART-API-7.1.4/smart/lib/proto buf-java-3.5.1.jar --include /home/cheeyong.teh/SMART-API-7.1.4/smart/lib/slf4j-api-1.6.1.jar --include /home/cheeyong.teh/SMART-API-7.1.4/smart/lib/slf4j-log4j12-1.6.1.jar --py thon lch_smart --build --install com.lchclearnet.swapclear.smart.SMARTClientDataProviderFactory I'm using --include instead of --jar and pass in com.lchclearnet.swapclear.smart.SMARTClientDataProviderFactory as a class I want to wrap. It seem fine and everything build fine but when I do a print(dir(lch_smart)). It doesn't seem to wrap that SMARTClientDataProviderFactory class print(dir(lch_smart)) ['CLASSPATH', 'ConstVariableDescriptor', 'FinalizerClass', 'FinalizerProxy', 'InvalidArgsError', 'JArray', 'JArray_bool', 'JArray_byte', 'JArray_char', 'JArray_double', 'JArray_float', 'JArray_int', 'JArray_long', 'JArray_object', 'JArray_short', 'JArray_string', 'JCCEnv', 'JCC_VERSION', 'JObject', 'JavaError', 'PrintWriter', 'StringWriter', 'VERSION', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__module_dir__', '__name__', '__package__', '__path__', '__spec__', '_lch_smart', 'findClass', 'getVMEnv', 'initVM', 'makeClass', 'makeInterface', 'os'] You're using --use_full_names, thus to access the wrapper for com.lchclearnet.swapclear.smart.SMARTClientDataProviderFactory you need to say: >>> from com.lchclearnet.swapclear.smart import SMARTClientDataProviderFactory Andi.. If I use --jar option I will still get the "AttributeError: 'bool' object has no attribute 'setdefault'" error. Thanks, Chee Yong Chee Yong Teh 27 Bush Lane, London, EC4R 0AN | +44 203 929 3138 OTC Infrastructure Service of the Year & Global Compression Service of the Year -Original Message- From: Andi Vajda Sent: 05 May 2020 23:30 To: Chee Yong Teh Cc: pylucene-dev@lucene.apache.org Subject: Re: AttributeError: 'bool' object has no attribute 'setdefault' On Tue, 5 May 2020, Chee Yong Teh wrote: Hi Andi, That’s third party library jar file that we try to wrap so we can call it from python. I don’t really know why they create a classes like that way. Would you able to add an option to just only wrap classes under a package like I want to wrap all public classes in package com.lchclearnet.* So any public classes under com.lchclearnet.swapclear and com.lchclearnet.common will get wrapped? At the moment I think JCC try to wrap all the public classes found in the jar if I pass in the jar via -jar option. I wonder why this isn't documented. JCC's __main__.py file lists all the options you can use with JCC. The one that doesn't seem listed is the non-option: if a command line argument doesn't start with '-', then it is assumed to be a class name. Better yet, you can also use a className:methodName syntax to only wrap that. There is a large example of a JCC invocation here: https://svn.apache.org/viewvc/lucene/pylucene/trunk/Makefile?view=mark up look for org.apache.lucene.index.IndexWriter:getReader, for an example. For controlling which
RE: AttributeError: 'bool' object has no attribute 'setdefault'
Hi Andi, I think I got it working but there is an issue with the class name with '.'. In the jar there are some class name like below public static final class SensitivityProfileIdList.Builder public static final class SRMBreakdown.Builder So JCC will wrap this can change the '.' to '$' SensitivityProfileIdList$Builder SRMBreakdown$Builder I cannot really use this classes in python and python flag it up as syntax error. Would it be better to use '_' instead of '$' to replace the '.' in the class name? Thanks, Chee Yong Chee Yong Teh 27 Bush Lane, London, EC4R 0AN | +44 203 929 3138 OTC Infrastructure Service of the Year & Global Compression Service of the Year -Original Message- From: Andi Vajda Sent: 06 May 2020 00:34 To: Chee Yong Teh Cc: pylucene-dev@lucene.apache.org Subject: Re: AttributeError: 'bool' object has no attribute 'setdefault' > On May 5, 2020, at 16:17, Chee Yong Teh wrote: > > > Hi Andi, > > Ok I have changed the command to > > python -m jcc --version 7.1.4 --use_full_names --include > /home/cheeyong.teh/SMART-API-7.1.4/smart/lib/smart-swapclear-public-release_daru.12. > jar --include > /home/cheeyong.teh/SMART-API-7.1.4/smart/lib/colt-1.2.0.jar --include > /home/cheeyong.teh/SMART-API-7.1.4/smart/lib/commons-math3-3.6.1.jar > --include /home/cheeyong .teh/SMART-API-7.1.4/smart/lib/jna-5.2.0.jar > --include > /home/cheeyong.teh/SMART-API-7.1.4/smart/lib/log4j-1.2.16.jar > --include /home/cheeyong.teh/SMART-API-7.1.4/smart/lib/proto > buf-java-3.5.1.jar --include > /home/cheeyong.teh/SMART-API-7.1.4/smart/lib/slf4j-api-1.6.1.jar > --include > /home/cheeyong.teh/SMART-API-7.1.4/smart/lib/slf4j-log4j12-1.6.1.jar > --py thon lch_smart --build --install > com.lchclearnet.swapclear.smart.SMARTClientDataProviderFactory > > I'm using --include instead of --jar and pass in > com.lchclearnet.swapclear.smart.SMARTClientDataProviderFactory as a > class I want to wrap. It seem fine and everything build fine but when > I do a print(dir(lch_smart)). It doesn't seem to wrap that > SMARTClientDataProviderFactory class > > >>> print(dir(lch_smart)) > ['CLASSPATH', 'ConstVariableDescriptor', 'FinalizerClass', > 'FinalizerProxy', 'InvalidArgsError', 'JArray', 'JArray_bool', > 'JArray_byte', 'JArray_char', 'JArray_double', 'JArray_float', > 'JArray_int', 'JArray_long', 'JArray_object', 'JArray_short', > 'JArray_string', 'JCCEnv', 'JCC_VERSION', 'JObject', 'JavaError', > 'PrintWriter', 'StringWriter', 'VERSION', '__builtins__', > '__cached__', '__doc__', '__file__', '__loader__', '__module_dir__', > '__name__', '__package__', '__path__', '__spec__', '_lch_smart', > 'findClass', 'getVMEnv', 'initVM', 'makeClass', 'makeInterface', 'os'] > >>> You're using --use_full_names, thus to access the wrapper for com.lchclearnet.swapclear.smart.SMARTClientDataProviderFactory you need to say: >>> from com.lchclearnet.swapclear.smart import SMARTClientDataProviderFactory Andi.. > > If I use --jar option I will still get the "AttributeError: 'bool' object has > no attribute 'setdefault'" error. > > Thanks, > > Chee Yong > > Chee Yong Teh > 27 Bush Lane, London, EC4R 0AN | +44 203 929 3138 > > OTC Infrastructure Service of the Year & Global Compression Service > of the Year -Original Message- > From: Andi Vajda > Sent: 05 May 2020 23:30 > To: Chee Yong Teh > Cc: pylucene-dev@lucene.apache.org > Subject: Re: AttributeError: 'bool' object has no attribute 'setdefault' > > > On Tue, 5 May 2020, Chee Yong Teh wrote: > > > Hi Andi, > > > > That’s third party library jar file that we try to wrap so we can call it > > from python. > > > > I don’t really know why they create a classes like that way. > > > > Would you able to add an option to just only wrap classes under a > > package like I want to wrap all public classes in package > > com.lchclearnet.* > > > > So any public classes under com.lchclearnet.swapclear and > > com.lchclearnet.common will get wrapped? At the moment I think JCC > > try to wrap all the public classes found in the jar if I pass in the > > jar via -jar option. > > I wonder why this isn't documented. > JCC's __main__.py file lists all the options you can use with JCC. > The one that doesn't seem listed is the non-option: > if a command line argument doesn't start with '-', then it is assumed > to be a class name. Better yet, you can also use a > className:methodName syntax to only wrap that. There is a large > example of a JCC invocation > here: > https://svn.apache.org/viewvc/lucene/pylucene/trunk/Makefile?view=mark > up look for org.apache.lucene.index.IndexWriter:getReader, for an > example. > For controlling which dependencies are pulled in, the answer is none unless > you declare them via --jar, other classes, or --package. > > In other words, depending on your use case, you may be able to just generate > wrappers for the actual entrypoints you wish to call from Python and the >