Bug#945391: asciidocapi: fails with AttributeError: 'NoneType' object has no attribute 'loader'

2019-11-24 Thread Joseph Herlant
Control: forwarded -1 https://github.com/asciidoc/asciidoc-py3/pull/86

Hi Simon,

Thanks a lot for the report!
I was able to reproduce the bug you described and I can confirm that
your patch works as expected.
Thanks a lot for that! :)

I forwarded your patch to the upstream repo:
https://github.com/asciidoc/asciidoc-py3/pull/86
I'll give them a few days for comments and style changes if they have
any and will release the new version after that.

Thanks again,
Joseph



Bug#945391: asciidocapi: fails with AttributeError: 'NoneType' object has no attribute 'loader'

2019-11-23 Thread Simon Ruderich
Package: asciidoc
Version: 8.6.10+git20190307.51d7c14-1
Severity: normal
Tags: patch

Hello,

using asciidocapi with the following small script (also attached)

#!/usr/bin/python3

import io
import sys

sys.path.append('/usr/share/asciidoc')
import asciidocapi


infile = io.StringIO('Test')
outfile = io.StringIO()

adoc = asciidocapi.AsciiDocAPI()
adoc.execute(infile, outfile)

results in an exception:

Traceback (most recent call last):
File "./test", line 13, in 
adoc = asciidocapi.AsciiDocAPI()
File "/usr/share/asciidoc/asciidocapi.py", line 209, in __init__
self.__import_asciidoc()
File "/usr/share/asciidoc/asciidocapi.py", line 244, in __import_asciidoc
module = importlib.util.module_from_spec(spec)
File "", line 580, in module_from_spec
AttributeError: 'NoneType' object has no attribute 'loader'

The attached patch fixes this issue (tested with python3.7 and
python3.8).

Regards
Simon
-- 
+ privacy is necessary
+ using gnupg http://gnupg.org
+ public key id: 0x92FEFDB7E44C32F9
#!/usr/bin/python3

import io
import sys

sys.path.append('/usr/share/asciidoc')
import asciidocapi


infile = io.StringIO('Test')
outfile = io.StringIO()

adoc = asciidocapi.AsciiDocAPI()
adoc.execute(infile, outfile)
--- /usr/share/asciidoc/asciidocapi.py.orig	2019-11-19 08:27:07.987333977 +0100
+++ /usr/share/asciidoc/asciidocapi.py	2019-11-24 08:23:19.141730508 +0100
@@ -239,9 +239,13 @@
 import imp
 module = imp.load_source('asciidoc', self.cmd)
 else:
-import importlib.util
-spec = importlib.util.spec_from_file_location('asciidoc', self.cmd)
-module = importlib.util.module_from_spec(spec)
+# Thanks to Mad Physicist for this solution, read on 2019-11-19
+# https://stackoverflow.com/questions/2601047/import-a-python-module-without-the-py-extension/43602645#43602645
+from importlib.util import spec_from_loader, module_from_spec
+from importlib.machinery import SourceFileLoader
+loader = SourceFileLoader('asciidoc', self.cmd)
+spec = spec_from_loader('asciidoc', loader)
+module = module_from_spec(spec)
 spec.loader.exec_module(module)
 self.asciidoc = module
 except ImportError:


signature.asc
Description: PGP signature