Update update.py to also write a stock setup.py
One of the points of pbr was ensuring that we had a consistent build environment, but we still have boilerplate setup.py laying around. Install the right boilerplate at update time. Change-Id: If4b2e16b469171204270ace8144792e607cfddd7
This commit is contained in:
parent
f7fbf480da
commit
11aa4b333f
21
tests/files/setup.py
Normal file
21
tests/files/setup.py
Normal file
@ -0,0 +1,21 @@
|
||||
#!/usr/bin/env python
|
||||
# Copyright (c) 2013 Hewlett-Packard Development Company, L.P.
|
||||
#
|
||||
# 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
|
||||
|
||||
setuptools.setup(
|
||||
setup_requires=['d2to1', 'pbr>=0.5,<0.6'],
|
||||
d2to1=True)
|
@ -23,7 +23,7 @@ import tempfile
|
||||
import testtools
|
||||
|
||||
|
||||
def _load_req(fname):
|
||||
def _file_to_list(fname):
|
||||
with open(fname) as f:
|
||||
content = map(lambda x: x.rstrip(), f.readlines())
|
||||
print content
|
||||
@ -43,6 +43,7 @@ class UpdateTest(testtools.TestCase):
|
||||
self.oslo_file = os.path.join(self.oslo_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")
|
||||
os.mkdir(self.project_dir)
|
||||
os.mkdir(self.oslo_dir)
|
||||
|
||||
@ -50,34 +51,41 @@ class UpdateTest(testtools.TestCase):
|
||||
shutil.copy("tests/files/project-with-oslo-tar.txt", self.oslo_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("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"])
|
||||
subprocess.call([sys.executable, "update.py", "project_with_oslo"])
|
||||
|
||||
def test_requirements(self):
|
||||
reqs = _load_req(self.req_file)
|
||||
reqs = _file_to_list(self.req_file)
|
||||
self.assertIn("jsonschema>=1.0.0,!=1.4.0,<2", reqs)
|
||||
|
||||
def test_project(self):
|
||||
reqs = _load_req(self.proj_file)
|
||||
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.3.0", reqs)
|
||||
self.assertIn("SQLAlchemy>=0.7,<=0.7.99", reqs)
|
||||
|
||||
def test_project_with_oslo(self):
|
||||
reqs = _load_req(self.oslo_file)
|
||||
reqs = _file_to_list(self.oslo_file)
|
||||
oslo_tar = ("-f http://tarballs.openstack.org/oslo.config/"
|
||||
"oslo.config-1.2.0a3.tar.gz#egg=oslo.config-1.2.0a3")
|
||||
self.assertIn(oslo_tar, reqs)
|
||||
self.assertIn("oslo.config>=1.1.0", reqs)
|
||||
|
||||
def test_test_project(self):
|
||||
reqs = _load_req(self.proj_test_file)
|
||||
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.assertIn("# THIS FILE IS MANAGED BY THE GLOBAL REQUIREMENTS REPO"
|
||||
" - DO NOT EDIT", setup_contents)
|
||||
|
55
update.py
55
update.py
@ -1,18 +1,19 @@
|
||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright 2012 OpenStack, LLC
|
||||
# Copyright 2013 Hewlett-Packard Development Company, L.P.
|
||||
#
|
||||
# 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
|
||||
# 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
|
||||
# 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.
|
||||
# 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.
|
||||
|
||||
r"""
|
||||
A simple script to update the requirements files from a global set of
|
||||
@ -34,6 +35,31 @@ import sys
|
||||
from pip import req
|
||||
|
||||
|
||||
_setup_py_text = """#!/usr/bin/env python
|
||||
# Copyright (c) 2013 Hewlett-Packard Development Company, L.P.
|
||||
#
|
||||
# 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.
|
||||
|
||||
# THIS FILE IS MANAGED BY THE GLOBAL REQUIREMENTS REPO - DO NOT EDIT
|
||||
import setuptools
|
||||
|
||||
setuptools.setup(
|
||||
setup_requires=['pbr>=0.5.20'],
|
||||
pbr=True)
|
||||
"""
|
||||
|
||||
|
||||
def _parse_pip(pip):
|
||||
|
||||
install_require = req.InstallRequirement.from_line(pip)
|
||||
@ -71,7 +97,7 @@ def _sync_requirements_file(source_reqs, dest_path):
|
||||
with open(dest_path, 'r') as dest_reqs_file:
|
||||
dest_reqs = dest_reqs_file.readlines()
|
||||
|
||||
print "Syncing %s" % dest_path
|
||||
print("Syncing %s" % dest_path)
|
||||
|
||||
with open(dest_path, 'w') as new_reqs:
|
||||
for old_line in dest_reqs:
|
||||
@ -105,12 +131,19 @@ def _copy_requires(source_path, dest_dir):
|
||||
for dest in target_files:
|
||||
dest_path = os.path.join(dest_dir, dest)
|
||||
if os.path.exists(dest_path):
|
||||
print "_sync_requirements_file(%s, %s)" % (source_reqs, dest_path)
|
||||
print("_sync_requirements_file(%s, %s)" % (source_reqs, dest_path))
|
||||
_sync_requirements_file(source_reqs, dest_path)
|
||||
|
||||
|
||||
def _write_setup_py(dest_path):
|
||||
print("Syncing setup.py")
|
||||
with open(os.path.join(dest_path, 'setup.py'), 'w') as setup_file:
|
||||
setup_file.write(_setup_py_text)
|
||||
|
||||
|
||||
def main(argv):
|
||||
_copy_requires('global-requirements.txt', argv[0])
|
||||
_write_setup_py(argv[0])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
Loading…
x
Reference in New Issue
Block a user