Skip to content

Commit

Permalink
Review
Browse files Browse the repository at this point in the history
  • Loading branch information
lasote committed Jul 22, 2019
1 parent c764179 commit 4f8c721
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 8 deletions.
5 changes: 3 additions & 2 deletions conans/model/graph_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,11 @@ def from_dict(data):
""" constructs a GraphLockNode from a json like dict
"""
json_pref = data["pref"]
pref = PackageReference.loads(json_pref) if json_pref else None
pref = PackageReference.loads(json_pref, validate=False) if json_pref else None
python_requires = data.get("python_requires")
if python_requires:
python_requires = [ConanFileReference.loads(ref) for ref in python_requires]
python_requires = [ConanFileReference.loads(ref, validate=False)
for ref in python_requires]
options = OptionsValues.loads(data["options"])
modified = data.get("modified")
requires = data.get("requires", {})
Expand Down
7 changes: 3 additions & 4 deletions conans/model/ref.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ class ConanFileReference(namedtuple("ConanFileReference", "name version user cha
""" Full reference of a package recipes, e.g.:
opencv/2.4.10@lasote/testing
"""
sep_pattern = re.compile(r"([^/]+)/([^/]+)@([^/]+)/([^/#]+)#?(.+)?")

def __new__(cls, name, version, user, channel, revision=None, validate=True):
"""Simple name creation.
Expand Down Expand Up @@ -176,12 +175,12 @@ def _validate(self):
if self.revision is not None:
ConanName.validate_revision(self.revision)

if not self.name or not self.version:
raise InvalidNameException("Specify the 'name' and the 'version'")

if (self.user and not self.channel) or (self.channel and not self.user):
raise InvalidNameException("Specify the 'user' and the 'channel' or neither of them")

if self.revision and not (self.user and self.channel and self.name and self.version):
raise InvalidNameException("A reference with revision has to specify all the fields")

@staticmethod
def loads(text, validate=True):
""" Parses a text string to generate a ConanFileReference object
Expand Down
2 changes: 1 addition & 1 deletion conans/test/functional/command/export_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ class MyPkg(ConanFile):
""")
client.save({"conanfile.py": conanfile})
client.run('export .')
folder = client.cache.package_layout(ConanFileReference.loads("lib/1.0@")).export()
client.cache.package_layout(ConanFileReference.loads("lib/1.0@")).export()
self.assertIn("lib/1.0: A new conanfile.py version was exported", client.out)

# Do it twice
Expand Down
2 changes: 2 additions & 0 deletions conans/test/functional/command/install_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,8 @@ class MyPkg(ConanFile):

# This fails, Conan thinks this is a path
client.run('install lib/1.0', assert_error=True)
fake_path = os.path.join(client.current_folder, "lib", "1.0")
self.assertIn("Conanfile not found at {}".format(fake_path), client.out)

# Try this syntax to upload too
client.run('install lib/1.0@')
Expand Down
2 changes: 1 addition & 1 deletion conans/test/functional/graph_lock/graph_lock_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ def build(self):
client.save({"conanfile.py": consumer})

def _check_lock(self, ref_b):
ref_b = repr(ConanFileReference.loads(ref_b))
ref_b = repr(ConanFileReference.loads(ref_b, validate=False))
lock_file = load(os.path.join(self.client.current_folder, LOCKFILE))
self.assertIn("Tool/0.1@user/channel", lock_file)
self.assertNotIn("Tool/0.2@user/channel", lock_file)
Expand Down
8 changes: 8 additions & 0 deletions conans/test/unittests/model/ref_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def basic_test(self):
self.assertEqual(ref.revision, "rev1")

def errors_test(self):
self.assertRaises(ConanException, ConanFileReference.loads, "")
self.assertIsNone(ConanFileReference.loads("opencv/2.4.10@", validate=False).channel)
self.assertIsNone(ConanFileReference.loads("opencv/2.4.10@", validate=False).user)
self.assertRaises(ConanException, ConanFileReference.loads, "opencv/2.4.10@lasote")
Expand Down Expand Up @@ -65,6 +66,13 @@ def revisions_test(self):
self.assertEqual(ref.channel, "testing")
self.assertEqual(ref.revision, "23")

ref = ConanFileReference.loads("opencv/2.4.10#23")
self.assertIsNone(ref.channel)
self.assertIsNone(ref.user)
self.assertEqual(ref.name, "opencv")
self.assertEqual(ref.version, "2.4.10")
self.assertEqual(ref.revision, "23")

ref = ConanFileReference("opencv", "2.3", "lasote", "testing", "34")
self.assertEqual(ref.revision, "34")

Expand Down

0 comments on commit 4f8c721

Please sign in to comment.