diff --git a/src/setup.py b/src/setup.py index 194b8dd..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,9 +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=[pkgname, pkgname + ".test"], + packages=findPackages(), package_data={pkgname: ['LICENSE']}, version=version, description="A Cygwin command line package management tool.",