Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is rst2pdf intended to be used as a python module? #1116

Open
liquidsigma opened this issue Jan 10, 2023 · 2 comments
Open

Is rst2pdf intended to be used as a python module? #1116

liquidsigma opened this issue Jan 10, 2023 · 2 comments

Comments

@liquidsigma
Copy link

Description of problem
I have successfully imported rst2pdf as module and called the main() function.
But I am not sure if rst2pdf is supposed to be used in such a way, since it calls sys.exit(). I can catch the respective exception by:

import rst2pdf.createpdf
try:
    rst2pdf.createpdf.main(["input.rst","output.pdf"])
except SystemExit:
    pass

Will my work around also work in future versions of rst2pdf?
Or is it the intention of rst2pdf to be solely used on the command line via rst2pdf.exe?

Using rst2pdf via import, and the code shown above, enables me to easily bundle my app using Pyinstaller.

🖥 Versions

python -V
Python 3.10.3

pip freeze | grep rst2pdf
rst2pdf==0.99

pip freeze | grep reportlab
reportlab==3.6.12

Which operating system are you using?
Windows 10

@akrabat
Copy link
Member

akrabat commented Jan 10, 2023

Hey @liquidsigma, I've never used it like that as I only use it from the command line. However, I'm keen to support your use-case as best we can. We're not planning on changing anything related to sys.exit() calls at the moment, but is there a reasonably simple change that we could make that would help make your use-case easier? I'm happy to accept a PR that supports using rst2pdf as a python module more easily as long as it doesn't break the cli usage.

@liquidsigma
Copy link
Author

liquidsigma commented Jan 11, 2023

Thanks @akrabat for the fast response!
Actually I'm quite happy with rst2pdf as it is, since I can capture the exception raised by sys.exit() and based on the return_code decide what to do in my app. Maybe a code snippet in the documentation regarding the use of rst2pdf as module would already be enough for most users:

import rst2pdf.createpdf
try:
    rst2pdf.createpdf.main(["input.rst","output.pdf"])   # on regular exit this calls sys.exit() with return code 0
except SystemExit as e:
    if e.code == 0:
        pass    # rst2pdf completed without any errors
    else:
        pass    # rst2pdf completed with error(s)

@lornajane lornajane self-assigned this Apr 23, 2023
@lornajane lornajane removed their assignment Apr 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants