Skip to content

Commit 6f34900

Browse files
committed
fixed cli, formatted code and changed text/example
1 parent 17d75f1 commit 6f34900

6 files changed

Lines changed: 54 additions & 33 deletions

File tree

.github/workflows/publish.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ jobs:
88
runs-on: ubuntu-latest
99
steps:
1010
- uses: actions/checkout@v2
11+
- name: Setup Python
12+
- uses: actions/setup-python@v4
13+
with:
14+
python-version: "3.10.8"
1115
- name: Build and publish to pypi
1216
uses: JRubics/poetry-publish@v1.13
1317
with:

pymcfunction/cli.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,30 +127,38 @@ def compile():
127127

128128
lines = []
129129
imports = ""
130-
for x in statements:
131-
if x.split(" ")[0] in ["import", "from"]:
132-
imports += x + "\n"
133-
statements.remove(x)
134-
elif x == "##pymcfunction-tick":
130+
removelist = []
131+
for s in statements:
132+
if s.split(" ")[0] in ["import", "from"]:
133+
imports += s + "\n"
134+
removelist.append(s)
135+
if s == "##pymcfunction-tick":
135136
specialFunctions["tick"].append(
136137
config["namespace"] + ":" + f.removesuffix(".py")
137138
)
138-
elif x == "##pymcfunction-load":
139+
elif s == "##pymcfunction-load":
139140
specialFunctions["load"].append(
140141
config["namespace"] + ":" + f.removesuffix(".py")
141142
)
142-
if len(x) > 0:
143-
if x[0] == "#":
144-
statements.remove(x)
143+
if len(s) > 0:
144+
if s[0] == "#":
145+
removelist.append(s)
146+
147+
# Yes, this is needed because of weird python behaviour
148+
for r in removelist:
149+
statements.remove(r)
145150

146151
for s in statements:
152+
code = imports + "\n_output = " + s + "\nprint(_output)"
147153
try:
148154
stdout = StringIO()
149155
with redirect_stdout(stdout):
150-
exec(imports + "\n_output = " + s + "\nprint(_output)")
156+
exec(code)
151157
lines.append(stdout.getvalue().strip("\n"))
152-
except Exception:
153-
print(f"\nError while compiling {f}!")
158+
except Exception as e:
159+
print("\n" + str(e) + "\n\nCode used:\n" + code)
160+
print(f"\n\nError while compiling {f}!")
161+
print(statements)
154162
raise typer.Abort()
155163
# Write to file
156164
Path(os.path.split(out)[0]).mkdir(parents=True, exist_ok=True)

pymcfunction/commands/simple.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from pymcfunction.types import Gamemode, Weather
22

33

4-
def say(msg):
4+
def say(msg: str):
55
return "say " + str(msg)
66

77

@@ -100,5 +100,6 @@ def pardon(player: str):
100100
def pardon_ip(ip: str):
101101
return "pardon " + ip
102102

103-
def teammsg(msg:str):
104-
return "teammsg " + msg
103+
104+
def teammsg(msg: str):
105+
return "teammsg " + msg

pymcfunction/commands/team.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@ def create(self, displayName: str = None):
77

88
def listTeams(self):
99
return "team list"
10-
10+
1111
def listMembers(self):
1212
return "team list " + self.name
13-
13+
1414
def remove(self):
1515
return "team remove " + self.name
16-
16+
1717
def empty(self):
1818
return "team emtpy " + self.name
19-
20-
def join(self, target:str="@s"):
19+
20+
def join(self, target: str = "@s"):
2121
return f"team join {self.name} {target}"
22-
23-
def leave(self, target:str):
22+
23+
def leave(self, target: str):
2424
return f"team leave {target}"
25-
26-
def modify(self, option:str, value:str):
27-
return f"team modify {self.name} {option} {value}"
25+
26+
def modify(self, option: str, value: str):
27+
return f"team modify {self.name} {option} {value}"

pymcfunction/commands/teleport.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
from pymcfunction.types import AnchorType
22

3+
34
class teleport:
4-
def __init__(self, target:str="@s") -> None:
5+
def __init__(self, target: str = "@s") -> None:
56
self.target = target
6-
7-
def destination(self, coord:str, rotation:float|int=None):
8-
return f"teleport {self.target} {coord}" + ((" " + str(rotation)) if rotation else "")
97

10-
def facingCoordinate(self, coord:str, facing:str):
8+
def destination(self, coord: str, rotation: float | int = None):
9+
return f"teleport {self.target} {coord}" + (
10+
(" " + str(rotation)) if rotation else ""
11+
)
12+
13+
def facingCoordinate(self, coord: str, facing: str):
1114
return f"teleport {self.target} {coord} facing {facing}"
12-
13-
def facingEntity(self, coord:str, facingEntity:str, anchor:AnchorType=AnchorType.EYES):
14-
return f"teleport {self.target} {coord} facing entity {facingEntity} {anchor.value}"
15+
16+
def facingEntity(
17+
self, coord: str, facingEntity: str, anchor: AnchorType = AnchorType.EYES
18+
):
19+
return f"teleport {self.target} {coord} facing entity {facingEntity} {anchor.value}"

test/data/ticker.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
##pymcfunction-tick
2+
from pymcfunction import *
3+
4+
say("TICK")

0 commit comments

Comments
 (0)