Skip to content

Commit ce76f0e

Browse files
committed
Fix formatting errors
Signed-off-by: Tushar Goel <tushar.goel.dav@gmail.com>
1 parent 308d645 commit ce76f0e

6 files changed

Lines changed: 175 additions & 127 deletions

File tree

src/univers/conan/errors.py

Lines changed: 63 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,19 @@
1313

1414
@contextmanager
1515
def conanfile_remove_attr(conanfile, names, method):
16-
""" remove some self.xxxx attribute from the class, so it raises an exception if used
16+
"""remove some self.xxxx attribute from the class, so it raises an exception if used
1717
within a given conanfile method
1818
"""
1919
original_class = type(conanfile)
2020

2121
def _prop(attr_name):
2222
def _m(_):
2323
raise ConanException(f"'self.{attr_name}' access in '{method}()' method is forbidden")
24+
2425
return property(_m)
2526

2627
try:
27-
new_class = type(original_class.__name__, (original_class, ), {})
28+
new_class = type(original_class.__name__, (original_class,), {})
2829
conanfile.__class__ = new_class
2930
for name in names:
3031
setattr(new_class, name, _prop(name))
@@ -40,9 +41,12 @@ def conanfile_exception_formatter(conanfile_name, func_name):
4041
"""
4142

4243
def _raise_conanfile_exc(e):
43-
from conan.api.output import LEVEL_DEBUG, conan_output_level
44+
from conan.api.output import LEVEL_DEBUG
45+
from conan.api.output import conan_output_level
46+
4447
if conan_output_level <= LEVEL_DEBUG:
4548
import traceback
49+
4650
raise ConanExceptionInUserConanfileMethod(traceback.format_exc())
4751
m = _format_conanfile_exception(conanfile_name, func_name, e)
4852
raise ConanExceptionInUserConanfileMethod(m)
@@ -54,12 +58,17 @@ def _raise_conanfile_exc(e):
5458
msg = "{}: Invalid configuration: {}".format(str(conanfile_name), exc)
5559
raise ConanInvalidConfiguration(msg)
5660
except AttributeError as exc:
57-
list_methods = [m for m in dir(list) if not m.startswith('__')]
58-
if "NoneType" in str(exc) and func_name in ['layout', 'package_info'] and \
59-
any(method in str(exc) for method in list_methods):
60-
raise ConanException("{}: {}. No default values are set for components. You are probably "
61-
"trying to manipulate a component attribute in the '{}' method "
62-
"without defining it previously".format(str(conanfile_name), exc, func_name))
61+
list_methods = [m for m in dir(list) if not m.startswith("__")]
62+
if (
63+
"NoneType" in str(exc)
64+
and func_name in ["layout", "package_info"]
65+
and any(method in str(exc) for method in list_methods)
66+
):
67+
raise ConanException(
68+
"{}: {}. No default values are set for components. You are probably "
69+
"trying to manipulate a component attribute in the '{}' method "
70+
"without defining it previously".format(str(conanfile_name), exc, func_name)
71+
)
6372
else:
6473
_raise_conanfile_exc(exc)
6574
except Exception as exc:
@@ -74,6 +83,7 @@ def _format_conanfile_exception(scope, method, exception):
7483
"""
7584
import sys
7685
import traceback
86+
7787
try:
7888
conanfile_reached = False
7989
tb = sys.exc_info()[2]
@@ -91,8 +101,11 @@ def _format_conanfile_exception(scope, method, exception):
91101
msg = "%s: Error in %s() method" % (scope, method)
92102
msg += ", line %d\n\t%s" % (line, contents)
93103
else:
94-
msg = ("while calling '%s', line %d\n\t%s" % (name, line, contents)
95-
if line else "\n\t%s" % contents)
104+
msg = (
105+
"while calling '%s', line %d\n\t%s" % (name, line, contents)
106+
if line
107+
else "\n\t%s" % contents
108+
)
96109
content_lines.append(msg)
97110
conanfile_reached = True
98111
index += 1
@@ -105,8 +118,9 @@ def _format_conanfile_exception(scope, method, exception):
105118

106119
class ConanException(Exception):
107120
"""
108-
Generic conans exception
121+
Generic conans exception
109122
"""
123+
110124
def __init__(self, *args, **kwargs):
111125
self.info = None
112126
self.remote = kwargs.pop("remote", None)
@@ -119,6 +133,7 @@ def remote_message(self):
119133

120134
def __str__(self):
121135
from conans.util.files import exception_message_safe
136+
122137
msg = super(ConanException, self).__str__()
123138
if self.remote:
124139
return "{}.{}".format(exception_message_safe(msg), self.remote_message())
@@ -127,18 +142,20 @@ def __str__(self):
127142

128143

129144
class ConanReferenceDoesNotExistInDB(ConanException):
130-
""" Reference does not exist in cache db """
145+
"""Reference does not exist in cache db"""
146+
131147
pass
132148

133149

134150
class ConanReferenceAlreadyExistsInDB(ConanException):
135-
""" Reference already exists in cache db """
151+
"""Reference already exists in cache db"""
152+
136153
pass
137154

138155

139156
class NoRemoteAvailable(ConanException):
140-
""" No default remote configured or the specified remote do not exists
141-
"""
157+
"""No default remote configured or the specified remote do not exists"""
158+
142159
pass
143160

144161

@@ -162,6 +179,7 @@ class ConanInvalidConfiguration(ConanExceptionInUserConanfileMethod):
162179
"""
163180
This binary, for the requested configuration and package-id cannot be built
164181
"""
182+
165183
pass
166184

167185

@@ -172,35 +190,39 @@ class ConanMigrationError(ConanException):
172190
# Remote exceptions #
173191
class InternalErrorException(ConanException):
174192
"""
175-
Generic 500 error
193+
Generic 500 error
176194
"""
195+
177196
pass
178197

179198

180199
class RequestErrorException(ConanException):
181200
"""
182-
Generic 400 error
201+
Generic 400 error
183202
"""
203+
184204
pass
185205

186206

187207
class AuthenticationException(ConanException): # 401
188208
"""
189-
401 error
209+
401 error
190210
"""
211+
191212
pass
192213

193214

194215
class ForbiddenException(ConanException): # 403
195216
"""
196-
403 error
217+
403 error
197218
"""
219+
198220
pass
199221

200222

201223
class NotFoundException(ConanException): # 404
202224
"""
203-
404 error
225+
404 error
204226
"""
205227

206228
def __init__(self, *args, **kwargs):
@@ -209,10 +231,12 @@ def __init__(self, *args, **kwargs):
209231

210232

211233
class RecipeNotFoundException(NotFoundException):
212-
213234
def __init__(self, ref, remote=None):
214235
from conans.model.recipe_ref import RecipeReference
215-
assert isinstance(ref, RecipeReference), "RecipeNotFoundException requires a RecipeReference"
236+
237+
assert isinstance(
238+
ref, RecipeReference
239+
), "RecipeNotFoundException requires a RecipeReference"
216240
self.ref = ref
217241
super(RecipeNotFoundException, self).__init__(remote=remote)
218242

@@ -222,31 +246,35 @@ def __str__(self):
222246

223247

224248
class PackageNotFoundException(NotFoundException):
225-
226249
def __init__(self, pref, remote=None):
227250
from conans.model.package_ref import PkgReference
251+
228252
assert isinstance(pref, PkgReference), "PackageNotFoundException requires a PkgReference"
229253
self.pref = pref
230254

231255
super(PackageNotFoundException, self).__init__(remote=remote)
232256

233257
def __str__(self):
234-
return "Binary package not found: '{}'{}".format(self.pref.repr_notime(),
235-
self.remote_message())
258+
return "Binary package not found: '{}'{}".format(
259+
self.pref.repr_notime(), self.remote_message()
260+
)
236261

237262

238263
class UserInterfaceErrorException(RequestErrorException):
239264
"""
240-
420 error
265+
420 error
241266
"""
267+
242268
pass
243269

244270

245-
EXCEPTION_CODE_MAPPING = {InternalErrorException: 500,
246-
RequestErrorException: 400,
247-
AuthenticationException: 401,
248-
ForbiddenException: 403,
249-
NotFoundException: 404,
250-
RecipeNotFoundException: 404,
251-
PackageNotFoundException: 404,
252-
UserInterfaceErrorException: 420}
271+
EXCEPTION_CODE_MAPPING = {
272+
InternalErrorException: 500,
273+
RequestErrorException: 400,
274+
AuthenticationException: 401,
275+
ForbiddenException: 403,
276+
NotFoundException: 404,
277+
RecipeNotFoundException: 404,
278+
PackageNotFoundException: 404,
279+
UserInterfaceErrorException: 420,
280+
}

src/univers/conan/version.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55

66
@total_ordering
77
class _VersionItem:
8-
""" a single "digit" in a version, like X.Y.Z all X and Y and Z are VersionItems
8+
"""a single "digit" in a version, like X.Y.Z all X and Y and Z are VersionItems
99
They can be int or strings
1010
"""
11+
1112
def __init__(self, item):
1213
try:
1314
self._v = int(item)
@@ -51,6 +52,7 @@ class Version:
5152
This is NOT an implementation of semver, as users may use any pattern in their versions.
5253
It is just a helper to parse "." or "-" and compare taking into account integers when possible
5354
"""
55+
5456
def __init__(self, value):
5557
value = str(value)
5658
self._value = value
@@ -93,7 +95,7 @@ def bump(self, index):
9395
# better not make it public yet, keep it internal
9496
items = list(self._items[:index])
9597
try:
96-
items.append(self._items[index]+1)
98+
items.append(self._items[index] + 1)
9799
except TypeError:
98100
raise ConanException(f"Cannot bump '{self._value} version index {index}, not an int")
99101
items.extend([0] * (len(items) - index - 1))
@@ -166,8 +168,11 @@ def __eq__(self, other):
166168
if not isinstance(other, Version):
167169
other = Version(other)
168170

169-
return (self._nonzero_items, self._pre, self._build) ==\
170-
(other._nonzero_items, other._pre, other._build)
171+
return (self._nonzero_items, self._pre, self._build) == (
172+
other._nonzero_items,
173+
other._pre,
174+
other._build,
175+
)
171176

172177
def __hash__(self):
173178
return hash((self._nonzero_items, self._pre, self._build))
@@ -180,16 +185,23 @@ def __lt__(self, other):
180185

181186
if self._pre:
182187
if other._pre: # both are pre-releases
183-
return (self._nonzero_items, self._pre, self._build) < \
184-
(other._nonzero_items, other._pre, other._build)
188+
return (self._nonzero_items, self._pre, self._build) < (
189+
other._nonzero_items,
190+
other._pre,
191+
other._build,
192+
)
185193
else: # Left hand is pre-release, right side is regular
186-
if self._nonzero_items == other._nonzero_items: # Problem only happens if both equal
194+
if (
195+
self._nonzero_items == other._nonzero_items
196+
): # Problem only happens if both equal
187197
return True
188198
else:
189199
return self._nonzero_items < other._nonzero_items
190200
else:
191201
if other._pre: # Left hand is regular, right side is pre-release
192-
if self._nonzero_items == other._nonzero_items: # Problem only happens if both equal
202+
if (
203+
self._nonzero_items == other._nonzero_items
204+
): # Problem only happens if both equal
193205
return False
194206
else:
195207
return self._nonzero_items < other._nonzero_items

src/univers/conan/version_range.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33
from univers.conan.errors import ConanException
44
from univers.conan.version import Version
55

6-
76
_Condition = namedtuple("_Condition", ["operator", "version"])
87

98

109
class _ConditionSet:
11-
1210
def __init__(self, expression, prerelease):
1311
expressions = expression.split()
1412
self.prerelease = prerelease

tests/test_conan_version_bump.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
from univers.conan.version import Version
44

55
values = [
6-
['1.0.0', 0, "2.0.0"],
7-
['1.1.0', 0, "2.0.0"],
8-
['1.1.1-pre', 0, "2.0.0"],
9-
['1.1.1', 1, "1.2.0"],
10-
['1.1.1', 2, "1.1.2"],
6+
["1.0.0", 0, "2.0.0"],
7+
["1.1.0", 0, "2.0.0"],
8+
["1.1.1-pre", 0, "2.0.0"],
9+
["1.1.1", 1, "1.2.0"],
10+
["1.1.1", 2, "1.1.2"],
1111
]
1212

1313

0 commit comments

Comments
 (0)