Treat requirements special in the superrepo

We don't want to try and make a requirements package. But we do want to
use it as the source of constraints for all the collected repos.

Change-Id: I984f71f81451f0695d7e86a6cfccc555a89c4ee7
This commit is contained in:
Clint Byrum 2016-07-13 17:32:49 -07:00
parent 8a9592d40e
commit 169b858a83
2 changed files with 22 additions and 2 deletions

View File

@ -13,7 +13,6 @@
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
import os import os
import git import git
@ -57,6 +56,14 @@ class BuildSpec(object):
# Nope, detach head # Nope, detach head
repo.head.reference = repo.commit(self.version) repo.head.reference = repo.commit(self.version)
for subdir in os.listdir(repo.working_tree_dir): for subdir in os.listdir(repo.working_tree_dir):
# requirements is special
if subdir == 'requirements':
reqdir = os.path.join(
repo.working_tree_dir, 'requirements')
reqfile = os.path.join(reqdir, 'upper-constraints.txt')
if reqfile not in self.settings.constraints:
self.settings.constraints.append(reqfile)
continue
# Skip any projects explicitly in the manifest # Skip any projects explicitly in the manifest
if subdir in existing_project_names: if subdir in existing_project_names:
continue continue

View File

@ -65,7 +65,8 @@ class TestBuildSpec(unittest.TestCase):
@utils.make_test_repo("parentrepo") @utils.make_test_repo("parentrepo")
@utils.make_test_repo("childrepo") @utils.make_test_repo("childrepo")
def test_build_spec_superrepo(self, parentrepo, childrepo): @utils.make_test_repo("reqrepo")
def test_build_spec_superrepo(self, parentrepo, childrepo, reqrepo):
parentrepo = git.Repo(parentrepo) parentrepo = git.Repo(parentrepo)
childname = os.path.basename(childrepo) childname = os.path.basename(childrepo)
with open(os.path.join(childrepo, 'setup.py'), 'w') as setup: with open(os.path.join(childrepo, 'setup.py'), 'w') as setup:
@ -76,6 +77,14 @@ class TestBuildSpec(unittest.TestCase):
parentrepo.create_submodule(childname, childname, parentrepo.create_submodule(childname, childname,
url=childrepo.working_tree_dir) url=childrepo.working_tree_dir)
parentrepo.index.commit('adding child repo') parentrepo.index.commit('adding child repo')
constraints_path = os.path.join(reqrepo, 'upper-constraints.txt')
with open(constraints_path, 'w') as cf:
cf.write("foo==1.0\n{}==11.0\n".format(childname))
reqrepo = git.Repo(reqrepo)
reqrepo.index.add(['upper-constraints.txt'])
reqrepo.index.commit('adding upper constraints')
parentrepo.create_submodule('requirements', 'requirements',
url=reqrepo.working_tree_dir)
parenthash = parentrepo.head.commit.hexsha parenthash = parentrepo.head.commit.hexsha
childhash = childrepo.head.commit.hexsha childhash = childrepo.head.commit.hexsha
manifest = { manifest = {
@ -91,3 +100,7 @@ class TestBuildSpec(unittest.TestCase):
self.assertEqual(childhash, bs.projects[0].gitref) self.assertEqual(childhash, bs.projects[0].gitref)
child_path = os.path.join(parentrepo.working_tree_dir, childname) child_path = os.path.join(parentrepo.working_tree_dir, childname)
self.assertEqual(child_path, bs.projects[0].giturl) self.assertEqual(child_path, bs.projects[0].giturl)
constraints_added = os.path.join(parentrepo.working_tree_dir,
'requirements',
'upper-constraints.txt')
self.assertIn(constraints_added, bs.settings.constraints)