Skip to content

Commit

Permalink
fix: use importlib_metadata for backwards compatibility, fix #14
Browse files Browse the repository at this point in the history
  • Loading branch information
wu-vincent committed Jun 3, 2024
1 parent 5112b81 commit 546aeaa
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 10 deletions.
1 change: 1 addition & 0 deletions include/bedrock/forward.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class LevelSoundManager;
class LevelStorage;
class Localization;
class LootTables;
class MapDataManager;
class MapItemSavedData;
class MaterialTypeHelper;
class MobEffectInstance;
Expand Down
1 change: 0 additions & 1 deletion include/bedrock/world/level/level_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
#include "bedrock/world/events/event_coordinator.h"
#include "bedrock/world/level/level_listener.h"
#include "bedrock/world/level/level_settings.h"
#include "bedrock/world/level/saveddata/maps/map_data_manager.h"

class ILevel : public Bedrock::EnableNonOwnerReferences {
public:
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ classifiers = [
]
dependencies = [
"click",
"importlib_metadata",
"importlib_resources",
"packaging",
"requests",
Expand Down
2 changes: 1 addition & 1 deletion python/src/endstone/_internal/plugin_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import site
import subprocess
import sys
from importlib.metadata import entry_points, metadata
from importlib_metadata import entry_points, metadata
from typing import List
from endstone import Server
from endstone.command import Command
Expand Down
14 changes: 6 additions & 8 deletions python/src/endstone/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,18 @@
import os
import shutil
import typing
import importlib_resources
from importlib_resources import files, as_file
from pathlib import Path
import tomlkit
from endstone._internal.endstone_python import (
Command,
CommandSender,
PluginDescription,
PluginLoader,
PluginLoadOrder,
PluginManager,
)
from endstone._internal.endstone_python import Plugin as _Plugin
from endstone._internal.endstone_python import PluginCommand as _PluginCommand
from endstone.command import CommandExecutor
from endstone.command import Command, CommandExecutor, CommandSender
from endstone.event import Event

__all__ = [
Expand All @@ -32,7 +30,7 @@ class PluginCommand(Command):
def __init__(self, impl: _PluginCommand) -> None:
Command.__init__(self, impl.name)
self._impl = impl
self._executor: CommandExecutor | None = None
self._executor: typing.Optional[CommandExecutor] = None

@property
def executor(self) -> CommandExecutor:
Expand Down Expand Up @@ -139,7 +137,7 @@ class Plugin(_Plugin):

def __init__(self):
_Plugin.__init__(self)
self._description: PluginDescription | None = None
self._description: typing.Optional[PluginDescription] = None
self._plugin_commands: dict[_PluginCommand, PluginCommand] = {}
self._config = None

Expand Down Expand Up @@ -222,8 +220,8 @@ def save_resources(self, path: str, replace: bool = False) -> None:
out_path = Path(self.data_folder) / path
if not out_path.exists() or replace:
out_path.parent.mkdir(exist_ok=True)
resource = importlib_resources.files(self.__class__.__module__).joinpath(path)
with importlib_resources.as_file(resource) as f:
resource = files(self.__class__.__module__).joinpath(path)
with as_file(resource) as f:
shutil.copy(f, out_path)
else:
self.logger.warning(f"Could not save {out_path.name} to {out_path}: file already exists.")
Expand Down

0 comments on commit 546aeaa

Please sign in to comment.