From 6bf80a0d68883804c3f0d715517914f2b0039621 Mon Sep 17 00:00:00 2001 From: alquerci Date: Fri, 12 Sep 2014 16:19:31 +0200 Subject: [PATCH] Added a way to keep the package list synchronized with the srcdir --- src/setup.py | 52 +++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 45 insertions(+), 7 deletions(-) diff --git a/src/setup.py b/src/setup.py index cd1ff7b..9a9786d 100644 --- a/src/setup.py +++ b/src/setup.py @@ -16,6 +16,7 @@ from distutils.core import setup; import os; +import re; realpathfile = os.path.realpath(os.path.dirname(__file__)); realpathcwd = os.path.realpath(os.getcwd()); @@ -37,15 +38,52 @@ long_description = f.read(); f.close(); +def findPackages(srcdir='.'): + """Finds all regular package under the srcdir directory. + + A regular package must have a valid name and a parent package + with an exception when its parent directory is srcdir. Moreover + the srcdir cannot be a package. + + @param srcdir: str Find out under this directory + + @return: list A list of fully qualified package name + """ + assert isinstance(srcdir, str); + + packages = list(); + + for dirpath, dirnames, filenames in os.walk(srcdir, followlinks=False) : + # srcdir cannot be a package + if srcdir == dirpath : + continue; + + # check whether dirpath is a directory of regular package + isRegularPackage = False; + parentdir = dirpath; + while not srcdir == parentdir : + if ( + not re.match(r'^\w+$', os.path.basename(parentdir)) + or not os.path.isfile(os.path.join(parentdir, '__init__.py')) + ) : + break; + + parentdir = os.path.dirname(parentdir); + if srcdir == parentdir : + isRegularPackage = True; + + if not isRegularPackage : + continue; + + # dirpath is a directory of regular package, proceed + packageName = os.path.relpath(dirpath, srcdir).replace(os.path.sep, '.'); + packages.append(packageName); + + return packages; + setup( name=pkgname, - packages=[ - 'cygapt', - 'cygapt.test', - 'cygapt.test.case', - 'cygapt.test.case.py2', - 'cygapt.test.case.py2.minor6', - ], + packages=findPackages(), package_data={pkgname: ['LICENSE']}, version=version, description="A Cygwin command line package management tool.",