Skip to content

Commit

Permalink
Comply to pep8 (PR)
Browse files Browse the repository at this point in the history
  • Loading branch information
WingedSeal committed Aug 1, 2023
1 parent f109185 commit 5c0934c
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 49 deletions.
5 changes: 3 additions & 2 deletions src/jmc/compile/command/builtin_function/execute_excluded.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def _hardcode_parse(calc_pos: int, string: str, token: Token,
elif char == ")":
count -= 1

if char not in {"0", "1", "2", "3", "4", "5", "6", "7",
if char not in {"0", "1", "2", "3", "4", "5", "6", "7",
"8", "9", "+", "-", "*", "/", "\\", "%",
" ", "\t", "\n", "(", ")"}:
raise JMCSyntaxException(
Expand All @@ -36,7 +36,8 @@ def _hardcode_parse(calc_pos: int, string: str, token: Token,
raise JMCSyntaxException(
"Invalid syntax in Hardcode.calc", token, tokenizer, display_col_length=False)

return string[:calc_pos] + eval_expr(expression.replace("\\", "//")) + string[index + 13:]
return string[:calc_pos] + \
eval_expr(expression.replace("\\", "//")) + string[index + 13:]


def _hardcode_process(string: str, index_string: str,
Expand Down
55 changes: 28 additions & 27 deletions src/jmc/compile/command/builtin_function/load_only.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def call(self) -> str:
)
class ItemCreateSign(JMCFunction):
_VARIANTS = {"oak", "spruce", "birch", "jungle",
"acacia", "dark_oak", "crimson", "warped",
"acacia", "dark_oak", "crimson", "warped",
"mangrove", "bamboo", "cherry"}

def call(self) -> str:
Expand Down Expand Up @@ -1210,7 +1210,7 @@ def inner(arg: str) -> SIMPLE_JSON_BODY:
self.add_formatted_text_prop(
"clickEvent", inner, self.check_bool("local"))
return ""


@func_property(
func_type=FuncType.LOAD_ONLY,
Expand All @@ -1233,12 +1233,12 @@ def call(self) -> str:
"Unexpected empty URL",
self.raw_args["url"].token,
self.tokenizer)

self.add_formatted_text_prop(
"clickEvent", {
"action": "open_url", "value": self.args["url"]}, self.check_bool("local"))
return ""


@func_property(
func_type=FuncType.LOAD_ONLY,
Expand All @@ -1262,7 +1262,7 @@ def call(self) -> str:
"Unexpected empty URL",
self.raw_args["url"].token,
self.tokenizer)

@lru_cache()
def inner(arg: str) -> SIMPLE_JSON_BODY:
return {
Expand Down Expand Up @@ -1296,12 +1296,12 @@ def call(self) -> str:
"Unexpected empty page number",
self.raw_args["page"].token,
self.tokenizer)

self.add_formatted_text_prop(
"clickEvent", {
"action": "change_page", "value": self.args["page"]}, self.check_bool("local"))
return ""


@func_property(
func_type=FuncType.LOAD_ONLY,
Expand All @@ -1317,15 +1317,15 @@ def call(self) -> str:
)
class TextPropsClickPage(JMCFunction):
def call(self) -> str:

@lru_cache()
def inner(arg: str) -> SIMPLE_JSON_BODY:
return {
"action": "change_page", "value": arg}
self.add_formatted_text_prop(
"clickEvent", inner, self.check_bool("local"))
return ""


@func_property(
func_type=FuncType.LOAD_ONLY,
Expand All @@ -1348,12 +1348,12 @@ def call(self) -> str:
"Unexpected empty clipboard content",
self.raw_args["text"].token,
self.tokenizer)

self.add_formatted_text_prop(
"clickEvent", {
"action": "copy_to_clipboard", "value": self.args["text"]}, self.check_bool("local"))
return ""


@func_property(
func_type=FuncType.LOAD_ONLY,
Expand All @@ -1377,15 +1377,15 @@ def call(self) -> str:
"Unexpected emptyclipboard content",
self.raw_args["text"].token,
self.tokenizer)

@lru_cache()
def inner(arg: str) -> SIMPLE_JSON_BODY:
return {
"action": "copy_to_clipboard", "value": self.args["text"].replace(self.args["indexString"], arg)}
self.add_formatted_text_prop(
"clickEvent", inner, self.check_bool("local"))
return ""


@func_property(
func_type=FuncType.LOAD_ONLY,
Expand All @@ -1408,7 +1408,7 @@ def call(self) -> str:
"Unexpected empty FormattedText",
self.raw_args["text"].token,
self.tokenizer)

self.add_formatted_text_prop(
"hoverEvent", {
"action": "show_text", "contents": json.loads(self.format_text("text"))}, self.check_bool("local"))
Expand Down Expand Up @@ -1437,15 +1437,15 @@ def call(self) -> str:
"Unexpected empty FormattedText",
self.raw_args["text"].token,
self.tokenizer)

@lru_cache()
def inner(arg: str) -> SIMPLE_JSON_BODY:
return {
"action": "show_text", "contents": json.loads(self.format_text("text").replace(self.args["indexString"], arg))}
self.add_formatted_text_prop(
"hoverEvent", inner, self.check_bool("local"))
return ""


@func_property(
func_type=FuncType.LOAD_ONLY,
Expand All @@ -1468,7 +1468,7 @@ def call(self) -> str:
"Missing item in TextProp.hoverItem",
self.raw_args["item"].token,
self.tokenizer)

self.add_formatted_text_prop(
"hoverEvent", {
"action": "show_item", "contents": json.loads(self.args["item"])}, self.check_bool("local"))
Expand Down Expand Up @@ -1497,7 +1497,7 @@ def call(self) -> str:
"Missing item in TextProps.hoverItem",
self.raw_args["item"].token,
self.tokenizer)

@lru_cache()
def inner(arg: str) -> SIMPLE_JSON_BODY:
return {
Expand Down Expand Up @@ -1528,7 +1528,7 @@ def call(self) -> str:
"Missing entity in TextProp.hoverEntity",
self.raw_args["entity"].token,
self.tokenizer)

self.add_formatted_text_prop(
"hoverEvent", {
"action": "show_entity", "contents": json.loads(self.args["entity"])}, self.check_bool("local"))
Expand Down Expand Up @@ -1557,7 +1557,7 @@ def call(self) -> str:
"Missing entity in TextProps.hoverEntity",
self.raw_args["entity"].token,
self.tokenizer)

@lru_cache()
def inner(arg: str) -> SIMPLE_JSON_BODY:
return {
Expand Down Expand Up @@ -1588,7 +1588,7 @@ def call(self) -> str:
"Missing font in TextProp.font",
self.raw_args["font"].token,
self.tokenizer)

self.add_formatted_text_prop(
"font", self.args["font"], self.check_bool("local"))
return ""
Expand Down Expand Up @@ -1616,14 +1616,14 @@ def call(self) -> str:
"Missing font in TextProps.font",
self.raw_args["font"].token,
self.tokenizer)

@lru_cache()
def inner(arg: str) -> SIMPLE_JSON_BODY:
return self.args["font"].replace(self.args["indexString"], arg)
self.add_formatted_text_prop(
"font", inner, self.check_bool("local"))
return ""


@func_property(
func_type=FuncType.LOAD_ONLY,
Expand Down Expand Up @@ -1682,7 +1682,7 @@ def inner(arg: str) -> SIMPLE_JSON_BODY:
"keybind", inner, self.check_bool("local"))
return ""


@func_property(
func_type=FuncType.LOAD_ONLY,
call_string="TextProp.nbt",
Expand Down Expand Up @@ -1722,7 +1722,7 @@ def call(self) -> str:
self.tokenizer)

self.add_formatted_text_prop(
"__private_nbt_expand__", {self.args["type"]: self.args["source"], "nbt": self.args["path"], "interpret": self.args["interpret"]}, self.check_bool("local"))
"__private_nbt_expand__", {self.args["type"]: self.args["source"], "nbt": self.args["path"], "interpret": self.args["interpret"]}, self.check_bool("local"))
return ""


Expand Down Expand Up @@ -1767,9 +1767,10 @@ def call(self) -> str:

@lru_cache()
def inner(arg: str) -> SIMPLE_JSON_BODY:
return {self.args["type"]: self.args["source"], "nbt": self.args["path"].replace(self.args["indexString"], arg), "interpret": self.args["interpret"]}
return {self.args["type"]: self.args["source"], "nbt": self.args["path"].replace(
self.args["indexString"], arg), "interpret": self.args["interpret"]}
self.add_formatted_text_prop(
"__private_nbt_expand__", inner, self.check_bool("local"))
"__private_nbt_expand__", inner, self.check_bool("local"))
return ""


Expand Down
32 changes: 16 additions & 16 deletions src/jmc/compile/command/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ def eval_expr(expr: str) -> str:


OPERATORS: dict[type, Callable[..., Any]] = {ast.Add: op.add, ast.Sub: op.sub, ast.Mult: op.mul,
ast.Div: op.truediv, ast.FloorDiv: op.floordiv, ast.Mod: op.mod,
ast.Div: op.truediv, ast.FloorDiv: op.floordiv, ast.Mod: op.mod,
ast.Pow: op.pow, ast.USub: op.neg}


Expand Down Expand Up @@ -599,14 +599,14 @@ def __parse_bracket(self) -> None:
key, json_body, is_local = self.datapack.data.formatted_text_prop[prop_]
if isinstance(json_body, dict) and 'nbt' in json_body.keys():
self.current_json[key] = {}
self.current_json[key]["nbt"] = json_body["nbt"](arg) # type: ignore
self.current_json[key]["interpret"] = json_body["interpret"](arg) # type: ignore
self.current_json[key]["nbt"] = json_body["nbt"](arg) # type: ignore # fmt: off
self.current_json[key]["interpret"] = json_body["interpret"](arg) # type: ignore # fmt: off
if "entity" in json_body.keys():
self.current_json[key]["entity"] = json_body["entity"] # type: ignore
self.current_json[key]["entity"] = json_body["entity"] # type: ignore # fmt: off
if "block" in json_body.keys():
self.current_json[key]["block"] = json_body["block"] # type: ignore
self.current_json[key]["block"] = json_body["block"] # type: ignore # fmt: off
if "storage" in json_body.keys():
self.current_json[key]["storage"] = json_body["storage"] # type: ignore
self.current_json[key]["storage"] = json_body["storage"] # type: ignore # fmt: off
elif not callable(json_body):
raise JMCValueError(
f"Custom property '{prop_}' expected no argument", self.token, self.tokenizer, suggestion="Remove '()'")
Expand Down Expand Up @@ -644,24 +644,24 @@ def __parse_bracket(self) -> None:
del self.current_json["text"]

if "__private_nbt_expand__" in self.current_json:
self.current_json["nbt"] = self.current_json["__private_nbt_expand__"]["nbt"] # type: ignore
self.current_json["interpret"] = self.current_json["__private_nbt_expand__"]["interpret"] # type: ignore
if "storage" in self.current_json["__private_nbt_expand__"]: # type: ignore
self.current_json["storage"] = self.current_json["__private_nbt_expand__"]["storage"] # type: ignore
if "block" in self.current_json["__private_nbt_expand__"]: # type: ignore
self.current_json["block"] = self.current_json["__private_nbt_expand__"]["block"] # type: ignore
if "entity" in self.current_json["__private_nbt_expand__"]: # type: ignore
self.current_json["entity"] = self.current_json["__private_nbt_expand__"]["entity"] # type: ignore
self.current_json["nbt"] = self.current_json["__private_nbt_expand__"]["nbt"] # type: ignore # fmt: off
self.current_json["interpret"] = self.current_json["__private_nbt_expand__"]["interpret"] # type: ignore # fmt: off
if "storage" in self.current_json["__private_nbt_expand__"]: # type: ignore # fmt: off
self.current_json["storage"] = self.current_json["__private_nbt_expand__"]["storage"] # type: ignore # fmt: off
if "block" in self.current_json["__private_nbt_expand__"]: # type: ignore # fmt: off
self.current_json["block"] = self.current_json["__private_nbt_expand__"]["block"] # type: ignore # fmt: off
if "entity" in self.current_json["__private_nbt_expand__"]: # type: ignore # fmt: off
self.current_json["entity"] = self.current_json["__private_nbt_expand__"]["entity"] # type: ignore # fmt: off
del self.current_json["__private_nbt_expand__"]

tmp_json: SIMPLE_JSON_TYPE = {"text": ""}
for prop_, value_ in self.current_json.items():
if prop_ in {"bold", "italic", "underlined",
if prop_ in {"bold", "italic", "underlined",
"strikethrough", "obfuscated", "color"}:
tmp_json[prop_] = value_
self.result.append(self.current_json)
self.current_json = tmp_json

def __parse_code(self, char: str) -> None:
"""
Parse color code
Expand Down
6 changes: 3 additions & 3 deletions src/jmc/compile/compiling.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,8 @@ def build(datapack: DataPack, config: "Configuration", is_delete: bool, cert_con
for func_path, func in datapack.functions.items():
namespace = func_path.split("/")[0]
if namespace in header.namespace_overrides:
path = output_folder / "data" / namespace / "functions" / \
(func_path[len(namespace)+1:] + ".mcfunction")
path = output_folder / "data" / namespace / "functions" / \
(func_path[len(namespace) + 1:] + ".mcfunction")
else:
path = namespace_folder / "functions" / (func_path + ".mcfunction")
content = post_process(func.content)
Expand All @@ -341,7 +341,7 @@ def build(datapack: DataPack, config: "Configuration", is_delete: bool, cert_con
namespace = json_path.split("/")[0]
if namespace in header.namespace_overrides:
path = output_folder / "data" / \
namespace / (json_path[len(namespace)+1:] + ".json")
namespace / (json_path[len(namespace) + 1:] + ".json")
else:
path = namespace_folder / (json_path + ".json")
if json:
Expand Down
3 changes: 2 additions & 1 deletion src/jmc/compile/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,8 @@ def parse_new(self, tokenizer: Tokenizer,

namespace = json_name.split("/")[0]
if namespace in Header().namespace_overrides:
json_path = namespace + "/" + json_type + "/" + json_name[len(namespace)+1:]
json_path = namespace + "/" + json_type + \
"/" + json_name[len(namespace) + 1:]
else:
json_path = json_type + "/" + json_name

Expand Down

0 comments on commit 5c0934c

Please sign in to comment.