aboutsummaryrefslogtreecommitdiffstats
path: root/setuptools/command
diff options
context:
space:
mode:
authorPJ Eby <distutils-sig@python.org>2004-03-19 20:53:14 +0000
committerPJ Eby <distutils-sig@python.org>2004-03-19 20:53:14 +0000
commit8423e1ed14ac1691c2863c6e8cac9230cf558d7b (patch)
tree79f2d2cef146e08a9480357637cca4662307bd08 /setuptools/command
downloadexternal_python_setuptools-8423e1ed14ac1691c2863c6e8cac9230cf558d7b.tar.gz
external_python_setuptools-8423e1ed14ac1691c2863c6e8cac9230cf558d7b.tar.bz2
external_python_setuptools-8423e1ed14ac1691c2863c6e8cac9230cf558d7b.zip
Initial checkin of setuptools 0.0.1.
--HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4040869
Diffstat (limited to 'setuptools/command')
-rw-r--r--setuptools/command/__init__.py11
-rw-r--r--setuptools/command/build_ext.py7
-rw-r--r--setuptools/command/build_py.py123
-rw-r--r--setuptools/command/depends.py27
-rw-r--r--setuptools/command/install.py11
-rw-r--r--setuptools/command/install_lib.py17
-rw-r--r--setuptools/command/test.py82
7 files changed, 278 insertions, 0 deletions
diff --git a/setuptools/command/__init__.py b/setuptools/command/__init__.py
new file mode 100644
index 00000000..3429634c
--- /dev/null
+++ b/setuptools/command/__init__.py
@@ -0,0 +1,11 @@
+import distutils.command
+
+__all__ = ['test', 'depends']
+
+
+# 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_ext.py b/setuptools/command/build_ext.py
new file mode 100644
index 00000000..86ac13a9
--- /dev/null
+++ b/setuptools/command/build_ext.py
@@ -0,0 +1,7 @@
+# Attempt to use Pyrex for building extensions, if available
+
+try:
+ from Pyrex.Distutils.build_ext import build_ext
+except ImportError:
+ from distutils.command.build_ext import build_ext
+
diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py
new file mode 100644
index 00000000..7d5b6ffd
--- /dev/null
+++ b/setuptools/command/build_py.py
@@ -0,0 +1,123 @@
+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):
+
+ """Enhanced 'build_py' command that includes data files with packages
+
+ The data files are specified via a 'package_data' argument to 'setup()'.
+ See 'setuptools.dist.Distribution' for more details.
+
+ Also, this version of the 'build_py' command allows you to specify both
+ 'py_modules' and 'packages' in the same setup operation.
+ """
+
+ def finalize_options(self):
+ _build_py.finalize_options(self)
+ self.package_data = self.distribution.package_data
+ self.data_files = self.get_data_files()
+
+
+ def run(self):
+
+ """Build modules, packages, and copy data files to build directory"""
+
+ 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()
+
+ # Only compile actual .py files, using our base class' idea of what our
+ # output files are.
+ self.byte_compile(_build_py.get_outputs(self,include_bytecode=0))
+
+
+ def get_data_files(self):
+
+ """Generate list of '(package,src_dir,build_dir,filenames)' tuples"""
+
+ data = []
+
+ for package in self.packages:
+ # Locate package source directory
+ src_dir = self.get_package_dir(package)
+
+ # Compute package build directory
+ build_dir = os.path.join(*([self.build_lib]+package.split('.')))
+
+ # Length of path to strip from found files
+ plen = len(src_dir)+1
+
+ # Strip directory from globbed filenames
+ filenames = [
+ file[plen:] for file in self.find_data_files(package, src_dir)
+ ]
+
+ data.append( (package, src_dir, build_dir, filenames) )
+
+ return data
+
+
+ def find_data_files(self, package, src_dir):
+
+ """Return filenames for package's data files in 'src_dir'"""
+
+ globs = self.package_data.get('',[])+self.package_data.get(package,[])
+ files = []
+
+ for pattern in globs:
+ # Each pattern has to be converted to a platform-specific path
+ files.extend(glob(os.path.join(src_dir, convert_path(pattern))))
+
+ return files
+
+
+
+ def build_package_data(self):
+
+ """Copy data files into build directory"""
+
+ lastdir = None
+
+ for package, src_dir, build_dir, filenames in self.data_files:
+
+ for filename in filenames:
+ target = os.path.join(build_dir,filename)
+ self.mkpath(os.path.dirname(target))
+ self.copy_file(os.path.join(src_dir,filename), target)
+
+
+ def get_outputs(self, include_bytecode=1):
+
+ """Return complete list of files copied to the build directory
+
+ This includes both '.py' files and data files, as well as '.pyc' and
+ '.pyo' files if 'include_bytecode' is true. (This method is needed for
+ the 'install_lib' command to do its job properly, and to generate a
+ correct installation manifest.)
+ """
+
+ return _build_py.get_outputs(self,include_bytecode) + [
+ os.path.join(build_dir,filename)
+ for package,src_dir,build_dir,filenames in self.data_files
+ for filename in filenames
+ ]
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/setuptools/command/depends.py b/setuptools/command/depends.py
new file mode 100644
index 00000000..e149faca
--- /dev/null
+++ b/setuptools/command/depends.py
@@ -0,0 +1,27 @@
+from distutils.cmd import Command
+import os
+
+class depends(Command):
+ """Download and install dependencies, if needed"""
+
+ description = "download and install dependencies, if needed"
+
+ user_options = [
+ ('temp=', 't',
+ "directory where dependencies will be downloaded and built"),
+ ('ignore-extra-args', 'i',
+ "ignore options that won't be passed to child setup scripts"),
+ ]
+
+ def initialize_options(self):
+ self.temp = None
+ self.install_purelib = self.install_platlib = None
+ self.install_lib = self.install_libbase = None
+ self.install_scripts = self.install_data = self.install_headers = None
+ self.compiler = self.debug = self.force = None
+
+ def finalize_options(self):
+ self.set_undefined_options('build',('build_temp', 'temp'))
+
+ def run(self):
+ self.announce("downloading and building here")
diff --git a/setuptools/command/install.py b/setuptools/command/install.py
new file mode 100644
index 00000000..82e7ebe8
--- /dev/null
+++ b/setuptools/command/install.py
@@ -0,0 +1,11 @@
+from distutils.command.install import install as _install
+
+class install(_install):
+ """Build dependencies before installation"""
+
+ def has_dependencies(self):
+ return self.distribution.has_dependencies()
+
+ sub_commands = [('depends',has_dependencies)] + _install.sub_commands
+
+
diff --git a/setuptools/command/install_lib.py b/setuptools/command/install_lib.py
new file mode 100644
index 00000000..ec406f7e
--- /dev/null
+++ b/setuptools/command/install_lib.py
@@ -0,0 +1,17 @@
+from distutils.command.install_lib import install_lib as _install_lib
+
+class install_lib(_install_lib):
+ """Don't add compiled flags to filenames of non-Python files"""
+
+ def _bytecode_filenames (self, py_filenames):
+ bytecode_files = []
+ for py_file in py_filenames:
+ if not py_file.endswith('.py'):
+ continue
+ if self.compile:
+ bytecode_files.append(py_file + "c")
+ if self.optimize > 0:
+ bytecode_files.append(py_file + "o")
+
+ return bytecode_files
+
diff --git a/setuptools/command/test.py b/setuptools/command/test.py
new file mode 100644
index 00000000..6b37a9fd
--- /dev/null
+++ b/setuptools/command/test.py
@@ -0,0 +1,82 @@
+from distutils.cmd import Command
+from distutils.errors import DistutilsOptionError
+import sys
+
+class test(Command):
+
+ """Command to run unit tests after installation"""
+
+ description = "run unit tests after installation"
+
+ user_options = [
+ ('test-module=','m', "Run 'test_suite' in specified module"),
+ ('test-suite=','s',
+ "Test suite to run (e.g. 'some_module.test_suite')"),
+ ]
+
+ test_suite = None
+ test_module = None
+
+ def initialize_options(self):
+ pass
+
+
+ def finalize_options(self):
+
+ if self.test_suite is None:
+ if self.test_module is None:
+ self.test_suite = self.distribution.test_suite
+ else:
+ self.test_suite = self.test_module+".test_suite"
+ elif self.test_module:
+ raise DistutilsOptionError(
+ "You may specify a module or a suite, but not both"
+ )
+
+ self.test_args = [self.test_suite]
+
+ if self.verbose:
+ self.test_args.insert(0,'--verbose')
+
+
+ def run(self):
+
+ # Install before testing
+ self.run_command('install')
+
+ if self.test_suite:
+ cmd = ' '.join(self.test_args)
+
+ if self.dry_run:
+ self.announce('skipping "unittest %s" (dry run)' % cmd)
+ else:
+ self.announce('running "unittest %s"' % cmd)
+ import unittest
+ unittest.main(None, None, [unittest.__file__]+self.test_args)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+