Re: uses for setup.cfg and extracting data from it

2009-09-16 Thread Ben Finney
P.J. Eby p...@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

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Distutils] uses for setup.cfg and extracting data from it

2009-09-11 Thread P.J. Eby

At 08:14 AM 9/12/2009 +1000, Ben Finney wrote:
Specifically, I want to programmatically access the metadata that is 
held in the arguments to the ‘distutils.setup()’ call. Without, 
as you say, executing any Distutils command. I am not aware of any 
‘distutils’ public functions that can do that, and reading 
URL:http://docs.python.org/distutils/ again doesn't enlighten me. 
Would you be more specific about what these functions are?


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.)


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.  You could use config or commandline instead of init 
if you wanted those pieces of processing to be done as well - i.e. if 
you wanted to be sure any setup.cfg options were processed.


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.  (Which is why 
setuptools always runs setup scripts in a loose sandbox that detects 
when a script tries to modify the filesystem outside the setup directory.)


--
http://mail.python.org/mailman/listinfo/python-list


uses for setup.cfg and extracting data from it

2009-09-09 Thread Chris Withers

Hi All,

Do people generally source control their package's setup.cfg?

http://docs.python.org/distutils/configfile.html sort of implies it 
should be editable by the person installing the package, but I've never 
personally used a package where that's the case...


Assuming the distutils docs are out of date and this file is really 
owned by the package maintainer, how do I extract information from it 
in setup.py (and elsewhere for that matter!)


I'm looking for somewhere consistent to store the following for all my 
packages:


- mailing lists url

- issue tracker url

- change log url

- documentation url

...such that I can generate a sensible long_description for use on PyPI 
but also such that I can include the information in the Sphinx docs...


cheers,

Chris

--
Simplistix - Content Management, Batch Processing  Python Consulting
   - http://www.simplistix.co.uk
--
http://mail.python.org/mailman/listinfo/python-list


Re: uses for setup.cfg and extracting data from it

2009-09-09 Thread Ben Finney
Chris Withers ch...@simplistix.co.uk writes:

 Do people generally source control their package's setup.cfg?

Yes. I prefer the distribution metadata to be declarative, for the
reasons you touch on later in your message. So where it makes sense I
store it in ‘setup.cfg’ or some other declarative file, and put it under
VCS like any other file needed for generating the distribution.

 http://docs.python.org/distutils/configfile.html sort of implies it
 should be editable by the person installing the package

Yes, that's part of its purpose: to allow customisation of the various
actions of distutils.

 but I've never personally used a package where that's the case...

I don't understand. When you, as the person installing the distribution,
get the sdist for that distribution, you can edit (or create, if it
didn't exist) the ‘setup.cfg’. What's stopping you from doing so?

 Assuming the distutils docs are out of date and this file is really
 owned by the package maintainer

If the distribution maintainer generates and distributes sdist files,
then they can “own” the ‘setup.cfg’ file without hindering the
recipient's customisation of the same file at installation time.

 how do I extract information from it in setup.py (and elsewhere for
 that matter!)

That's one of the pain points of the current distutils capability:
there's no standard-library way to extract that information. Various
efforts are under way to try to change that, but the legacy of existing
distributions is heavy and long.

You'll probably be interested in the discussions currently ongoing in
the Distutils SIG, regarding how to get the distribution metadata so
it's stored declaratively to make it easier to extract.

-- 
 \ “I have yet to see any problem, however complicated, which, |
  `\  when you looked at it in the right way, did not become still |
_o__)more complicated.” —Paul Anderson |
Ben Finney

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Distutils] uses for setup.cfg and extracting data from it

2009-09-09 Thread P.J. Eby

At 11:25 PM 9/9/2009 +1000, Ben Finney wrote:
That's one of the pain points of the current distutils capability: 
there's no standard-library way to extract that information.


If you're talking about setup.cfg (and all the other distutils .cfg 
files), all you need to do is create a Distribution object and call 
parse_config_files() on it, then access the appropriate 
attributes.  Take you maybe 3 or 4 lines of code.


If you're talking about setup.py, all you need to do is use the 
distutils functions that allow you to run a setup.py without 
executing any of its commands.  (Of course, you then need to be able 
to deal with badly-behaved setup scripts, and it's true there's no 
stdlib support for that.)


--
http://mail.python.org/mailman/listinfo/python-list