Skip to content

Commit

Permalink
Added a way to keep the package list synchronized with the srcdir
Browse files Browse the repository at this point in the history
  • Loading branch information
alquerci committed Sep 16, 2014
1 parent e234a21 commit 687a2a4
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion src/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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.",
Expand Down

0 comments on commit 687a2a4

Please sign in to comment.