[merge] setup.py should find the packages automatically

Alexander Belchenko bialix at ukr.net
Thu Aug 17 10:09:18 BST 2006


John Arbash Meinel пишет:
> Attached is a bundle which automatically finds all packages underneath
> 'bzrlib' and adds them as packages to be installed.
> 
> There is a second bundle which removes urlgrabber from 'bzrlib/util'
> since we don't actually use it, and we don't want to install something
> we aren't using. (We have no code that references it at present).
> 
> I think of them as going together, but we can approve one without the other.
> 
> I actually forgot how nice bundles are for removing lots of files, since
> they don't have to include the reverse patch :)

John, I'm +1 in concept. But your implementation is not working:

$ python setup.py build
Traceback (most recent call last):
   File "D:\user\MyCode\bzr\sandbox\fix-setup-py\setup.py", line 26, in ?
     BZRLIB = {'packages':get_bzrlib_packages()}
NameError: name 'get_bzrlib_packages' is not defined

This also catched by test_setup test. Run:

python bzr selftest test_setup

and you'll see ;-)

Function *should be* defined prior to use. Need to rework your patch.
I'm -1 on current patch.

I'm also -1 on making function definition on top of setup.py because I
specially move all setup-related meta info to the top of file to easy
search, read and edit when necessary. May be move this function to
bzrlib/__init__.py?

> # Bazaar revision bundle v0.8
> #
> # message:
> #   Change setup.py to auto-generate the list of packages to install
> # committer: John Arbash Meinel <john at arbash-meinel.com>
> # date: Wed 2006-08-16 10:09:39.786999941 -0500
> 
> === modified file setup.py
> --- setup.py
> +++ setup.py
...
> +BZRLIB = {'packages':get_bzrlib_packages()}
>  
>  PKG_DATA = {# install files from selftest suite
>              'package_data': {'bzrlib': ['doc/api/*.txt',
> @@ -63,9 +35,6 @@
>  # Reinvocation stolen from bzr, we need python2.4 by virtue of bzr_man
>  # including bzrlib.help
>  
> -import os
> -import sys
> -
>  try:
>      version_info = sys.version_info
>  except AttributeError:
> @@ -91,6 +60,27 @@
>      os.unsetenv(REINVOKE)
>  
>  
> +def get_bzrlib_packages():
> +    """Recurse through the bzrlib directory, and extract the package names"""
> +
> +    packages = []
> +    base_path = os.path.dirname(os.path.abspath(bzrlib.__file__))
> +    for root, dirs, files in os.walk(base_path):
> +        if '__init__.py' in files:
> +            assert root.startswith(base_path)
> +            # Get just the path below bzrlib
> +            package_path = root[len(base_path):]
> +            # Remove leading and trailing slashes
> +            package_path = package_path.strip('\\/')
> +            if not package_path:
> +                package_name = 'bzrlib'
> +            else:
> +                package_name = ('bzrlib.' +
> +                            package_path.replace('/', '.').replace('\\', '.'))
> +            packages.append(package_name)
> +    return sorted(packages)
> +
> +

--
Alexander






More information about the bazaar mailing list