Skip to content

Commit

Permalink
Merge pull request #31 from Schulich-Ignite/dev
Browse files Browse the repository at this point in the history
Release 0.0.12
  • Loading branch information
raduschirliu authored Oct 24, 2020
2 parents 33445d2 + f476d79 commit 73158b5
Show file tree
Hide file tree
Showing 4 changed files with 858 additions and 78 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="schulich-ignite",
version="0.0.11",
version="0.0.12",
author="Schulich Ignite",
author_email="[email protected]",
description="Spark library for Shulich Ignite sessions",
Expand Down
13 changes: 7 additions & 6 deletions spark/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def __init__(self, globals_dict):
"default": "#888888"
}
match_255 = r"(?:(?:2(?:(?:5[0-5])|(?:[0-4][0-9])))|(?:[01]?[0-9]{1,2}))"
match_alpha = r"(?:1(?:\.0*)?)|(?:0(?:\.[0-9]*)?)"
match_alpha = r"(?:(?:1(?:\.0*)?)|(?:0(?:\.[0-9]*)?))"
match_360 = r"(?:(?:3[0-5][0-9])|(?:[0-2]?[0-9]{1,2}))"
match_100 = r"(?:100|[0-9]{1,2})"
self.regexes = [
Expand Down Expand Up @@ -455,23 +455,24 @@ def parse_color(self, func_name, *args):

if argc == 1:
if type(args[0]) is int:
return "rgb({}, {}, {})".format(args[0], args[0], args[0])
return "rgb({}, {}, {})".format(*np.clip([args[0]] * 3, 0, 255))
elif not type(args[0]) is str:
raise TypeError(
"Enter colour value in a valid format, e.g. #FF0000, rgb(255, 0, 0), or hsl(0, 100%, 50%)"
)
return self.parse_color_string(func_name, args[0])
elif argc == 3 or argc == 4:
color_args = args[:3]
for col, name in zip(color_args, ["r","g","b"]):
self.check_int_is_ranged(col, 0, 255, func_name, name)
for color_arg, arg_name in zip(color_args, ["r", "g", "b"]):
self.check_type_is_int(color_arg, func_name=func_name, arg_name=arg_name)
color_args = np.clip(color_args, 0, 255)

if argc == 3:
return "rgb({}, {}, {})".format(*color_args)
else:
# Clip alpha between 0 and 1
alpha_arg = args[3]
self.check_float_is_ranged(alpha_arg, 0, 1, func_name, "a")
self.check_type_is_num(alpha_arg, func_name=func_name, arg_name="a")
# Clip alpha between 0 and 1
alpha_arg = np.clip(alpha_arg, 0, 1.0)
return "rgba({}, {}, {}, {})".format(*color_args, alpha_arg)
else:
Expand Down
19 changes: 10 additions & 9 deletions spark/util/Errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,19 @@ def __init__(self, func_name, argument_name, allowed_types, actual_type, arg):
argname = "type"
type_str = ""
if type(allowed_types) == list:
if len(allowed_types) == 1:
type_str += str(allowed_types[0])
elif len(allowed_types) == 2:
type_str += "{} or {}".format(*allowed_types)
allowed_type_names = [t.__name__ for t in allowed_types]
if len(allowed_type_names) == 1:
type_str += allowed_type_names[0]
elif len(allowed_type_names) == 2:
type_str += "{} or {}".format(*allowed_type_names)
else:
type_str = (", ".join("{}"*(len(allowed_types)-1))).format(*allowed_types[:-1])
type_str += ", or {}".format(allowed_types[-1])
type_str = ", ".join([str(t) for t in allowed_type_names[:-1]])
type_str += ", or {}".format(allowed_type_names[-1])
else:
type_str = str(allowed_types)
type_str = str(allowed_type_names)

self.message = "{} expected {} {}, got {} of type {}".format(
func_name, argname, type_str, arg, actual_type)
func_name, argname, type_str, arg, actual_type.__name__)
super().__init__(self.message)


Expand All @@ -38,7 +39,7 @@ def __init__(self, func_name, allowed_nums, actual_num):
elif len(allowed_nums) == 2:
num_str += "{} or {}".format(*allowed_nums)
else:
num_str = (", ".join("{}"*(len(allowed_nums)-1))).format(*allowed_nums[:-1])
num_str = ", ".join([str(n) for n in allowed_nums[:-1]])
num_str += ", or {}".format(allowed_nums[-1])
else:
num_str = str(allowed_nums)
Expand Down
Loading

0 comments on commit 73158b5

Please sign in to comment.