[Checkins] SVN: zc.sourcerelease/branches/dev/ Ignore stuff
Jim Fulton
jim at zope.com
Wed Oct 24 18:12:46 EDT 2007
Log message for revision 81066:
Ignore stuff
Changed:
_U zc.sourcerelease/branches/dev/
D zc.sourcerelease/branches/dev/sample/
U zc.sourcerelease/branches/dev/setup.py
U zc.sourcerelease/branches/dev/src/zc/sourcerelease/README.txt
U zc.sourcerelease/branches/dev/src/zc/sourcerelease/__init__.py
U zc.sourcerelease/branches/dev/src/zc/sourcerelease/tests.py
-=-
Property changes on: zc.sourcerelease/branches/dev
___________________________________________________________________
Name: svn:ignore
+ develop-eggs
bin
parts
Modified: zc.sourcerelease/branches/dev/setup.py
===================================================================
--- zc.sourcerelease/branches/dev/setup.py 2007-10-24 21:58:05 UTC (rev 81065)
+++ zc.sourcerelease/branches/dev/setup.py 2007-10-24 22:12:46 UTC (rev 81066)
@@ -8,7 +8,7 @@
setup(
name = "zc.sourcerelease",
description = "Utility script to create source releases from buildouts",
- version = ".1",
+ version = "0.1",
license = "ZPL 1.0",
url='http://www.python.org/pypi/zc.sourcerelease',
author='Jim Fulton', author_email='jim at zope.com',
Modified: zc.sourcerelease/branches/dev/src/zc/sourcerelease/README.txt
===================================================================
--- zc.sourcerelease/branches/dev/src/zc/sourcerelease/README.txt 2007-10-24 21:58:05 UTC (rev 81065)
+++ zc.sourcerelease/branches/dev/src/zc/sourcerelease/README.txt 2007-10-24 22:12:46 UTC (rev 81066)
@@ -34,30 +34,20 @@
it.
>>> print get(link_server),
+ <html><body>
+ <a href="index/">index/</a><br>
+ <a href="sample1-1.0.zip">sample1-1.0.zip</a><br>
+ <a href="sample2-1.0.zip">sample2-1.0.zip</a><br>
+ <a href="setuptools-0.6c7-py2.4.egg">setuptools-0.6-py2.4.egg</a><br>
+ <a href="zc.buildout-1.0-py2.4.egg">zc.buildout-1.0-py2.4.egg</a><br>
+ <a href="zc.buildout-99.99-pyN.N.egg">zc.buildout-99.99-pyN.N.egg</a><br>
+ <a href="zc.recipe.egg-1.0-py2.4.egg">zc.recipe.egg-1.0-py2.4.egg</a><br>
+ </body></html>
-We also have a sample buildout in which we'll install the
-buildout-source-release script:
+We have the buildout-source-release installed in a local bin
+directory. We'll create another buildout that we'll use for our
+source release.
- >>> write('buildout.cfg',
- ... '''
- ... [buildout]
- ... parts = script
- ... find-links = %(link_server)s
- ...
- ... [script]
- ... recipe = zc.recipe.egg
- ... eggs = zc.sourcerelease
- ... ''' % globals())
-
- >>> print system(buildout), # doctest: +ELLIPSIS
- Getting distribution for 'zc.recipe.egg'.
- ...
- Generated script '/sample-buildout/bin/buildout-source-release'.
-
-
-This just gets us the script. Now we'll create another buildout that
-we'll use for our source release.
-
>>> mkdir('sample')
>>> sample = join(sample_buildout, 'sample')
>>> write(sample, 'buildout.cfg',
@@ -74,20 +64,141 @@
We'll run the release script against this sample directory:
>>> print system(join('bin', 'buildout-source-release')
- ... +' file://'+join(sample)+' buildout.cfg'),
+ ... +' file://'+sample+' buildout.cfg'),
+ ... # doctest: +ELLIPSIS
+ Creating source release.
+ ...
-What we end up with is a tar file:
+We end up with a tar file:
- >>> ls()
+ >>> ls('.')
+ - .installed.cfg
+ d bin
+ - buildout.cfg
+ d develop-eggs
+ d eggs
+ d parts
+ d sample
+ - sample.tgz
-Let's copy the tar file to a temporary directory:
+Let's extract the tar file to a temporary directory:
>>> mkdir('test')
>>> import tarfile
>>> tf = tarfile.open('sample.tgz', 'r:gz')
- >>> tf.extract('sample', 'test')
+ >>> for name in tf.getnames():
+ ... tf.extract(name, 'test')
+ >>> tf.close()
+
>>> ls('test')
+ d sample
+ >>> ls('test', 'sample')
+ - buildout.cfg
+ d eggs
+ - install.py
+ d release-distributions
+
+The extracted sample directory has eggs for buildout and setuptools:
+
+ >>> ls('test', 'sample', 'eggs')
+ d setuptools-0.6c7-py2.4.egg
+ d zc.buildout-99.99-py2.4.egg
+
+Note that version 99.99 of zc.buildout was used because it was the
+most recent version on the link server. This happens to be different than the version of buildout used by the source-release script.
+
+It has a release-distributions directory containing distributions
+needed to install the buildout:
+
+ >>> ls('test', 'sample', 'release-distributions', 'dist')
+ - sample1-1.0.zip
+ - sample2-1.0.zip
+ - zc.buildout-99.99-pyN.N.egg
+ - zc.recipe.egg-1.0.0b6-py2.4.egg
+
+(There normally aren't distributions for buildout and setuptools
+because these are pre-installed in the eggs directory of the source
+release. In this case, we have a release for zc.buildout because it
+was downloaded from the link server. Anything that we downloaded is
+included.)
+
+So, not that we've extracted the source release we built, we can try
+to install it. To do this, we'll to run the installer.
+
+ >>> import sys
+ >>> print system(sys.executable+' '+join('test', 'sample', 'install.py')),
+ ... # doctest: +ELLIPSIS
+ Creating directory ...
+
+
+Running the installer simply builds out the saved buildout, using the
+release-distribution as the source for installable eggs. In our case,
+we get a sample script that we can run:
+
+ >>> print system(join('test', 'sample', 'bin', 'sample1')),
+ Hello. My name is sample1
+
+Note that the sample bin directory doesn't contain a buildout script:
+
+ >>> ls('test', 'sample', 'bin')
+ - sample1
+
+If we want one, we can run the install script again with an argument
+of 'bootstrap'.
+
+ >>> print system(sys.executable+
+ ... ' '+join('test', 'sample', 'install.py bootstrap')),
+ Generated script '/sample-buildout/test/sample/bin/buildout'.
+
+ >>> ls('test', 'sample', 'bin')
+ - buildout
+ - sample1
+
+Note that the install script is a specialized buildout script, so
+other buildout options can be provided, although this shouldn't
+normally be necessary.
+
+Often, we'll use file URLs for testing, but store the buildouts to be
+released in a source code repository like subversion. We've created a
+simple sample. Let's try to install it:
+
+ >>> print system(join('bin', 'buildout-source-release')+' '+
+ ... 'svn://svn.zope.org/repos/main/zc.sourcerelease/svnsample'+
+ ... ' release.cfg'),
+ ... # doctest: +ELLIPSIS
+ A ...
+ Creating source release.
+ ...
+
+ >>> ls('.')
+ - .installed.cfg
+ d bin
+ - buildout.cfg
+ d develop-eggs
+ d eggs
+ d parts
+ d sample
+ - sample.tgz
+ - svnsample.tgz
+ d test
+
+ >>> mkdir('svntest')
+ >>> import tarfile
+ >>> tf = tarfile.open('svnsample.tgz', 'r:gz')
+ >>> for name in tf.getnames():
+ ... tf.extract(name, 'svntest')
+ >>> tf.close()
+
+ >>> print system(sys.executable
+ ... +' '+join('svntest', 'svnsample', 'install.py')),
+ ... # doctest: +ELLIPSIS
+ Creating directory ...
+
+ >>> print system(join('svntest', 'svnsample', 'bin', 'sample')),
+ sample from svn called
+
+
.. [#zip_in_future] It is possible that an option will be added in the
future to generate zip files rather than tar archives.
Modified: zc.sourcerelease/branches/dev/src/zc/sourcerelease/__init__.py
===================================================================
--- zc.sourcerelease/branches/dev/src/zc/sourcerelease/__init__.py 2007-10-24 21:58:05 UTC (rev 81065)
+++ zc.sourcerelease/branches/dev/src/zc/sourcerelease/__init__.py 2007-10-24 22:12:46 UTC (rev 81066)
@@ -29,7 +29,25 @@
r = p.wait()
if r:
raise SystemError("Subprocess failed!")
+
+def _relative(path, to):
+ rel = []
+
+ # Remove trailing separators
+ while 1:
+ d, b = os.path.split(to)
+ if b:
+ break
+ to = d
+ while path and path != to:
+ path, base = os.path.split(path)
+ if base:
+ rel.insert(0, base)
+ if path != to:
+ return None
+ return os.path.join(*rel)
+
def source_release(args=None):
if args is None:
args = sys.argv[1:]
@@ -40,31 +58,34 @@
co1 = os.path.join(t1, name)
co2 = os.path.join(t2, name)
here = os.getcwd()
+ print 'Creating source release.'
try:
if url.startswith('file://'):
shutil.copytree(urlparse.urlparse(url)[2], co1)
else:
- system('svn', 'export', url, co1)
+ _system('svn', 'export', url, co1)
shutil.copytree(co1, co2)
cache = os.path.join(co2, 'release-distributions')
os.mkdir(cache)
buildout = zc.buildout.buildout.Buildout(
- os.path.join(co1, config),
- [('buildout', 'download-cache', cache),
- ('buildout', 'verbosity', '10'),
- ],
+ os.path.join(co1, config), [],
False, False, 'install',
)
- buildout.install([])
+ eggs_directory = buildout['buildout']['eggs-directory']
+
+ buildout.bootstrap([])
+
+ _system(os.path.join(co1, 'bin', 'buildout'),
+ '-Uvc', os.path.join(co1, config),
+ 'buildout:download-cache='+cache)
+
os.chdir(here)
- env = pkg_resources.Environment([
- buildout['buildout']['eggs-directory']
- ])
+ env = pkg_resources.Environment([eggs_directory])
dists = [env[project][0].location
- for project in ('zc.buildout', 'setuptools')
- ]
+ for project in ('zc.buildout', 'setuptools')]
+
eggs = os.path.join(co2, 'eggs')
os.mkdir(eggs)
for dist in dists:
@@ -75,11 +96,17 @@
else:
shutil.copy(dist, eggs)
+ eggs_directory = _relative(eggs_directory, co1)
+ if eggs_directory is None:
+ print 'Invalid eggs directory'
+ sys.exit(0)
+
open(os.path.join(co2, 'install.py'), 'w').write(
install_template % dict(
path = [os.path.basename(dist) for dist in dists],
config = config,
version = sys.version_info[:2],
+ eggs_directory = eggs_directory,
))
@@ -100,16 +127,18 @@
print "Python %%s.%%s is required." %% %(version)r
sys.exit(1)
+here = os.path.abspath(os.path.dirname(__file__))
+
sys.path[0:0] = [
- os.path.join('eggs', dist)
+ os.path.join(here, %(eggs_directory)r, dist)
for dist in %(path)r
]
-config = %(config)r
+config = os.path.join(here, %(config)r)
import zc.buildout.buildout
zc.buildout.buildout.main([
'-Uc', config,
- 'buildout:download-cache=release-distributions',
+ 'buildout:download-cache='+os.path.join(here, 'release-distributions'),
'buildout:install-from-cache=true',
]+sys.argv[1:])
"""
Modified: zc.sourcerelease/branches/dev/src/zc/sourcerelease/tests.py
===================================================================
--- zc.sourcerelease/branches/dev/src/zc/sourcerelease/tests.py 2007-10-24 21:58:05 UTC (rev 81065)
+++ zc.sourcerelease/branches/dev/src/zc/sourcerelease/tests.py 2007-10-24 22:12:46 UTC (rev 81066)
@@ -13,6 +13,7 @@
##############################################################################
import os
+import re
import shutil
import tempfile
import unittest
@@ -67,6 +68,16 @@
else:
shutil.copy(src, dest)
+bo = """
+[buildout]
+parts = script
+find-links = %(link_server)s
+
+[script]
+recipe = zc.recipe.egg
+eggs = zc.sourcerelease
+"""
+
def setUp(test):
zc.buildout.testing.buildoutSetUp(test)
sample_eggs = test.globs['tmpdir']('sample_eggs')
@@ -77,8 +88,7 @@
test.globs['link_server'] = test.globs['start_server'](
test.globs['sample_eggs'])
- for project in ('zc.sourcerelease', 'zc.recipe.egg', 'zc.buildout',
- 'setuptools'):
+ for project in ('zc.recipe.egg', 'zc.buildout', 'setuptools'):
dist = pkg_resources.working_set.find(
pkg_resources.Requirement.parse(project))
copy_egg(dist.location, sample_eggs)
@@ -88,6 +98,31 @@
else:
copy_egg(dist.location, sample_eggs)
+ zc.buildout.testing.install_develop('zc.sourcerelease', test)
+
+ # Set up the buildout-source-release script
+ test.globs['write']('buildout.cfg', bo % test.globs)
+ test.globs['system'](test.globs['buildout'])
+
+ # Install wacky v 99.99 zc.buildout
+ env = pkg_resources.Environment([sample_eggs])
+ dist = env['zc.buildout'][0]
+ eggname, oldver, pyver = egg_parse(
+ os.path.basename(dist.location)
+ ).groups()
+ dest = os.path.join(sample_eggs, "%s-99.99-py%s.egg" % (eggname, pyver))
+ shutil.copy(dist.location, dest)
+ zip = zipfile.ZipFile(dest, 'a')
+ zip.writestr(
+ 'EGG-INFO/PKG-INFO',
+ zip.read('EGG-INFO/PKG-INFO').replace("Version: %s" % oldver,
+ "Version: 99.99")
+ )
+ zip.close()
+
+egg_parse = re.compile('([0-9a-zA-Z_.]+)-([0-9a-zA-Z_.]+)-py(\d[.]\d).egg$'
+ ).match
+
def test_suite():
return unittest.TestSuite((
doctest.DocFileSuite(
@@ -96,6 +131,7 @@
checker=renormalizing.RENormalizing([
zc.buildout.testing.normalize_path,
zc.buildout.testing.normalize_egg_py,
+ (re.compile('-\S+-py'), ''),
]),
),
))
More information about the Checkins
mailing list