Refactor setup.py using Python Build Reasonableness[1]
as a standard for OpenStack projects.

[1] http://docs.openstack.org/developer/pbr/

Closes-Bug: #1559150
Change-Id: Ie3b3845f11236f5338228690418760599914cce4
This commit is contained in:
Alan Pevec 2016-03-22 19:25:43 +01:00 committed by Javier Pena
parent 92ea78df62
commit 1bbcbff4fb
11 changed files with 72 additions and 181 deletions

View File

@ -200,9 +200,9 @@ This is the current matrix of available tests:
| sahara | | X | |
| trove | | X | |
| horizon | X | | |
| manila | X | | |
| nagios | X | | |
| SSL | X | | |
| manila | X | | |
| nagios | X | | |
| SSL | X | | |
To run these tests:

View File

@ -1,15 +0,0 @@
#!/usr/bin/env python
import os, sys
try:
import packstack
except ImportError:
# packstack isn't installed, running from source checkout
sys.path.insert(0, os.path.join(os.path.split(sys.argv[0])[0], ".."))
import packstack
os.environ["INSTALLER_PROJECT_DIR"] = os.path.abspath(os.path.split(packstack.__file__)[0])
from packstack.installer import run_setup
run_setup.main()

View File

@ -1,19 +0,0 @@
#!/usr/bin/env bash
SCRIPT_PATH="${BASH_SOURCE[0]}"
SCRIPT_DIR=`dirname $SCRIPT_PATH`
cd $SCRIPT_DIR/..
if [ -n "$1" ] ; then
# tagged release
BRANCH=`git rev-parse --abbrev-ref HEAD`
git fetch gerrit
git tag -m $1 -s $1 gerrit/$BRANCH
git push gerrit tag $1
else
# development release
VERSION=`python setup.py --version`
sed -i -e "s/RESERVE_STR = None/RESERVE_STR = '$VERSION'/g" packstack/version.py
python setup.py sdist
git checkout packstack/version.py
fi

View File

@ -26,7 +26,7 @@
import sys
sys.path.append('..')
from packstack import version as packstackversion
from packstack.version import version_info
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
@ -52,7 +52,7 @@ source_suffix = '.rst'
# source_encoding = 'utf-8-sig'
# The master toctree document.
master_doc = 'index'
master_doc = 'packstack'
# General information about the project.
project = u'packstack'
@ -63,9 +63,9 @@ copyright = u'2012, Red Hat'
# built documents.
#
# The short X.Y version.
version = packstackversion.version_string()
version = version_info.version_string()
# The full version, including alpha/beta/rc tags.
release = version
release = version_info.release_string()
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.

View File

@ -34,6 +34,8 @@ PACKSTACK_SRC_DOC = pkg_resources.resource_filename(
)
if os.path.exists(PACKSTACK_SRC_DOC):
PACKSTACK_DOC = PACKSTACK_SRC_DOC
elif os.path.exists(os.path.join(sys.prefix, 'share/packstack/packstack.rst')):
PACKSTACK_DOC = os.path.join(sys.prefix, 'share/packstack/packstack.rst')
else:
PACKSTACK_DOC = '/usr/share/packstack/packstack.rst'
@ -87,7 +89,7 @@ PUPPET_MODULES_DEPS = ['rubygem-json']
FILE_INSTALLER_LOG = "setup.log"
DIR_PROJECT_DIR = os.environ.get('INSTALLER_PROJECT_DIR', os.path.join(os.getcwd(), 'packstack'))
DIR_PROJECT_DIR = os.environ.get('INSTALLER_PROJECT_DIR', os.path.abspath(os.path.join(os.path.split(__file__)[0], '..')))
DIR_PLUGINS = os.path.join(DIR_PROJECT_DIR, "plugins")
DIR_MODULES = os.path.join(DIR_PROJECT_DIR, "modules")

View File

@ -35,8 +35,8 @@ import output_messages
from .exceptions import FlagValidationError
from .exceptions import ParamValidationError
from packstack import version
from packstack.modules.common import filtered_hosts
from packstack.version import version_info
from setup_controller import Controller
controller = Controller()
@ -799,7 +799,7 @@ def initCmdLineParser():
# Init parser and all general flags
usage = "usage: %prog [options] [--help]"
parser = OptionParser(usage=usage, version="%prog {0} {1}".format(version.release_string(), version.version_string()))
parser = OptionParser(usage=usage, version="%prog {0}".format(version_info.version_string()))
parser.add_option("--gen-answer-file", help="Generate a template of an answer file.")
parser.add_option("--answer-file", help="Runs the configuration in non-interactive mode, extracting all information from the"
"configuration file. using this option excludes all other options")

View File

@ -12,81 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import pkg_resources
import pbr.version
from .installer.utils import execute
VERSION = ['8', '0', '0']
OS_RELEASE = 'Mitaka'
RESERVE_STR = None
def vr_from_git():
"""Returns VR string calculated from GIT repo."""
proj_dir = os.path.dirname(os.path.dirname(__file__))
rc, tag = execute(
'git describe --exact-match',
workdir=proj_dir,
use_shell=True,
can_fail=False,
log=False
)
if not rc:
# we are on tagged commit, so let's use the tag as VR string
return tag.strip()
rc, description = execute(
'git describe --always',
workdir=proj_dir,
use_shell=True,
log=False
)
if '-' in description:
# last tag has been found
tag, snap_tag, git_hash = description.split('-')
else:
# no tag has been found
tag = '.'.join(VERSION)
rc, git_hash = execute(
'git log -n1 --pretty=format:%h',
workdir=proj_dir,
use_shell=True,
log=False
)
git_hash = 'g{0}'.format(git_hash)
rc, snap_tag = execute(
'git log --oneline | wc -l',
workdir=proj_dir,
use_shell=True,
log=False
)
tag, snap_tag, git_hash = tag.strip(), snap_tag.strip(), git_hash.strip()
return '{tag}.dev{snap_tag}.{git_hash}'.format(**locals())
def vr_from_setuptools():
"""Returns VR string fetched from setuptools."""
requirement = pkg_resources.Requirement.parse('packstack')
provider = pkg_resources.get_provider(requirement)
return provider.version
def release_string():
return OS_RELEASE
def version_string():
try:
version = vr_from_git()
except Exception:
# Not a git repo, so get version from setuptools
try:
version = vr_from_setuptools()
except Exception:
# In case of problem with setuptools, return version
# saved by release.sh or VERSION if nothing was saved
version = RESERVE_STR if RESERVE_STR else '.'.join(VERSION)
return version
version_info = pbr.version.VersionInfo('packstack')

View File

@ -1,3 +1,4 @@
pbr>=1.6 # Apache-2.0
netaddr>=0.7.6
PyYAML>=3.10
docutils>=0.11

46
setup.cfg Normal file
View File

@ -0,0 +1,46 @@
[metadata]
name = packstack
summary = A utility to install OpenStack
description-file = README.md
author = RDO
author-email = rdo-list@redhat.com
home-page = http://www.rdoproject.org/
classifier =
Environment :: OpenStack
Intended Audience :: Developers
Intended Audience :: Information Technology
Intended Audience :: System Administrators
License :: OSI Approved :: Apache Software License
Operating System :: POSIX :: Linux
Programming Language :: Python
Programming Language :: Python :: 2.7
[files]
packages =
packstack
data_files =
share/packstack = docs/packstack.rst
[global]
setup-hooks =
pbr.hooks.setup_hook
[egg_info]
tag_build =
tag_date = 0
tag_svn_revision = 0
[build_sphinx]
all_files = 1
build-dir = docs/build
source-dir = docs
[pbr]
warnerrors = True
autodoc_tree_index_modules = True
[entry_points]
console_scripts =
packstack = packstack.installer.run_setup:main

View File

@ -1,54 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import setuptools
import os
from setuptools import setup
from setuptools import find_packages
from packstack import version
# Utility function to read the README file.
# Used for the long_description. It's nice, because now 1) we have a top level
# README file and 2) it's easier to type in the README file than to put a raw
# string in below ...
def read(fname):
return open(os.path.join(os.path.dirname(__file__), fname)).read()
setup(
name="packstack",
version=version.version_string(),
author="Derek Higgins",
author_email="derekh@redhat.com",
description=("A utility to install OpenStack"),
license="ASL 2.0",
keywords="openstack",
url="https://github.com/openstack/packstack",
packages=find_packages('.') + ['docs'],
package_data={'docs': ['docs/packstack.rst']},
include_package_data=True,
long_description=read('README.md'),
zip_safe=False,
install_requires=['netaddr>=0.7.6', 'pyOpenSSL<15.0.0', 'PyYAML>=3.10',
'docutils>=0.11', 'cryptography!=1.3.0,>=1.0'],
classifiers=[
"Development Status :: 3 - Alpha",
"Topic :: Utilities",
"License :: OSI Approved :: Apache Software License",
],
scripts=["bin/packstack"]
)
setuptools.setup(
setup_requires=['pbr>=1.8'],
pbr=True)

View File

@ -38,4 +38,4 @@ commands = sphinx-build -a -E -W -d releasenotes/build/doctrees -b html releasen
# All other checks should be enabled in the future.
ignore = E123,E125,H803,F403,F821,F811,F841,E501,H302,H303,H304,H306,H405,H404,H305,H307,H501,H201,H101
show-source = True
exclude=.venv,.git,.tox
exclude=.venv,.git,.tox,.eggs