hwmaier / asciidoc-ditaa-filter

ditaa filter for AsciiDoc
7 stars 6 forks source link

Modified to run in Python3 #3

Closed fgrebenicek closed 5 months ago

fgrebenicek commented 5 months ago
hwmaier commented 5 months ago

Thank you for the PR. Unfortunately your PR breaks compatibility of the tool with Python 2 which I like to still maintain. The temp file management needs changes (line 105/106) to work with Python 2.

hwmaier commented 5 months ago

Doing some tests it appears that Python 3 needs these lines 105/106:

            if isinstance(source,str):
                source = bytes(source, "utf8")

while for Python 2 those two lines need to be removed.

hwmaier commented 5 months ago

This simple test:

echo "123" | c:\Python27\python.exe ditaa2img.py -o test.png -

results in this strange error: ditaa2img.py: [Error 32] The process cannot access the file because it is being used by another process: 'c:\\users\\user\\appdata\\local\\temp\\tmpx9mbqm'

hwmaier commented 5 months ago

I think I found a solution which works for both Python versions.

Can you please test by replacing lines 100-110 with this:

            if self.infile == '-':
                source = sys.stdin.read()
                with tempfile.NamedTemporaryFile(mode='w', delete=False) as temp:
                    infile = temp.name
                    print_verbose("Temporary input file is %s" % infile)
                    temp.write(source)
            else:
                infile = self.infile
fgrebenicek commented 5 months ago

Hello @hwmaier, I have finally implemented your proposal and it seems to work for me on my Debian 10:

It also seems to work on Ubuntu 22.04.3 LTS with