Pregunta

Am I able to configure setup.py and then install the egg through easy_install such that it can do some sort of template or inject the version number into one of my source files? I have version = os.environ.get('BUILD_NUMBER', 0.1) in my setup.py and I want to put this version number into one of the source files because I need a version number to run some stuff. The reason I don’t hard code this is because the version number changes each time there is a new build.

I want to inject this version/build number into a runner script - not a Python file. This runner script is sent to /usr/local/bin by easy_install.

¿Fue útil?

Solución

If your build tool is already generating the build numbers, why not have it fill in a template version.py in your project?

  • project/
    • project/__init__.py
    • project/version.py

Where version.py is simply:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
__all__ = ('__version__',)
__version__ = $BUILD_NUMBER

This way, it is always available and doesn't depend on something like setup.py metadata. For your setup.py script, try something like this:

def get_version():
    """
    Gets the latest version number out of the package,
    saving us from maintaining it in multiple places.
    """
    local_results = {}
    execfile('project/version.py', {}, local_results)
    return local_results['__version__']

setup(
    name="Project",
    version=get_version(),
    ...
)
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top