Skip to content

Commit 909556c

Browse files
authored
Merge pull request #34 from CommanderBot-Dev/pack-tweaks
Hide stacktraces by default and add name argument to pack command
2 parents cf3bbed + a204c0d commit 909556c

File tree

5 files changed

+70
-44
lines changed

5 files changed

+70
-44
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [Unreleased]
8+
9+
## Changed
10+
11+
- Optional `pack` command argument for changing the name of the generated data pack or resource pack
12+
- The `pack` command no longer shows exception tracebacks by default
13+
714
## [0.9.0] - 2021-05-09
815

916
## Changed

commanderbot_ext/ext/pack/pack_cog.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import asyncio
22
import io
33
from logging import Logger, getLogger
4+
from typing import Optional
45

56
from discord import File, Message
67
from discord.ext.commands import Bot, Cog, Context, command
@@ -14,9 +15,13 @@ def __init__(self, bot: Bot, **options):
1415
self.log: Logger = getLogger(self.qualified_name)
1516
self.project_config = options
1617
self.build_timeout = options.pop("timeout", 5)
18+
self.show_stacktraces = options.pop("stacktraces", False)
1719

18-
@command(name="pack")
19-
async def cmd_pack(self, ctx: Context):
20+
@command(
21+
name="pack",
22+
brief="Generate a data pack or a resource pack.",
23+
)
24+
async def cmd_pack(self, ctx: Context, name: Optional[str]):
2025
if not ctx.message:
2126
self.log.warn("Command executed without message.")
2227
return
@@ -34,11 +39,12 @@ async def cmd_pack(self, ctx: Context):
3439
generate_packs,
3540
self.project_config,
3641
self.build_timeout,
37-
author,
42+
self.show_stacktraces,
43+
name or author,
3844
message_content,
3945
)
4046

41-
content = f"```{joined}```" if (joined := "\n\n".join(build_output)) else ""
47+
content = f"```\n{joined}\n```" if (joined := "\n\n".join(build_output)) else ""
4248
files = [
4349
File(io.BytesIO(data), filename=filename)
4450
for filename, data in attachments.items()

commanderbot_ext/ext/pack/pack_generate.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
)
1515
from beet.core.utils import JsonDict
1616
from beet.toolchain.utils import format_exc
17+
from jinja2 import TemplateError
1718
from lectern import Document
1819

1920
BuildResult = Tuple[List[str], Dict[str, bytes]]
@@ -22,12 +23,23 @@
2223
def generate_packs(
2324
project_config: JsonDict,
2425
build_timeout: float,
26+
show_stacktraces: bool,
2527
project_name: str,
2628
message_content: str,
2729
) -> BuildResult:
2830
q: "Queue[BuildResult]" = Queue()
2931

30-
p = Process(target=worker, args=(q, project_name, project_config, message_content))
32+
p = Process(
33+
target=worker,
34+
args=(
35+
q,
36+
project_name,
37+
project_config,
38+
message_content,
39+
show_stacktraces,
40+
),
41+
)
42+
3143
p.start()
3244
p.join(timeout=build_timeout)
3345

@@ -45,6 +57,7 @@ def worker(
4557
project_name: str,
4658
project_config: JsonDict,
4759
message_content: str,
60+
show_stacktraces: bool,
4861
):
4962
project_directory = os.getcwd()
5063

@@ -90,7 +103,26 @@ def worker(
90103
exception = exc
91104

92105
if exception:
93-
build_output.append(format_exc(exception))
106+
exc_name = type(exception).__name__
107+
108+
if show_stacktraces:
109+
build_output.append(format_exc(exception))
110+
elif isinstance(
111+
exception,
112+
(
113+
TypeError,
114+
ValueError,
115+
AttributeError,
116+
LookupError,
117+
ArithmeticError,
118+
TemplateError,
119+
),
120+
):
121+
build_output.append(f"{exc_name}: {exception}")
122+
else:
123+
build_output.append(
124+
f'{exc_name}: Enable the "stacktraces" option to see the full traceback.'
125+
)
94126

95127
q.put((build_output, {}))
96128

poetry.lock

Lines changed: 17 additions & 36 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ python = "^3.8"
1515
commanderbot = "^0.7.0"
1616
SQLAlchemy = "^1.4.9"
1717
aiosqlite = "^0.17.0"
18-
lectern = ">=0.11.1"
19-
beet = ">=0.22.1"
18+
lectern = ">=0.13.0"
19+
beet = ">=0.23.0"
2020

2121
[tool.poetry.dev-dependencies]
2222
black = "^20.8b1"

0 commit comments

Comments
 (0)