Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions arcade/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from arcade.management import show_info
from arcade.cli import run_arcade_cli

if __name__ == "__main__":
show_info()
run_arcade_cli()
1 change: 1 addition & 0 deletions arcade/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .cli import run_arcade_cli
57 changes: 57 additions & 0 deletions arcade/cli/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import argparse
import sys
from typing import Type

from .commands import BaseCommand, InfoCommand


class CLI:
def __init__(self):
self.commands: dict[str, BaseCommand] = {}
self.prog: str = "arcade"
self.description: str = "Arcade Game Library CLI"

def register_command(self, command_class: Type[BaseCommand]) -> None:
command = command_class() # type: ignore BaseCommand has different constructor than it's implementations
self.commands[command.name] = command

def create_parser(self) -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(
prog=self.prog,
description=self.description,
formatter_class=argparse.RawDescriptionHelpFormatter,
)

subparsers = parser.add_subparsers(dest="command", help="Available commands")

for command_name, command in self.commands.items():
command_parser = subparsers.add_parser(
command_name,
help=command.help,
description=command.description,
formatter_class=argparse.RawDescriptionHelpFormatter,
)
command.add_arguments(command_parser)

return parser

def run(self) -> int:
parser = self.create_parser()
args = parser.parse_args()

if args.command is None:
parser.print_help()
return 0

try:
command = self.commands[args.command]
return command.handle(args)
except Exception as e:
print(f"Error: {e}", file=sys.stderr)
return 1


def run_arcade_cli():
cli = CLI()
cli.register_command(InfoCommand)
return cli.run()
4 changes: 4 additions & 0 deletions arcade/cli/commands/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from .base import BaseCommand
from .info import InfoCommand

__all__ = ["BaseCommand", "InfoCommand"]
21 changes: 21 additions & 0 deletions arcade/cli/commands/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import argparse
from abc import ABC, abstractmethod


class BaseCommand(ABC):
name: str
description: str
help: str

def __init__(self, name: str, description: str, help: str) -> None:
self.name = name
self.description = description
self.help = help

@abstractmethod
def add_arguments(self, parser: argparse.ArgumentParser) -> None:
pass

@abstractmethod
def handle(self, args: argparse.Namespace) -> int:
pass
36 changes: 36 additions & 0 deletions arcade/cli/commands/info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import argparse
import sys

import PIL
import pyglet

import arcade

from .base import BaseCommand


class InfoCommand(BaseCommand):
def __init__(self):
super().__init__(
name="info",
description="Print Arcade and System Information",
help="Print information about the installed Arcade version and system specifications",
)

def add_arguments(self, parser: argparse.ArgumentParser) -> None:
pass

def handle(self, args: argparse.Namespace) -> int:
window = arcade.Window(visible=False)
version_str = f"Arcade {arcade.__version__}"
print()
print(version_str)
print("-" * len(version_str))
print("vendor:", window.ctx.info.VENDOR)
print("device:", window.ctx.info.RENDERER)
print("renderer:", window.ctx.info.CTX_INFO) # type: ignore
print("python:", sys.version)
print("platform:", sys.platform)
print("pyglet version:", pyglet.version)
print("PIL version:", PIL.__version__)
return 1
2 changes: 2 additions & 0 deletions arcade/gl/backends/opengl/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,8 @@ def __init__(self, ctx):
self.MAJOR_VERSION = self.get(gl.GL_MAJOR_VERSION)
"""Major version number of the OpenGL API supported by the current context."""

self.CTX_INFO = f"opengl {self.MAJOR_VERSION}.{self.MINOR_VERSION}"

self.MAX_COLOR_TEXTURE_SAMPLES = self.get(gl.GL_MAX_COLOR_TEXTURE_SAMPLES)
"""Maximum number of samples in a color multisample texture"""

Expand Down
1 change: 1 addition & 0 deletions arcade/gl/backends/webgl/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ class WebGLInfo(Info):
def __init__(self, ctx: WebGLContext):
super().__init__(ctx)
self._ctx = ctx
self.CTX_INFO = "webgl"

def get_int_tuple(self, enum, length: int):
# TODO: this might not work
Expand Down
48 changes: 0 additions & 48 deletions arcade/management/__init__.py

This file was deleted.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ dev = [
testing_libraries = ["pytest", "pytest-mock", "pytest-cov", "pyyaml==6.0.1"]

[project.scripts]
arcade = "arcade.management:execute_from_command_line"
arcade = "arcade.cli:run_arcade_cli"

[project.entry-points.pyinstaller40]
hook-dirs = "arcade.__pyinstaller:get_hook_dirs"
Expand Down
Loading