Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a way to keep the package list synchronized with the srcdir #57

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 45 additions & 7 deletions 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,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.",
Expand Down