diff --git a/README.md b/README.md index df317d5f..e1c135b1 100644 --- a/README.md +++ b/README.md @@ -87,4 +87,8 @@ nox --no-install # after the first Nox run, use this to skip reinstalling every # update test snapshots nox -- --snapshot-update + +# run hexdoc commands in an isolated environment to ensure it works on its own +nox -s hexdoc -- export +nox -s hexdoc -- repl ``` diff --git a/noxfile.py b/noxfile.py index 83706a63..67f4fee4 100644 --- a/noxfile.py +++ b/noxfile.py @@ -1,5 +1,13 @@ import nox +nox.options.sessions = ["tests"] + + +@nox.session(reuse_venv=True) +def hexdoc(session: nox.Session): + session.install(".") + session.run("hexdoc", *session.posargs) + @nox.session(reuse_venv=True) def tests(session: nox.Session): diff --git a/src/hexdoc/_cli/utils/load.py b/src/hexdoc/_cli/utils/load.py index ccabf2dc..5d49dbc2 100644 --- a/src/hexdoc/_cli/utils/load.py +++ b/src/hexdoc/_cli/utils/load.py @@ -27,7 +27,12 @@ def load_common_data(props_file: Path, verbosity: int): pm = PluginManager() version = load_version(props, pm) - MinecraftVersion.MINECRAFT_VERSION = pm.minecraft_version() + minecraft_version = MinecraftVersion.MINECRAFT_VERSION = pm.minecraft_version() + if minecraft_version is None: + logging.getLogger(__name__).warning( + "No plugins implement hexdoc_minecraft_version, " + "per-version validation will fail" + ) return props, pm, version diff --git a/src/hexdoc/_hooks.py b/src/hexdoc/_hooks.py index fc1039fd..9ec46406 100644 --- a/src/hexdoc/_hooks.py +++ b/src/hexdoc/_hooks.py @@ -7,14 +7,12 @@ HookReturn, LoadJinjaTemplatesImpl, LoadResourceDirsImpl, - MinecraftVersionImpl, ModVersionImpl, hookimpl, ) class HexdocPlugin( - MinecraftVersionImpl, ModVersionImpl, LoadResourceDirsImpl, LoadJinjaTemplatesImpl, @@ -25,11 +23,6 @@ class HexdocPlugin( def hexdoc_mod_version(): return "(TODO: remove)" - @staticmethod - @hookimpl - def hexdoc_minecraft_version() -> str: - return "1.20.1" # TODO: remove - @staticmethod @hookimpl def hexdoc_load_resource_dirs() -> HookReturn[Package]: diff --git a/src/hexdoc/core/compat.py b/src/hexdoc/core/compat.py index 43f338f6..fc6f2791 100644 --- a/src/hexdoc/core/compat.py +++ b/src/hexdoc/core/compat.py @@ -31,11 +31,16 @@ def matches(cls, specifier: str | SpecifierSet) -> bool: class MinecraftVersion(VersionSource): - MINECRAFT_VERSION: ClassVar[str] + MINECRAFT_VERSION: ClassVar[str | None] = None @override @classmethod - def get(cls): + def get(cls) -> str: + if cls.MINECRAFT_VERSION is None: + raise RuntimeError( + "Tried to call MinecraftVersion.get() " + "before initializing MinecraftVersion.MINECRAFT_VERSION" + ) return cls.MINECRAFT_VERSION @override @@ -43,7 +48,7 @@ def get(cls): def matches(cls, specifier: str | SpecifierSet) -> bool: if isinstance(specifier, str): specifier = SpecifierSet(specifier) - return cls.MINECRAFT_VERSION in specifier + return cls.get() in specifier @dataclass(frozen=True) diff --git a/src/hexdoc/plugin/manager.py b/src/hexdoc/plugin/manager.py index a5663a75..2ddcfcd3 100644 --- a/src/hexdoc/plugin/manager.py +++ b/src/hexdoc/plugin/manager.py @@ -95,7 +95,7 @@ def __init__(self) -> None: def mod_version(self, modid: str): return self._hook_caller(PluginSpec.hexdoc_mod_version, modid)() - def minecraft_version(self) -> str: + def minecraft_version(self) -> str | None: versions = dict[str, str]() for modid, caller in self._all_callers(PluginSpec.hexdoc_minecraft_version): @@ -113,7 +113,7 @@ def minecraft_version(self) -> str: match len(set(versions.values())): case 0: - raise ValueError("No plugins implement hexdoc_minecraft_version") + return None case 1: return versions.popitem()[1] case n: diff --git a/test/_submodules/HexMod b/test/_submodules/HexMod index c20bf015..9007e7be 160000 --- a/test/_submodules/HexMod +++ b/test/_submodules/HexMod @@ -1 +1 @@ -Subproject commit c20bf015778aaf1d44c47523f891b2580361a8ee +Subproject commit 9007e7be6c210f9e31e30c202e89542fb54ea8e8