Don't update pbr's setup.py

Due to the fact that we'd like to keep pbr's requirements in sync with
global requirements we should disable syncing of setup.py for pbr.

* existing tests fixed by adding standard setup.cfg file;
* new test case added for syncing pbr project (with pbr like setup.cfg file).

Change-Id: Ibf5fcdad118fffb4fd5dd50c5d1decfa6f9a6479
This commit is contained in:
Sergey Lukjanov 2014-02-14 02:05:01 +04:00
parent 4dc3efdce3
commit fbe30c43bf
6 changed files with 133 additions and 1 deletions

18
tests/files/pbr_setup.cfg Normal file
View File

@ -0,0 +1,18 @@
[metadata]
name = pbr
author = OpenStack
author-email = openstack-dev@lists.openstack.org
summary = Python Build Reasonableness
description-file =
README.rst
home-page = http://pypi.python.org/pypi/pbr
requires-python = >=2.6
classifier =
Development Status :: 5 - Production/Stable
Environment :: Console
Environment :: OpenStack
Intended Audience :: Developers
Intended Audience :: Information Technology
License :: OSI Approved :: Apache Software License
Operating System :: OS Independent
Programming Language :: Python

18
tests/files/setup.cfg Normal file
View File

@ -0,0 +1,18 @@
[metadata]
name = testproject
summary = OpenStack Test Project
description-file =
README.rst
author = OpenStack
author-email = openstack-dev@lists.openstack.org
home-page = http://www.openstack.org/
classifier =
Environment :: OpenStack
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
Programming Language :: Python :: 2.7
Programming Language :: Python :: 2.6

View File

@ -48,6 +48,8 @@ class UpdateTest(testtools.TestCase):
"test-requirements.txt")
self.setup_file = os.path.join(self.project_dir, "setup.py")
self.old_setup_file = os.path.join(self.oslo_dir, "setup.py")
self.setup_cfg_file = os.path.join(self.project_dir, "setup.cfg")
self.oslo_setup_cfg_file = os.path.join(self.oslo_dir, "setup.cfg")
os.mkdir(self.project_dir)
os.mkdir(self.oslo_dir)
@ -58,6 +60,8 @@ class UpdateTest(testtools.TestCase):
shutil.copy("tests/files/test-project.txt", self.proj_test_file)
shutil.copy("tests/files/setup.py", self.setup_file)
shutil.copy("tests/files/old-setup.py", self.old_setup_file)
shutil.copy("tests/files/setup.cfg", self.setup_cfg_file)
shutil.copy("tests/files/setup.cfg", self.oslo_setup_cfg_file)
shutil.copy("update.py", os.path.join(self.dir, "update.py"))
# now go call update and see what happens

86
tests/test_update_pbr.py Normal file
View File

@ -0,0 +1,86 @@
# Copyright 2013 IBM Corp.
# Copyright (c) 2013 Mirantis Inc.
#
# 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.
# Based on test_update.py
from __future__ import print_function
import os
import shutil
import subprocess
import sys
import tempfile
import testtools
def _file_to_list(fname):
with open(fname) as f:
content = list(map(lambda x: x.rstrip(), f.readlines()))
print(content)
return content
class UpdateTestPbr(testtools.TestCase):
def setUp(self):
super(UpdateTestPbr, self).setUp()
self.dir = tempfile.mkdtemp()
self.project_dir = os.path.join(self.dir, "project_pbr")
self.req_file = os.path.join(self.dir, "global-requirements.txt")
self.dev_req_file = os.path.join(self.dir, "dev-requirements.txt")
self.proj_file = os.path.join(self.project_dir, "requirements.txt")
self.proj_test_file = os.path.join(self.project_dir,
"test-requirements.txt")
self.setup_file = os.path.join(self.project_dir, "setup.py")
self.setup_cfg_file = os.path.join(self.project_dir, "setup.cfg")
os.mkdir(self.project_dir)
shutil.copy("tests/files/gr-base.txt", self.req_file)
shutil.copy("tests/files/dev-req.txt", self.dev_req_file)
shutil.copy("tests/files/project.txt", self.proj_file)
shutil.copy("tests/files/test-project.txt", self.proj_test_file)
shutil.copy("tests/files/setup.py", self.setup_file)
shutil.copy("tests/files/pbr_setup.cfg", self.setup_cfg_file)
shutil.copy("update.py", os.path.join(self.dir, "update.py"))
# now go call update and see what happens
self.addCleanup(os.chdir, os.path.abspath(os.curdir))
os.chdir(self.dir)
subprocess.call([sys.executable, "update.py", "project_pbr"])
def test_requirements(self):
reqs = _file_to_list(self.req_file)
self.assertIn("jsonschema>=1.0.0,!=1.4.0,<2", reqs)
def test_project(self):
reqs = _file_to_list(self.proj_file)
# ensure various updates take
self.assertIn("jsonschema>=1.0.0,!=1.4.0,<2", reqs)
self.assertIn("python-keystoneclient>=0.4.1", reqs)
self.assertIn("SQLAlchemy>=0.7,<=0.7.99", reqs)
def test_test_project(self):
reqs = _file_to_list(self.proj_test_file)
self.assertIn("testtools>=0.9.32", reqs)
self.assertIn("testrepository>=0.0.17", reqs)
# make sure we didn't add something we shouldn't
self.assertNotIn("sphinxcontrib-pecanwsme>=0.2", reqs)
def test_install_setup(self):
setup_contents = _file_to_list(self.setup_file)
self.assertNotIn("# THIS FILE IS MANAGED BY THE GLOBAL REQUIREMENTS "
"REPO - DO NOT EDIT", setup_contents)

View File

@ -48,6 +48,8 @@ class UpdateTestWithSuffix(testtools.TestCase):
"test-requirements.txt")
self.setup_file = os.path.join(self.project_dir, "setup.py")
self.old_setup_file = os.path.join(self.oslo_dir, "setup.py")
self.setup_cfg_file = os.path.join(self.project_dir, "setup.cfg")
self.oslo_setup_cfg_file = os.path.join(self.oslo_dir, "setup.cfg")
os.mkdir(self.project_dir)
os.mkdir(self.oslo_dir)
@ -58,6 +60,8 @@ class UpdateTestWithSuffix(testtools.TestCase):
shutil.copy("tests/files/test-project.txt", self.proj_test_file)
shutil.copy("tests/files/setup.py", self.setup_file)
shutil.copy("tests/files/old-setup.py", self.old_setup_file)
shutil.copy("tests/files/setup.cfg", self.setup_cfg_file)
shutil.copy("tests/files/setup.cfg", self.oslo_setup_cfg_file)
shutil.copy("update.py", os.path.join(self.dir, "update.py"))
# now go call update and see what happens

View File

@ -151,11 +151,13 @@ def _copy_requires(suffix, dest_dir):
def _write_setup_py(dest_path):
target_setup_py = os.path.join(dest_path, 'setup.py')
setup_cfg = os.path.join(dest_path, 'setup.cfg')
# If it doesn't have a setup.py, then we don't want to update it
if not os.path.exists(target_setup_py):
return
has_pbr = 'pbr' in open(target_setup_py, 'r').read()
if has_pbr:
is_pbr = 'name = pbr' in open(setup_cfg, 'r').read()
if has_pbr and not is_pbr:
print("Syncing setup.py")
# We only want to sync things that are up to date with pbr mechanics
with open(target_setup_py, 'w') as setup_file: