Personal tools
You are here: Home Blog archive 2009 March

March

Sub-archives

Create version in Genericsetup metadata.xml from setup.py

by Bastian Blank — last modified Mar 09, 2009 12:25 AM
Filed Under:

Today I asked if it is possible to do automatic updates of the version in metadata.xml from the (possible mangled) version from setup.py. Nothing popped up, so I wrote an extension of setuptools which does this.

import os.path
from distutils import log
from setuptools.command.egg_info import egg_info as _egg_info

class egg_info(_egg_info):
    def run(self):
        _egg_info.run(self)

        version = self.distribution.metadata.version

        for package in self.distribution.packages:
            path = os.path.join(*(package.split('.') + ['profiles', 'default']))
            if os.path.isdir(path):
                metadata_out = os.path.join(path, 'metadata.xml')
                metadata_in = os.path.join(path, 'metadata.xml.in')
                if os.path.exists(metadata_in):
                    log.info('writing %s', metadata_out)
                    d = open(metadata_in, 'r').read().replace('@VERSION@', version)
                    open(metadata_out, 'w').write(d)

setup(
    cmdclass = {'egg_info': egg_info},
    [...]
)

The version is listed with a placeholder in the input file called metadata.xml.in and is replaced during a normal develop call as done by buildout.

<metadata>
    <version>@VERSION@</version>
</metadata>

UPDATE: This is evil. metadata.xml should list the the config/profile version, not the code version.