[Distutils] Using code from a dependency in setup.py

George V. Reilly george at reilly.org
Thu May 30 02:40:02 CEST 2013


Actually, Bread's setup is fine; it's not doing anything interesting.
It's Jam's setup that's the problem.

Robert's mention of `setup_requires` led me to
http://stackoverflow.com/a/12061891/6364, which gave me the hint
I needed: create a separate `Distribution` object before calling `setup`
which defines the `setup_requires` entries.

Jam's `setup.py` now looks like:

from setuptools import setup, dist

dist.Distribution(dict(setup_requires='Bread'))

from bread.setup_topping import *

setup(
name='Jam',
version='0.2',
long_description=open('README.md').read(),
**topping_setup_options
)

# Remove *.egg left by bootstrapping Bread
cleanup_bread_bootstrap()

And `bread/setup_topping.py` looks like:

from setuptools.command.bdist_egg import bdist_egg as _bdist_egg
import os, fnmatch, glob, shutil

def recursive_data_files(treeroot, pattern):
results = []
for base, dirs, files in os.walk(treeroot):
goodfiles = fnmatch.filter(files, pattern)
if goodfiles:
results.append((base, [os.path.join(base, f) for f in goodfiles]))
return results

def make_data_files(output='output'):
return (
[('', ['bread.yaml'])]
+ recursive_data_files(output, '*')
)

class bdist_egg(_bdist_egg):
def initialize_options(self):
bake_bread()    # build files to './output'
self.distribution.data_files = make_data_files()
_bdist_egg.initialize_options(self)

topping_setup_options = dict(
cmdclass={
'bdist_egg': bdist_egg,
},
install_requires=[
'Bread',
],
zip_safe=False,
)

def cleanup_bread_bootstrap(root='.'):
for f in glob.glob(os.path.join(os.path.abspath(root), '*.egg')):
if os.path.isdir(f):
shutil.rmtree(f)  # Egg directory
else:
os.remove(f)      # Zipped Egg



On Wed, May 29, 2013 at 2:48 PM, zooko <zooko at zooko.com> wrote:

> Here is my explanation of why it can be problematic if you import Bread in
> Bread's setup.py:
>
> https://bugs.launchpad.net/nevow/+bug/812537/comments/3
>
> If you do want to import dependencies of Bread in Bread's setup.py, and if
> your
> build tool (e.g. setuptools) supports it, then you could add the
> dependencies
> to the "setup_requires" list.
>
> If possible, maybe you could move some of this work from setup.py-time
> (whether
> build-time or install-time) to "first time I run" or a custom "initialize
> me
> now" command of Bread. I think setup.py is a sub-optimal place to do stuff,
> because there are a lot of complicated things going then and there, and
> because
> it is very inconvenient to write unit tests of setup.py behavior.
>
> Regards,
>
> Zooko
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/distutils-sig/attachments/20130529/d1c84a0c/attachment.html>


More information about the Distutils-SIG mailing list