1

Is there any way to call an installed python egg from python code? I need to cal a sphinx documentation generator from within a python code, and currently i'm doing it like this:

os.system( "sphinx-build.exe -b html c:\\src c:\\dst" )

This works, but requires some additional configuration: 'scripts' folder inside a python installation folder need to be added to a system PATH ( i'm on Windows ). Is it any better, native way to call an installed python egg?

Jonathan Livni
108k112 gold badges278 silver badges367 bronze badges
asked Apr 22, 2009 at 5:55

2 Answers 2

3

So basically, you want to use Sphinx as a library?

Here is what sphinx-build does:

from pkg_resources import load_entry_point
load_entry_point('Sphinx==0.5.1', 'console_scripts', 'sphinx-build')()

Looking at entry-points.txt in the EGG-INFO directory, notice that the sphinx-build entry point is the sphinx.main function (located in __init__.py).

Have a look at that and duplicate what it does, and you can use sphinx as a library. I have not looked at the code in detail, but it seems that the bulk of the sphinx-build-command is done by the build method on a Sphinx object.

In your code, you would have to do something like:

from sphinx.application import Sphinx
s = Sphinx(...)
s.build(...)

You need to have a look at the Sphinx source code to figure out the parameters to Sphinx.__init__() and Sphinx.build()

answered Apr 22, 2009 at 9:47
Sign up to request clarification or add additional context in comments.

Comments

1

Adding the egg to PYTHONPATH or to sys.path will allow you to access the modules and packages within.

answered Apr 22, 2009 at 6:16

1 Comment

-1: No reference to the documentation: docs.python.org/tutorial/modules.html

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.