[Zope-CVS] SVN: zpkgtools/trunk/zpkg - make sure the setup.py files
for depenedencies can locate the
Fred L. Drake, Jr.
fdrake at gmail.com
Thu Aug 5 12:29:42 EDT 2004
Log message for revision 26917:
- make sure the setup.py files for depenedencies can locate the
support code properly by default
- don't require components to have PUBLICATION.cfg in order to
build/install; the top-level component is the only one required to
have this, and that's checked when the distribution is built (this
makes it easier to work with individual components extracted from a
distribution)
- separate out the loading of the distribution class; this should make
it easier to create more customizable support code later
Changed:
U zpkgtools/trunk/zpkgsetup/setup.py
U zpkgtools/trunk/zpkgtools/app.py
-=-
Modified: zpkgtools/trunk/zpkgsetup/setup.py
===================================================================
--- zpkgtools/trunk/zpkgsetup/setup.py 2004-08-05 15:48:07 UTC (rev 26916)
+++ zpkgtools/trunk/zpkgsetup/setup.py 2004-08-05 16:29:42 UTC (rev 26917)
@@ -58,9 +58,10 @@
class SetupContext:
"""Object representing the arguments to distutils.core.setup()."""
- def __init__(self, pkgname, version, setup_file):
+ def __init__(self, pkgname, version, setup_file, distclass=None):
self._working_dir = os.path.dirname(os.path.abspath(setup_file))
self._pkgname = pkgname
+ self._distclass = distclass or "zpkgsetup.dist.ZPkgDistribution"
self.version = version
self.packages = []
self.package_data = {}
@@ -72,9 +73,10 @@
self.data_files = []
def initialize(self):
- self.load_metadata(
- os.path.join(self._working_dir, self._pkgname,
- publication.PUBLICATION_CONF))
+ metadata_file = os.path.join(self._working_dir, self._pkgname,
+ publication.PUBLICATION_CONF)
+ if os.path.isfile(metadata_file):
+ self.load_metadata(metadata_file)
pkgdir = os.path.join(self._working_dir, self._pkgname)
self.scan(self._pkgname, pkgdir, self._pkgname)
depsdir = os.path.join(self._working_dir, "Dependencies")
@@ -107,13 +109,21 @@
for name in self.__dict__:
if name[0] == "_":
del kwargs[name]
- from zpkgsetup.dist import ZPkgDistribution
from distutils.core import setup
- kwargs["distclass"] = ZPkgDistribution
+ kwargs["distclass"] = self.get_distribution_class()
ContextDisplay.kwargs = kwargs
kwargs["cmdclass"] = {"debugdisplay": ContextDisplay}
setup(**kwargs)
+ def get_distribution_class(self):
+ i = self._distclass.rfind(".")
+ if i >= 0:
+ modname = self._distclass[:i]
+ clsname = self._distclass[i+1:]
+ __import__(modname)
+ return getattr(sys.modules[modname], clsname)
+ raise ValueError("distribution class name must specify a module name")
+
def load_metadata(self, path):
f = open(path, "rU")
publication.load(f, metadata=self)
Modified: zpkgtools/trunk/zpkgtools/app.py
===================================================================
--- zpkgtools/trunk/zpkgtools/app.py 2004-08-05 15:48:07 UTC (rev 26916)
+++ zpkgtools/trunk/zpkgtools/app.py 2004-08-05 16:29:42 UTC (rev 26917)
@@ -136,7 +136,7 @@
destination = os.path.join(depsdir, fullname)
self.add_manifest(destination)
component.write_package(destination)
- component.write_setup_py()
+ component.write_setup_py(pathparts=["..", ".."])
component.write_setup_cfg()
self.add_headers(component)
if self.options.application:
@@ -452,11 +452,15 @@
f.write("optimize = 1\n")
f.close()
- def write_setup_py(self, filename="setup.py", version=None):
+ def write_setup_py(self, filename="setup.py", version=None, pathparts=[]):
setup_py = os.path.join(self.destination, filename)
self.ip.add_output(setup_py)
f = open(setup_py, "w")
- print >>f, SETUP_HEADER
+ if pathparts:
+ extrapath = ", ".join([""] + [repr(pp) for pp in pathparts])
+ else:
+ extrapath = ""
+ print >>f, SETUP_HEADER % extrapath
print >>f, "context = zpkgsetup.setup.SetupContext("
print >>f, " %r, %r, __file__)" % (self.name, version)
print >>f
@@ -481,8 +485,9 @@
# Python 2.2.x does not have __file__ for scripts.
__file__ = sys.argv[0]
-support_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)),
- 'Support')
+here = os.path.dirname(os.path.realpath(__file__))
+support_dir = os.path.join(here%s, 'Support')
+support_dir = os.path.normpath(support_dir)
if os.path.isdir(support_dir):
sys.path.insert(0, support_dir)
More information about the Zope-CVS
mailing list