On 14/01/13 07:15, Daniel Martinez wrote:
> Hi Stuart,
> 
> Thanks for your quick response. You were right at pointing out that the
> problem occured in documents which used asciidoc styles in some table
> columns, like the ones I was trying to compile. I found out that you can
> set the sys.executable property just by
> setting -Dpython.executable=/usr/bin/python JVM property. I did and it
> worked, although the workaround has now native python dependency, which
> I tried to avoid but it is ok for the time being.
> I'm a complete newbie with python but a quick look at the source code
> (asciiidoc.py) showed me that some process forking is being done for
> filter application, even in case the filter is asciidoc itself (which is
> the case for asciidoc styled columns):
> 
>         p = subprocess.Popen(filter_cmd, shell=True,
>                 stdin=subprocess.PIPE, stdout=subprocess.PIPE)
> 
> Wouldn't it be possible to avoid the call to subprocess.Popen(...) in
> this case and use just a recursive call to asciidoc.py instead? or isn't
> it reentrant and cannot be called this way?

Hi Daniel, unfortunately asciidoc is not reentrant, which is why it
doesn't simply call the asciidoc() function, it would take a complete
rewrite to make it reentrant. But this still would not solve the problem
of running filters which are all native executables.

Cheers, Stuart


> 
> Thanks a lot,
> Daniel
> 
> El domingo, 13 de enero de 2013 04:11:08 UTC+1, Stuart Rackham escribió:
> 
> 
> 
>     On 13/01/13 12:03, Daniel Martinez wrote:
>     > Hi,
>     >
>     > I'm trying to come up with a way of executing asciidoc from java
>     without
>     > any native dependency, not even the asciidoc installation.
>     Actually, I
>     > found that embedding the asciidoc directory as a resource in the java
>     > project allows me to import it from jython with no problem at all
>     and it
>     > seems to work with a few asciidoc documents I tried, using
>     AsciiDocAPI
>     > as suggested in the documentation. Nevertheless it is also quite
>     common
>     > for it to fail with well formed documents that are processed
>     flawlessly
>     > using native python... I also tried to remove the asciidoc code
>     from the
>     > java jar and set up jython syspath to point to the asciidoc
>     installation
>     > and got the same errors. Has anyone succeeded in making asciidoc work
>     > with jython-standalone library?
>     >
>     > I'm using JDK1.6-31 in Fedora 16 with jython-standalone 2.5.3.
>     Asciidoc
>     > version is 8.6.8
>     >
>     > As an example, the following java program tries to process the
>     official
>     > doc (asciidoc.txt) and fails with the error below:
>     >
>     > import org.python.util.PythonInterpreter;
>     >
>     > public class AsciiDocTest {
>     >
>     > public static void main(String[] args) {
>     >   PythonInterpreter python = new PythonInterpreter();            
>          
>     >            python.exec("from asciidocapi import AsciiDocAPI");
>     >            python.exec("asciidoc = AsciiDocAPI()");
>     >            python.exec("asciidoc.execute('/tmp/asciidoc.txt')");
>     > }
>     > }
>     >
>     > *_Output_*
>     > Exception in thread "MainThread" Traceback (most recent call last):
>     >   File "<string>", line 1, in <module>
>     >   File "__pyclasspath__/asciidocapi$py.class", line 248, in execute
>     > asciidocapi.AsciiDocError: ERROR: asciidoc.txt: line 6023: undefined
>     > filter attribute in command: "{python}" "{asciidoc-file}" -b
>     {backend}
>     > {asciidoc-args}{lang? -a "lang={lang}@"}{icons? -a icons -a
>     > "iconsdir={iconsdir}"}{imagesdir? -a
>     "imagesdir={imagesdir}"}{data-uri?
>     > -a data-uri} -a "indir={indir}"{trace? -a
>     "trace={trace}"}{blockname? -a
>     > "blockname={blockname}"} -s -
> 
>     The Python executable attribute ({python}) is not being set.
> 
>     In asciidoc.py it is set when asciidoc() is executed with:
> 
>       document.attributes['python'] = sys.executable
> 
>     Jython returns None if the jython interpreter executable is not being
>     executed which means that source using filters written in Python or
>     containing tables with an 'asciidoc' column style won't work.
> 
>     If you compile using the Jython interpreter it will work e.g.
> 
>       jython asciidoc.py doc/asciidoc.txt
> 
>     I don't know Jython/Java well enough to figure out a workaround.
> 
> 
>     Cheers, Stuart
> 
> 
> 
> 
> 
>     >
>     > Thanks,
>     > Daniel
>     >
>     > --
>     > You received this message because you are subscribed to the Google
>     > Groups "asciidoc" group.
>     > To view this discussion on the web visit
>     > https://groups.google.com/d/msg/asciidoc/-/tIfQcQ8z5u8J
>     <https://groups.google.com/d/msg/asciidoc/-/tIfQcQ8z5u8J>.
>     > To post to this group, send email to [email protected]
>     <javascript:>.
>     > To unsubscribe from this group, send email to
>     > [email protected] <javascript:>.
>     > For more options, visit this group at
>     > http://groups.google.com/group/asciidoc?hl=en
>     <http://groups.google.com/group/asciidoc?hl=en>.
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "asciidoc" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/asciidoc/-/atwA19fRELAJ.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/asciidoc?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"asciidoc" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/asciidoc?hl=en.

Reply via email to