summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpje <pje@571e12c6-e1fa-0310-aee7-ff1267fa46bd>2004-02-29 22:57:31 +0000
committerpje <pje@571e12c6-e1fa-0310-aee7-ff1267fa46bd>2004-02-29 22:57:31 +0000
commit84c2788dde09448c3fdf860b5aadc67845c5b19e (patch)
treef009766df4fb37397e6b99cc392a070c66b1076e
parentc078da1dbdd72f3a64fffd2eacfc5000e9be66a5 (diff)
downloadwsgiref-84c2788dde09448c3fdf860b5aadc67845c5b19e.tar.gz
Initial skeleton of 'setuptools' package, for installing dependencies, etc.
Cleaned up data file installation handling: we now just set extensions, and all data files contained in packages are installed automatically. Additional wildcards or filenames can be defined on a per-package basis. Also, fixed some broken installation bits for ZConfig. git-svn-id: svn://svn.eby-sarna.com/svnroot/wsgiref@231 571e12c6-e1fa-0310-aee7-ff1267fa46bd
-rw-r--r--setuptools/__init__.py12
-rw-r--r--setuptools/command/__init__.py11
-rw-r--r--setuptools/command/build_py.py96
-rw-r--r--setuptools/command/test.py44
-rw-r--r--setuptools/dist.py24
5 files changed, 187 insertions, 0 deletions
diff --git a/setuptools/__init__.py b/setuptools/__init__.py
new file mode 100644
index 0000000..f477a6e
--- /dev/null
+++ b/setuptools/__init__.py
@@ -0,0 +1,12 @@
+import distutils.core, setuptools.command
+
+# XXX from deps import Dependency, Distro
+
+__all__ = ['setup', ] # XXX Dependency, Distro
+
+
+def setup(**attrs):
+ from setuptools.dist import Distribution
+ attrs.setdefault("distclass",Distribution)
+ return distutils.core.setup(**attrs)
+
diff --git a/setuptools/command/__init__.py b/setuptools/command/__init__.py
new file mode 100644
index 0000000..a7e3c3d
--- /dev/null
+++ b/setuptools/command/__init__.py
@@ -0,0 +1,11 @@
+import distutils.command
+
+__all__ = [] # XXX 'happy', 'test', 'install_pkg_data'
+
+
+# Make our commands available as though they were part of the distutils
+
+distutils.command.__path__.extend(__path__)
+distutils.command.__all__.extend(
+ [cmd for cmd in __all__ if cmd not in distutils.command.__all__]
+)
diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py
new file mode 100644
index 0000000..cff9bcb
--- /dev/null
+++ b/setuptools/command/build_py.py
@@ -0,0 +1,96 @@
+from distutils.command.build_py import build_py as _build_py
+from distutils.util import convert_path
+from glob import glob
+import os.path
+
+class build_py(_build_py):
+
+ def initialize_options(self):
+ _build_py.initialize_options(self)
+ self.package_data = self.distribution.package_data
+
+ def run(self):
+ if not self.py_modules and not self.packages:
+ return
+
+ if self.py_modules:
+ self.build_modules()
+
+ if self.packages:
+ self.build_packages()
+ self.build_package_data()
+
+ self.byte_compile(_build_py.get_outputs(self,include_bytecode=0))
+
+ def build_package_data(self):
+ lastdir = None
+ for package, package_dir, outdir, files in self.get_package_data():
+ for file in files:
+ outfile = os.path.join(outdir,file)
+ self.mkpath(os.path.dirname(outfile))
+ self.copy_file(
+ os.path.join(package_dir,file), outfile
+ )
+
+ def get_outputs(self, include_bytecode=1):
+ return _build_py.get_outputs(include_bytecode) + [
+ os.path.join(outdir,file)
+ for package,package_dir,outdir,files in self.get_package_data()
+ for file in files
+ ]
+
+ def get_package_data(self):
+ data = []
+ for package in self.packages:
+ package_dir = self.get_package_dir(package)
+ outdir = os.path.join(
+ *([self.build_lib]+package.split('.'))
+ )
+ plen = len(package_dir)+1
+ files = [
+ file[plen:] for file in self.find_package_files(
+ package, package_dir
+ )
+ ]
+ data.append( (package, package_dir, outdir, files) )
+ return data
+
+ def find_package_files(self, package, package_dir):
+
+ globs = self.package_data.get('',[])+self.package_data.get(package,[])
+
+ files = []
+
+ for pattern in globs:
+ files.extend(
+ glob(os.path.join(package_dir, convert_path(pattern)))
+ )
+
+ return files
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/setuptools/command/test.py b/setuptools/command/test.py
new file mode 100644
index 0000000..62be491
--- /dev/null
+++ b/setuptools/command/test.py
@@ -0,0 +1,44 @@
+from distutils.cmd import Command
+import sys
+
+class test(Command):
+
+ """Command to run unit tests after installation"""
+
+ description = "Run unit tests after installation"
+
+ user_options = [
+ ('test-module=','m','Module to run tests from'),
+ ]
+
+ def initialize_options(self):
+ self.test_module = None
+
+ def finalize_options(self):
+
+ if self.test_module is None:
+ self.test_module = self.distribution.test_module
+
+ self.test_args = [self.test_module+'.test_suite']
+
+ if self.verbose:
+ self.test_args.insert(0,'--verbose')
+
+ def run(self):
+
+ # Install before testing
+ self.run_command('install')
+
+ if not self.dry_run:
+ import unittest
+ unittest.main(None, None, [unittest.__file__]+self.test_args)
+
+
+
+
+
+
+
+
+
+
diff --git a/setuptools/dist.py b/setuptools/dist.py
new file mode 100644
index 0000000..d128288
--- /dev/null
+++ b/setuptools/dist.py
@@ -0,0 +1,24 @@
+from distutils.core import Distribution as _Distribution
+
+from setuptools.command.build_py import build_py
+
+class Distribution(_Distribution):
+
+ # 'get_dependencies' command
+ requires = ()
+
+ # 'test' command
+ test_module = None
+
+ # 'install_pkg_data' command
+ package_data = ()
+
+
+ def __init__ (self, attrs=None):
+ _Distribution.__init__(self,attrs)
+ self.cmdclass.setdefault('build_py',build_py)
+ # XXX self.cmdclass.setdefault('build',build)
+
+ def has_pkg_data(self):
+ return self.package_data
+