-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Nox and get cookiecutter test working
- Loading branch information
1 parent
b324a1e
commit 9dbb20b
Showing
13 changed files
with
201 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: Run CI | ||
|
||
on: | ||
push: | ||
branches: main | ||
|
||
permissions: | ||
contents: read | ||
|
||
concurrency: | ||
group: ci | ||
cancel-in-progress: false | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.11' | ||
|
||
- name: Install Nox | ||
run: pip install nox | ||
|
||
- name: Run tests | ||
run: nox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import nox | ||
|
||
|
||
@nox.session | ||
def lint(session: nox.Session): | ||
session.install("favicons") # TODO: remove | ||
session.install(".[test]", "nox", "pyright") | ||
|
||
session.run("pyright", "--warnings") | ||
|
||
|
||
@nox.session | ||
def tests(session: nox.Session): | ||
session.install("favicons") # TODO: remove | ||
session.install(".[test]", "./test/_submodules/HexMod") | ||
|
||
# test cookiecutter last so the extra package install doesn't interfere | ||
session.run("pytest", "-k", "not test_cookiecutter") | ||
session.run("pytest", "-k", "test_cookiecutter") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,7 +70,7 @@ dev = [ | |
"black==23.7.0", | ||
"isort==5.12.0", | ||
"hatch", | ||
"build", | ||
"nox", | ||
] | ||
|
||
[project.urls] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,117 @@ | ||
# pyright: reportUnknownMemberType=false | ||
|
||
import json | ||
import subprocess | ||
import sys | ||
from pathlib import Path | ||
from textwrap import dedent | ||
|
||
from pytest import MonkeyPatch | ||
from pytest_cookies.plugin import Cookies | ||
|
||
from hexdoc._cli.app import render | ||
|
||
from .conftest import longrun | ||
|
||
|
||
@longrun | ||
def test_cookiecutter(cookies: Cookies, monkeypatch: MonkeyPatch): | ||
result = cookies.bake( | ||
{ | ||
"output_directory": "output", | ||
"modid": "mod", | ||
"pattern_regex": "hex_latest", | ||
"multiloader": False, | ||
"java_package": "com/package", | ||
"pattern_registry": "Patterns.java", | ||
} | ||
) | ||
|
||
assert result.exception is None | ||
assert result.project_path is not None | ||
|
||
monkeypatch.chdir(result.project_path) | ||
subprocess.run(["git", "init"], check=True) | ||
|
||
Path("gradle.properties").write_text( | ||
dedent( | ||
f"""\ | ||
modVersion=1.0.0 | ||
hexcastingVersion=0.11.1-7 | ||
minecraftVersion=1.20.1 | ||
""" | ||
) | ||
) | ||
|
||
java_root = Path("src/main/java/com/package") | ||
java_root.mkdir(parents=True) | ||
(java_root / "Patterns.java").touch() | ||
|
||
Path("src/generated/resources").mkdir(parents=True) | ||
|
||
book_root = Path( | ||
"src/main/resources/assets/hexcasting/patchouli_books/thehexbook/en_us" | ||
) | ||
book_root.mkdir(parents=True) | ||
|
||
category_root = book_root / "categories" | ||
category_root.mkdir(parents=True) | ||
with open(category_root / "foo.json", "w") as f: | ||
json.dump( | ||
{ | ||
"name": "hexdoc.mod.title", | ||
"icon": "minecraft:amethyst_shard", | ||
"description": "hexcasting.category.basics.desc", | ||
"sortnum": 0, | ||
}, | ||
f, | ||
) | ||
|
||
entry_root = book_root / "entries" | ||
(entry_root / "foo").mkdir(parents=True) | ||
with open(entry_root / "foo" / "bar.json", "w") as f: | ||
json.dump( | ||
{ | ||
"name": "hexdoc.welcome.header", | ||
"category": "hexcasting:foo", | ||
"icon": "minecraft:textures/mob_effect/nausea.png", | ||
"sortnum": 0, | ||
"advancement": "hexcasting:y_u_no_cast_angy", | ||
"pages": [ | ||
{ | ||
"type": "patchouli:text", | ||
"text": "hexcasting.page.couldnt_cast.1", | ||
}, | ||
], | ||
}, | ||
f, | ||
) | ||
|
||
(result.project_path / ".env").write_text( | ||
dedent( | ||
f"""\ | ||
GITHUB_REPOSITORY=GITHUB/REPOSITORY | ||
GITHUB_SHA=GITHUB_SHA | ||
GITHUB_PAGES_URL=GITHUB_PAGES_URL""" | ||
) | ||
) | ||
|
||
# TODO: remove when textures stop being broken | ||
with open(result.project_path / "doc" / "properties.toml", "a") as f: | ||
f.write( | ||
dedent( | ||
""" | ||
[textures] | ||
missing = [ | ||
"minecraft:*", | ||
"hexcasting:*", | ||
] | ||
""" | ||
) | ||
) | ||
|
||
monkeypatch.syspath_prepend(result.project_path / "doc" / "src") | ||
|
||
import hexdoc_mod # type: ignore | ||
subprocess.run([sys.executable, "-m", "pip", "install", "-e", "."]) | ||
|
||
render() |
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,73 @@ | ||
modid = "{{ cookiecutter.modid }}" | ||
book = "hexcasting:thehexbook" | ||
book = "{{ cookiecutter.book_id }}" | ||
default_lang = "en_us" | ||
|
||
_export_root = "{{ cookiecutter.__export_root }}" | ||
resource_dirs = [ # top takes priority | ||
{ path="{^_export_root}/resources", reexport=false }, | ||
"resources", | ||
"{_common.src}/main/resources", | ||
"{_common.src}/generated/resources", | ||
{% if cookiecutter.multiloader -%} | ||
"{_fabric.src}/main/resources", | ||
"{_fabric.src}/generated/resources", | ||
"{_forge.src}/main/resources", | ||
"{_forge.src}/generated/resources", | ||
{%- endif %} | ||
{ modid="hexcasting" }, | ||
{ modid="hexdoc" }, | ||
] | ||
export_dir = "{_export_root}/generated" | ||
export_dir = "{{ cookiecutter.__export_root }}/generated" | ||
|
||
{# beware of eldritch abombinations lurking beneath these waters -#} | ||
[extra.hexcasting] | ||
# regexes for parsing pattern registry files - try uncommenting a different one if your patterns aren't loading | ||
# NOTE: "!Raw" means "don't apply variable interpolation to this value" | ||
{% if cookiecutter.pattern_regex == "hex_latest" -%} | ||
_pattern_regex = { "!Raw"='make\(\s*"(?P<name>[a-zA-Z0-9_\/]+)",\s*(?:new )?(?:ActionRegistryEntry|OperationAction)\(\s*HexPattern\.fromAngles\(\s*"(?P<signature>[aqweds]+)",\s*HexDir.(?P<startdir>\w+)\)' } | ||
{% elif cookiecutter.pattern_regex == "hex_0.10.3" -%} | ||
_pattern_regex = { "!Raw"='HexPattern\.fromAngles\("(?P<signature>[qweasd]+)", HexDir\.(?P<startdir>\w+)\),\s*modLoc\("(?P<name>[^"]+)"\)[^;]+?(?:makeConstantOp|Op\w+|Widget\.\w+)(?:[^;]*(?P<is_per_world>true)\);)?' } | ||
{% elif cookiecutter.pattern_regex == "hexal_0.3.0" -%} | ||
_pattern_regex = { "!Raw"='make\(\s*"(?P<name>[a-zA-Z0-9_\/]+)",\s*HexPattern\.fromAngles\(\s*"(?P<signature>[aqweds]+)",\s*HexDir.(?P<startdir>\w+)\)' } | ||
{% elif cookiecutter.pattern_regex == "hexal_0.2.18" -%} | ||
{#- :yea: -#} | ||
_pattern_regex = { "!Raw"='(?s-m:HexPattern\.fromAngles\("(?P<signature>[qweasd]+)", HexDir\.(?P<startdir>\w+)\),\s*modLoc\("(?P<name>[^"]+)"\),[^,]+?(?:makeConstantOp|Op\w+).*?(?P<is_per_world>\btrue)?\)(?:[^\)]+?\bval\b|(?:(?!\bval\b)(?:.))+$))' } | ||
{% else %} | ||
{# intentionally crash the template because we got an unhandled value #} | ||
{{ 0/0 }} | ||
{% endif %} | ||
|
||
[[pattern_stubs]] | ||
path = "{^_common.package}/TODO/TODO.java" | ||
# Hex Casting (0.11.0) | ||
{{ "# " if cookiecutter.pattern_regex != "hex_latest" }}_pattern_regex = { "!Raw"='make\(\s*"(?P<name>[a-zA-Z0-9_\/]+)",\s*(?:new )?(?:ActionRegistryEntry|OperationAction)\(\s*HexPattern\.fromAngles\(\s*"(?P<signature>[aqweds]+)",\s*HexDir.(?P<startdir>\w+)\)' } | ||
|
||
# Hex Casting (0.10.3) | ||
{{ "# " if cookiecutter.pattern_regex != "hex_0.10.3" }}_pattern_regex = { "!Raw"='HexPattern\.fromAngles\("(?P<signature>[qweasd]+)", HexDir\.(?P<startdir>\w+)\),\s*modLoc\("(?P<name>[^"]+)"\)[^;]+?(?:makeConstantOp|Op\w+|Widget\.\w+)(?:[^;]*(?P<is_per_world>true)\);)?' } | ||
|
||
# Hexal (0.3.0) | ||
{{ "# " if cookiecutter.pattern_regex != "hexal_0.3.0" }}_pattern_regex = { "!Raw"='make\(\s*"(?P<name>[a-zA-Z0-9_\/]+)",\s*HexPattern\.fromAngles\(\s*"(?P<signature>[aqweds]+)",\s*HexDir.(?P<startdir>\w+)\)' } | ||
|
||
# Hexal (0.2.18) | ||
{{ "# " if cookiecutter.pattern_regex != "hexal_0.2.18" }}_pattern_regex = { "!Raw"='(?s-m:HexPattern\.fromAngles\("(?P<signature>[qweasd]+)", HexDir\.(?P<startdir>\w+)\),\s*modLoc\("(?P<name>[^"]+)"\),[^,]+?(?:makeConstantOp|Op\w+).*?(?P<is_per_world>\btrue)?\)(?:[^\)]+?\bval\b|(?:(?!\bval\b)(?:.))+$))' } | ||
|
||
[[extra.hexcasting.pattern_stubs]] | ||
path = "{^^^_common.package}/{{ cookiecutter.pattern_registry }}" | ||
regex = "{^_pattern_regex}" | ||
|
||
[minecraft_assets] | ||
# https://github.com/PrismarineJS/minecraft-assets/tree/83e2169afbbce40990d69fc53e5962e4a793d467/data/1.19.1 | ||
ref = "83e2169afbbce40990d69fc53e5962e4a793d467" | ||
version = "1.19.1" | ||
|
||
[template] | ||
static_dir = "static" | ||
icon = "icon.png" | ||
include = [ | ||
"{{ cookiecutter.modid }}", | ||
"hexcasting", | ||
"patchouli", | ||
"hexdoc", | ||
] | ||
|
||
[template.args] | ||
mod_name = "{{ cookiecutter.mod_display_name }}" | ||
author = "{{ cookiecutter.author }}" | ||
icon_href = "icon.png" | ||
show_landing_text = false | ||
|
||
|
||
# platforms | ||
|
||
[_common] | ||
src = "../Common/src" | ||
package = "{src}/main/java/TODO/{{ cookiecutter.modid }}" | ||
src = "../{{ 'common/src' if cookiecutter.multiloader else 'src' }}" | ||
package = "{src}/main/{{ cookiecutter.java_lang }}/{{ cookiecutter.java_package }}" | ||
|
||
{% if cookiecutter.multiloader -%} | ||
[_fabric] | ||
src = "../Fabric/src" | ||
package = "{src}/main/java/TODO/{{ cookiecutter.modid }}/fabric" | ||
src = "../fabric/src" | ||
package = "{src}/main/{{ cookiecutter.java_lang }}/{{ cookiecutter.java_package }}/fabric" | ||
|
||
[_forge] | ||
src = "../Forge/src" | ||
package = "{src}/main/java/TODO/{{ cookiecutter.modid }}/forge" | ||
src = "../forge/src" | ||
package = "{src}/main/{{ cookiecutter.java_lang }}/{{ cookiecutter.java_package }}/forge" | ||
{%- endif %} |
File renamed without changes.
2 changes: 0 additions & 2 deletions
2
....output_directory}}/doc/src/{{cookiecutter.__project_slug}}/_export/resources/__init__.py
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters