Skip to content

Commit

Permalink
Merge branch 'release/0.22.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
lasote committed Apr 20, 2017
2 parents c6cc15f + cf2817d commit 652b962
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 69 deletions.
3 changes: 1 addition & 2 deletions conans/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@
COMPLEX_SEARCH_CAPABILITY = "complex_search"
SERVER_CAPABILITIES = [COMPLEX_SEARCH_CAPABILITY, ]

__version__ = '0.22.1'

__version__ = '0.22.2'
68 changes: 38 additions & 30 deletions conans/model/ref.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,49 @@
import re
from conans.errors import ConanException, InvalidNameException
from conans.model.version import Version
from conans.model.username import Username


def _validate_conan_name(name, version=False):
"""Check for name compliance with pattern rules"""
if name == "*":
return
if ConanFileReference.validation_pattern.match(name) is None:
if version and name.startswith("[") and name.endswith("]"):
return
if len(name) > ConanFileReference.max_chars:
message = "'%s' is too long. Valid names must " \
"contain at most %s characters." % (name,
ConanFileReference.max_chars)
elif len(name) < ConanFileReference.min_chars:
message = "'%s' is too short. Valid names must contain"\
" at least %s characters." % (name, ConanFileReference.min_chars)
class ConanName(object):
_max_chars = 40
_min_chars = 2
_validation_pattern = re.compile("^[a-zA-Z0-9_][a-zA-Z0-9_\+\.-]{%s,%s}$"
% (_min_chars - 1, _max_chars))

@staticmethod
def invalid_name_message(name):
if len(name) > ConanName._max_chars:
message = ("'%s' is too long. Valid names must contain at most %s characters."
% (name, ConanName._max_chars))
elif len(name) < ConanName._min_chars:
message = ("'%s' is too short. Valid names must contain at least %s characters."
% (name, ConanName._min_chars))
else:
message = "'%s' is an invalid name. Valid names MUST begin with a "\
"letter or number, have between %s-%s chars, including "\
"letters, numbers, underscore,"\
" dot and dash" % (name, ConanFileReference.min_chars,
ConanFileReference.max_chars)
message = ("'%s' is an invalid name. Valid names MUST begin with a "
"letter or number, have between %s-%s chars, including "
"letters, numbers, underscore, dot and dash"
% (name, ConanName._min_chars, ConanName._max_chars))
raise InvalidNameException(message)

@staticmethod
def validate_user(username):
if ConanName._validation_pattern.match(username) is None:
ConanName.invalid_name_message(username)

@staticmethod
def validate_name(name, version=False):
"""Check for name compliance with pattern rules"""
if name == "*":
return
if ConanName._validation_pattern.match(name) is None:
if version and name.startswith("[") and name.endswith("]"):
return
ConanName.invalid_name_message(name)


class ConanFileReference(namedtuple("ConanFileReference", "name version user channel")):
""" Full reference of a conans, e.g.:
""" Full reference of a package recipes, e.g.:
opencv/2.4.10@lasote/testing
"""
max_chars = 40
min_chars = 2
base_er = "[a-zA-Z0-9_]+[a-zA-Z0-9_\+\.-]{%s,%s}" % (min_chars - 1, max_chars)
regular_expression = "^%s$" % base_er
validation_pattern = re.compile(regular_expression)
whitespace_pattern = re.compile(r"\s+")
sep_pattern = re.compile("@|/")

Expand All @@ -45,10 +53,10 @@ def __new__(cls, name, version, user, channel):
@param name: string containing the desired name
@param validate: checks for valid complex name. default True
"""
_validate_conan_name(name)
_validate_conan_name(version, True)
Username.validate(user, pattern=True)
_validate_conan_name(channel)
ConanName.validate_name(name)
ConanName.validate_name(version, True)
ConanName.validate_name(user)
ConanName.validate_name(channel)
version = Version(version)
return super(cls, ConanFileReference).__new__(cls, name, version, user, channel)

Expand Down
30 changes: 2 additions & 28 deletions conans/model/username.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,12 @@
from conans.errors import InvalidNameException
import re
from conans.model.ref import ConanName


class Username(str):

max_len = 30
min_len = 2
base_er = "[a-zA-Z][a-zA-Z0-9_-]{%s,%s}" % (min_len-1, max_len-1)
pattern = re.compile("^%s$" % base_er)

def __new__(cls, name):
"""Simple name creation.
@param name: string containing the desired name
@param validate: checks for valid simple name. default True
"""
Username.validate(name)
ConanName.validate_user(name)
return str.__new__(cls, name)

@staticmethod
def validate(name, pattern=False):
"""Check for name compliance with pattern rules. User names can be
with upper/lower case
"""
if Username.pattern.match(name) is None:
if pattern and name == "*":
return
if len(name) > Username.max_len:
message = "'%s' is too long. Valid names must contain at most %s characters." \
"" % (name, Username.max_len)
elif len(name) < Username.min_len:
message = "'%s' is too short. Valid names must contain at least %s characters." \
"" % (name, Username.min_len)
else:
message = "'%s' is an invalid name. "\
"Valid names should begin with alphanumerical characters, '_' and '-'." % name
raise InvalidNameException(message)
10 changes: 6 additions & 4 deletions conans/test/integration/conan_env_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from conans.test.utils.tools import TestClient
from conans.test.utils.cpp_test_files import cpp_hello_conan_files
from conans.util.files import load
from conans import tools


class ConanEnvTest(unittest.TestCase):
Expand Down Expand Up @@ -161,10 +162,11 @@ class HelloConan(ConanFile):
client.save(files, clean_first=True)
client.run("install --profile ./myprofile --build missing")

if platform.system() != "Windows":
ret = os.system("cd '%s' && chmod +x %s && ./%s" % (client.current_folder, "activate.sh", "activate.sh"))
else:
ret = os.system('cd "%s" && %s' % (client.current_folder, "activate.bat"))
with tools.chdir(client.current_folder):
if platform.system() != "Windows":
ret = os.system("chmod +x activate.sh && ./activate.sh")
else:
ret = os.system("activate.bat")
self.assertEquals(ret, 0)

def conan_env_deps_test(self):
Expand Down
17 changes: 16 additions & 1 deletion conans/test/model/ref_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,26 @@ def basic_test(self):
self.assertEqual(ref.channel, "testing")
self.assertEqual(str(ref), "opencv_lite/2.4.10@phil_lewis/testing")

ref = ConanFileReference.loads("opencv/2.4.10@3rd-party/testing")
self.assertEqual(ref.name, "opencv")
self.assertEqual(ref.version, "2.4.10")
self.assertEqual(ref.user, "3rd-party")
self.assertEqual(ref.channel, "testing")
self.assertEqual(str(ref), "opencv/2.4.10@3rd-party/testing")

def errors_test(self):
self.assertRaises(ConanException, ConanFileReference.loads, "")
self.assertRaises(ConanException, ConanFileReference.loads, "opencv/2.4.10")
self.assertRaises(ConanException, ConanFileReference.loads, "opencv/2.4.10 @ lasote")
self.assertRaises(ConanException, ConanFileReference.loads, "opencv??/2.4.10@laso/testing")
self.assertRaises(ConanException, ConanFileReference.loads, ".opencv/2.4.10@lasote/testing")
self.assertRaises(ConanException, ConanFileReference.loads, "o/2.4.10 @ lasote/testing")
self.assertRaises(ConanException, ConanFileReference.loads, "lib/1.0@user.surname/channel")
self.assertRaises(ConanException, ConanFileReference.loads, "lib/1.0@user&surname/channel")
self.assertRaises(ConanException, ConanFileReference.loads,
"opencv%s/2.4.10@laso/testing" % "A" * 40)
self.assertRaises(ConanException, ConanFileReference.loads,
"opencv/2.4.10%s@laso/testing" % "A" * 40)
self.assertRaises(ConanException, ConanFileReference.loads,
"opencv/2.4.10@laso%s/testing" % "A" * 40)
self.assertRaises(ConanException, ConanFileReference.loads,
"opencv/2.4.10@laso/testing%s" % "A" * 40)
11 changes: 7 additions & 4 deletions conans/test/model/username_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ class UsernameTest(unittest.TestCase):
def username_test(self):
Username("userwith-hypens")
self.assertRaises(ConanException, Username, "")
self.assertRaises(ConanException, Username, "A"*31)
self.assertRaises(ConanException, Username, "a")
self.assertRaises(ConanException, Username, "A"*42)
Username("A"*30)

self.assertRaises(ConanException, Username, "1A")
self.assertRaises(ConanException, Username, "_A")
self.assertRaises(ConanException, Username, "-A")
self.assertRaises(ConanException, Username, "&A")
Username("A1")
Username("1A")
Username("_A")
Username("a_")

self.assertRaises(ConanException, Username, "$$")
self.assertRaises(ConanException, Username, "$$")

0 comments on commit 652b962

Please sign in to comment.