deeplook / svglib

Read SVG files and convert them to other formats.
GNU Lesser General Public License v3.0
311 stars 80 forks source link

Since the 1.2.0 release the "svg2pdf" script doesn't work anymore #313

Closed knobix closed 2 years ago

knobix commented 2 years ago

Hi,

with the 1.2.0 release the included script svg2pdf has issues upon invocation (Python 3.8):

Traceback (most recent call last):
  File "/usr/local/bin/svg2pdf", line 33, in <module>
    sys.exit(load_entry_point('svglib==1.2.0', 'console_scripts', 'svg2pdf')())
  File "/usr/local/bin/svg2pdf", line 25, in importlib_load_entry_point
    return next(matches).load()
  File "/usr/local/lib/python3.8/importlib/metadata.py", line 77, in load
    module = import_module(match.group('module'))
  File "/usr/local/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'svglib.svg2pdf'

If the script in scripts/svg2pdf is copied to svglib/svg2pdf.py before build/installation the console script runs as expected.

Please let me know if you need further info.

github-actions[bot] commented 2 years ago

Thank you for raising your first issue! Your help to improve svglib is much appreciated!

claudep commented 2 years ago

I don't see any related change recently in source code.

knobix commented 2 years ago

I'm able to reproduce it within a fresh virtualenv:

$ python3.8 -m virtualenv venv
$ . venv/bin/activate
(venv) $ cd venv/
(venv) $ pip install svglib
Collecting svglib
[...] 
Successfully built svglib
Installing collected packages: webencodings, tinycss2, cssselect2, lxml, pillow, reportlab, svglib
Successfully installed cssselect2-0.4.1 lxml-4.7.1 pillow-9.0.0 reportlab-3.6.6 svglib-1.2.0 tinycss2-1.1.1 webencodings-0.5.1

If I try to run svg2pdf it fails although with lesser lines of backtrace info:

(venv) $ svg2pdf
Traceback (most recent call last):
  File "/home/knobix/venv/bin/svg2pdf", line 5, in <module>
    from svglib.svg2pdf import _main
ModuleNotFoundError: No module named 'svglib.svg2pdf'

The location of the svg2pdf script:

(venv) $ which svg2pdf
/home/knobix/venv/bin/svg2pdf

The file contents of the script:

(venv) cat bin/svg2pdf
#!/home/knobix/venv/bin/python
# -*- coding: utf-8 -*-
import re
import sys
from svglib.svg2pdf import _main
if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    sys.exit(_main())

If use pip install svglib==1.1.0 instead the script located at bin/svg2pdf works as expected. Its content is also the same as in scripts/svg2pdf of this repository.

claudep commented 2 years ago

Thanks a lot for the details. Until now, I guess the most probable offender is commit 15da63475. @victorbnl, would you be able to participate in searching what's wrong with 1.2.0? Typically, when comparing the installed trees, I can see a new entry_points.txt file in .dist-info directory. So maybe the issue is with the conversion of the previous scripts=['scripts/svg2pdf'], line in setup.py to the new console_scripts = svg2pdf = svglib.svg2pdf:_main of setup.cfg.

claudep commented 2 years ago

https://python-packaging.readthedocs.io/en/latest/command-line-scripts.html gives explanations about the difference between scripts and console_scripts.

claudep commented 2 years ago

If I understand it, moving from scripts to console_scripts is not just changing setup things, but also moving the scripts/svg2pdf content into the main source tree. For now, I guess it would be safer to revert that change and maybe do that move later for 1.3.0.

claudep commented 2 years ago

Just released 1.2.1. Hopefully your issue is gone now.

knobix commented 2 years ago

Just released 1.2.1. Hopefully your issue is gone now.

Indeed, I can confirm that the issue is gone now. Many thanks for the quick resolution!