Skip to content

Commit

Permalink
Accept a list for the requires attribute (#5371)
Browse files Browse the repository at this point in the history
* accept a list for the requires attribute

* use list for requires in a real conanfile
  • Loading branch information
jgsogo authored and danimtb committed Jun 19, 2019
1 parent cad452a commit 4a2e7fb
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 3 deletions.
2 changes: 1 addition & 1 deletion conans/model/conan_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def create_requirements(conanfile):
else:
if not conanfile.requires:
return Requirements()
if isinstance(conanfile.requires, tuple):
if isinstance(conanfile.requires, (tuple, list)):
return Requirements(*conanfile.requires)
else:
return Requirements(conanfile.requires, )
Expand Down
2 changes: 1 addition & 1 deletion conans/test/integration/conan_test_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test(conanfile_test, test_reference, path=None):
from conans import ConanFile
class HelloTestConan(ConanFile):
requires = "Hello/0.1@conan/stable"
requires = ["Hello/0.1@conan/stable", ]
def test(self):
self.output.warn("Tested ok!")
''', "Hello/0.1@conan/stable")
Expand Down
2 changes: 1 addition & 1 deletion conans/test/integration/order_libs_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def package_info(self):

conanfile = """from conans import ConanFile
class LibCConan(ConanFile):
requires = ("LibB/0.1@user/channel", "private"), "LibC/0.1@user/channel"
requires = [("LibB/0.1@user/channel", "private"), "LibC/0.1@user/channel"]
"""
client.save({"conanfile.py": conanfile})
client.run("install . -g cmake")
Expand Down
Empty file.
49 changes: 49 additions & 0 deletions conans/test/unittests/model/conan_file/create_requirements_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# coding=utf-8

import unittest
from collections import namedtuple

from conans.model.conan_file import create_requirements

MockConanFile = namedtuple("MockConanFile", ["requires", ])


class TupleTest(unittest.TestCase):

def test_implicit_tuple(self):
requires = "req/1.0@user/version", "req2/1.0@user/version"
self.assertEqual(type(requires), tuple)
conanfile = MockConanFile(requires=requires)
r = create_requirements(conanfile)
self.assertListEqual(list(r.keys()), ["req", "req2"])

def test_tuple(self):
requires = ("req/1.0@user/version", "req2/1.0@user/version")
self.assertEqual(type(requires), tuple)
conanfile = MockConanFile(requires=requires)
r = create_requirements(conanfile)
self.assertListEqual(list(r.keys()), ["req", "req2"])

def test_config_tuple(self):
requires = (("req/1.0@user/version", "private"), )
self.assertEqual(type(requires), tuple)
conanfile = MockConanFile(requires=requires)
r = create_requirements(conanfile)
self.assertListEqual(list(r.keys()), ["req", ])


class ListTest(unittest.TestCase):

def test_list(self):
requires = ["req/1.0@user/version", "req2/1.0@user/version"]
self.assertEqual(type(requires), list)
conanfile = MockConanFile(requires=requires)
r = create_requirements(conanfile)
self.assertListEqual(list(r.keys()), ["req", "req2"])

def test_config_list(self):
requires = [("req/1.0@user/version", "private"), ]
self.assertEqual(type(requires), list)
conanfile = MockConanFile(requires=requires)
r = create_requirements(conanfile)
self.assertListEqual(list(r.keys()), ["req", ])

0 comments on commit 4a2e7fb

Please sign in to comment.