Skip to content

Commit

Permalink
move version figuring to setup.py
Browse files Browse the repository at this point in the history
  • Loading branch information
mbacchi committed May 19, 2015
1 parent 8846d78 commit e04e15c
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 30 deletions.
12 changes: 4 additions & 8 deletions euca-deploy.spec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
%define name euca-deploy
%define version 0.1a
%define unmangled_version 0.1a
%define unmangled_version 0.1a
%define version 0.1
%define unmangled_version 0.1
%define unmangled_version 0.1
%define release 1

Summary: Tool for installing Eucalyptus
Expand All @@ -17,11 +17,7 @@ BuildArch: noarch
Vendor: Vic Iglesias <[email protected]>
Url: https://github.com/viglesiasce/euca-deploy/

Requires: PyYaml
Requires: python-devel
Requires: python-setuptools
Requires: gcc
Requires: git
Requires: fabric PyYaml

%description
# Euca Deploy
Expand Down
19 changes: 0 additions & 19 deletions eucadeploy/version.py

This file was deleted.

73 changes: 70 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,81 @@
#!/usr/bin/env python

from __future__ import with_statement
from distutils.command.build_py import build_py
from distutils.command.sdist import sdist
import os.path
import subprocess

from setuptools import setup, find_packages

from eucadeploy.version import get_version

__version__ = '0.1'


# Check if this is a git repo; maybe we can get more precise version info
try:
REPO_PATH = "."
# noinspection PyUnresolvedReferences
GIT = subprocess.Popen(
# TODO: mbacchi change this to "git describe --tag" when first git tag has been defined
['git', 'describe', '--always'], stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
env={'GIT_DIR': os.path.join(REPO_PATH, '.git')})
GIT.wait()
GIT.stderr.read()
if GIT.returncode == 0:
__version__ = GIT.stdout.read().strip().lstrip('v')
if type(__version__).__name__ == 'bytes':
__version__ = __version__.decode()
except:
# Not really a bad thing; we'll just use what we had
pass

class build_py_with_git_version(build_py):
'''Like build_py, but also hardcoding the version in __init__.__version__
so it's consistent even outside of the source tree'''

def build_module(self, module, module_file, package):
orig_outfile, _ = build_py.build_module(self, module, module_file,
package)
version_line = "__version__ = '{0}'\n".format(__version__)
new_outfile = orig_outfile + '.new'
with open(new_outfile, 'w') as new_fh:
with open(orig_outfile) as orig_fh:
for line in orig_fh:
if line.startswith('__version__ ='):
new_fh.write(version_line)
else:
new_fh.write(line)
new_fh.flush()
os.rename(new_outfile, orig_outfile)


class sdist_with_git_version(sdist):
'''Like sdist, but also hardcoding the version in __init__.__version__ so
it's consistent even outside of the source tree'''

def make_release_tree(self, base_dir, files):
sdist.make_release_tree(self, base_dir, files)
version_line = "__version__ = '{0}'\n".format(__version__)
orig_setup = os.path.join(base_dir, 'setup.py')
new_setup = orig_setup + '.new'
with open(new_setup, 'w') as new_fh:
with open(orig_setup) as orig_fh:
for line in orig_fh:
if line.startswith('__version__ ='):
new_fh.write(version_line)
else:
new_fh.write(line)
new_fh.flush()
os.rename(new_setup, orig_setup)


with open('README.md') as f:
long_description = f.read()

setup(
name='euca-deploy',
version=get_version(),
version=__version__,
description='Tool for installing Eucalyptus',
long_description=long_description,
author='Vic Iglesias',
Expand All @@ -38,4 +101,8 @@
'Topic :: System :: Clustering',
'Topic :: System :: Systems Administration',
],
cmdclass={
'build_py': build_py_with_git_version,
'sdist': sdist_with_git_version
},
)

0 comments on commit e04e15c

Please sign in to comment.