[Distutils] uses for setup.cfg and extracting data from it
Ben Finney
ben+python at benfinney.id.au
Thu Sep 17 02:07:55 CEST 2009
"P.J. Eby" <pje at telecommunity.com> writes:
> http://docs.python.org/distutils/apiref.html#module-distutils.core -
> specifically the run_setup() function. (It appears the docs do not
> have link anchors for individual functions, alas.)
<URL:http://docs.python.org/distutils/apiref.html#distutils.core.run_setup>
Sphinx (the system creating the documentation you see there) makes
anchors available for all the headings and functions etc., but hides the
links to them by default. When hovering on the heading for the function,
a “¶” (U+00B6 PILCROW SIGN) appears, and that character is contained
within an anchor to the heading.
> distutils.core.run_setup("setup.py", [], "init") will return you an
> initialized Distribution object from running the setup script, without
> parsing any configuration files or executing any commands.
[…]
Thank you.
It's not working for me, though: my ‘setup.py’ does some processing to
generate the arguments for the ‘setup()’ call, and imports some standard
library modules::
===== setup.py
[…]
import textwrap
from setuptools import setup, find_packages
main_module_name = 'daemon'
main_module = __import__(main_module_name, fromlist=['version'])
version = main_module.version
short_description, long_description = (
textwrap.dedent(d).strip()
for d in main_module.__doc__.split(u'\n\n', 1)
)
setup(
name = "python-daemon",
version = version.version,
packages = find_packages(exclude=["test"]),
[…]
=====
(The full distribution I'm using to try this can be found at
<URL:http://pypi.python.org/packages/source/p/python-daemon/python-daemon-1.4.7.tar.gz>
if you want to follow along at home.)
When I try to use the ‘run_setup’ function to extract a Distribution
object, it's failing::
>>> import distutils.core
>>> dist = distutils.core.run_setup("setup.py", stop_after='init')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.5/distutils/core.py", line 220, in run_setup
execfile(script_name, g, l)
File "setup.py", line 23, in <module>
for d in main_module.__doc__.split(u'\n\n', 1)
File "setup.py", line 23, in <genexpr>
for d in main_module.__doc__.split(u'\n\n', 1)
NameError: global name 'textwrap' is not defined
> This will work with a sufficiently well-behaved setup.py; setup
> scripts that try to do build or install steps outside of any distutils
> command may produce side-effects when run.
Well, this ‘setup.py’ is fairly simple, and doesn't do any build or
install steps; it's merely trying to do some internal processing to
generate the arguments for ‘setup()’.
--
\ “If you go flying back through time and you see somebody else |
`\ flying forward into the future, it's probably best to avoid eye |
_o__) contact.” —Jack Handey |
Ben Finney
More information about the Distutils-SIG
mailing list