forked from Bard-Gaming/Minecraft-Script
-
Notifications
You must be signed in to change notification settings - Fork 0
Update project configuration and documentation #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,77 @@ | ||
| name: Release | ||
|
|
||
| on: | ||
| push: | ||
| tags: | ||
| - "v*" | ||
|
|
||
| jobs: | ||
| verify: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 | ||
| with: | ||
| persist-credentials: false | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5 | ||
| with: | ||
| python-version: "3.12" | ||
|
|
||
| - name: Set up uv | ||
| uses: astral-sh/setup-uv@d4b2f3b6ecc6e67c4457f6d3e41ec42d3d0fcb86 # v5 | ||
|
|
||
| - name: Install dependencies | ||
| run: | | ||
| uv venv | ||
| uv pip install -r requirements.txt -r requirements-dev.txt -e . | ||
|
|
||
| - name: Check release versions | ||
| run: python scripts/check_release_versions.py --tag "${{ github.ref_name }}" | ||
|
|
||
| - name: Run tests | ||
| run: uv run pytest -q | ||
|
|
||
| publish-npm: | ||
| needs: verify | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 | ||
| with: | ||
| persist-credentials: false | ||
|
|
||
| - name: Set up Node.js | ||
| uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4 | ||
| with: | ||
| node-version: "20" | ||
| registry-url: "https://registry.npmjs.org" | ||
|
|
||
| - name: Verify npm package version matches tag | ||
| run: | | ||
| TAG_VERSION="${GITHUB_REF_NAME#v}" | ||
| NPM_VERSION="$(node -p "require('./npm/package.json').version")" | ||
| if [ "$TAG_VERSION" != "$NPM_VERSION" ]; then | ||
| echo "Tag version ($TAG_VERSION) does not match npm/package.json ($NPM_VERSION)" | ||
| exit 1 | ||
| fi | ||
|
|
||
| - name: Publish to npm | ||
| working-directory: npm | ||
| run: npm publish --access public | ||
| env: | ||
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
|
|
||
| github-release: | ||
| needs: [verify, publish-npm] | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: write | ||
| steps: | ||
| - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Create GitHub release | ||
| uses: softprops/action-gh-release@3bb12739c298aeb8a4eeaf626c5b8d85266b0e65 # v2 | ||
| with: | ||
| generate_release_notes: true | ||
This file contains hidden or 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,4 +1,5 @@ | ||
| .idea/ | ||
| .venv/ | ||
| twine_upload | ||
| setup.py | ||
| test_file.py | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -134,12 +134,37 @@ def __init__(self, datapack_id): | |||||||||||||||||||||
| self.version = get_version_context() | ||||||||||||||||||||||
| self.commands = CompileCommands() | ||||||||||||||||||||||
| self.used_context_ids = set() | ||||||||||||||||||||||
| self.functions_to_generate = set() | ||||||||||||||||||||||
| self.defined_functions: dict[str, MCSFunction] = {} | ||||||||||||||||||||||
| self.generated_functions: set[MCSFunction] = set() | ||||||||||||||||||||||
| self.pending_function_generation: list[MCSFunction] = [] | ||||||||||||||||||||||
| self.click_item_lookup = dict() | ||||||||||||||||||||||
| self.used_math_builtins = set() | ||||||||||||||||||||||
| self.used_builtin_functions = set() | ||||||||||||||||||||||
| self.scoreboard_event_functions = [] | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def schedule_function_generation(self, function: MCSFunction) -> None: | ||||||||||||||||||||||
| if function.body is None: | ||||||||||||||||||||||
| return | ||||||||||||||||||||||
| if function in self.generated_functions: | ||||||||||||||||||||||
| return | ||||||||||||||||||||||
| if function not in self.pending_function_generation: | ||||||||||||||||||||||
| self.pending_function_generation.append(function) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def generate_scheduled_functions(self) -> None: | ||||||||||||||||||||||
| for entry_name in ("init", "main", "kill"): | ||||||||||||||||||||||
| function = self.defined_functions.get(entry_name) | ||||||||||||||||||||||
| if function is not None: | ||||||||||||||||||||||
| self.schedule_function_generation(function) | ||||||||||||||||||||||
| for function in self.scoreboard_event_functions: | ||||||||||||||||||||||
| self.schedule_function_generation(function) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| while self.pending_function_generation: | ||||||||||||||||||||||
| function = self.pending_function_generation.pop(0) | ||||||||||||||||||||||
| if function in self.generated_functions: | ||||||||||||||||||||||
| continue | ||||||||||||||||||||||
| self.generated_functions.add(function) | ||||||||||||||||||||||
| function.generate_function(self) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def get_scoreboard_event_hooks(self) -> list[dict[str, str]]: | ||||||||||||||||||||||
| hooks = [] | ||||||||||||||||||||||
| for index, function in enumerate(self.scoreboard_event_functions): | ||||||||||||||||||||||
|
|
@@ -206,9 +231,10 @@ def visit_DefineFunctionNode(self, node, context: CompileContext) -> CompileResu | |||||||||||||||||||||
| if SCOREBOARD_CRITERIA_PATTERN.fullmatch(event_criteria) is None: | ||||||||||||||||||||||
| raise ValueError(f"Invalid scoreboard criteria {event_criteria!r}") | ||||||||||||||||||||||
| function = MCSFunction(context.get_function_name(fnc_name), fnc_body, fnc_parameter_names, context, event_criteria) | ||||||||||||||||||||||
| self.functions_to_generate.add(function) | ||||||||||||||||||||||
| self.defined_functions[function.name] = function | ||||||||||||||||||||||
| if event_criteria is not None: | ||||||||||||||||||||||
| self.scoreboard_event_functions.append(function) | ||||||||||||||||||||||
| self.schedule_function_generation(function) | ||||||||||||||||||||||
| context.declare(fnc_name, function) | ||||||||||||||||||||||
| return CompileResult(function) | ||||||||||||||||||||||
| def visit_VariableDeclareNode(self, node, context: CompileContext) -> CompileResult: | ||||||||||||||||||||||
|
|
@@ -459,11 +485,13 @@ def visit_ImportNode(self, node, context: CompileContext) -> CompileResult: | |||||||||||||||||||||
| def visit_FunctionCallNode(self, node, context: CompileContext) -> CompileResult: | ||||||||||||||||||||||
| fnc: MCSFunction = self.visit(node.get_root(), context).get_value() | ||||||||||||||||||||||
| arguments: tuple[mcs_type, ...] = tuple(map(lambda x: self.visit(x, context).get_value(), node.get_arguments())) | ||||||||||||||||||||||
| commands, return_value = fnc.call(self, arguments, context) | ||||||||||||||||||||||
| is_builtin = ( | ||||||||||||||||||||||
| hasattr(fnc.call, "__module__") and | ||||||||||||||||||||||
| fnc.call.__module__.endswith(".builtin_functions") | ||||||||||||||||||||||
| is_builtin = ( | ||||||||||||||||||||||
| hasattr(fnc.call, "__module__") | ||||||||||||||||||||||
| and fnc.call.__module__.endswith(".builtin_functions") | ||||||||||||||||||||||
| ) | ||||||||||||||||||||||
| if not is_builtin and fnc.body is not None: | ||||||||||||||||||||||
| self.schedule_function_generation(fnc) | ||||||||||||||||||||||
| commands, return_value = fnc.call(self, arguments, context) | ||||||||||||||||||||||
|
Comment on lines
+492
to
+494
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1: Tree-shaken function scheduling misses callback functions passed into builtins like Prompt for AI agents
Suggested change
|
||||||||||||||||||||||
| if is_builtin: | ||||||||||||||||||||||
| self.used_builtin_functions.add(fnc.call.__name__) | ||||||||||||||||||||||
| if commands is not None: | ||||||||||||||||||||||
|
|
@@ -533,8 +561,7 @@ def _mcs_compile(ast, functions_dir: str, datapack_id): | |||||||||||||||||||||
| context = CompileContext('init', top_level=True) | ||||||||||||||||||||||
| interpreter = CompileInterpreter(datapack_id) | ||||||||||||||||||||||
| interpreter.visit(ast, context) | ||||||||||||||||||||||
| for mcs_fnc in interpreter.functions_to_generate: | ||||||||||||||||||||||
| mcs_fnc.generate_function(interpreter) | ||||||||||||||||||||||
| interpreter.generate_scheduled_functions() | ||||||||||||||||||||||
| version = get_version_context() | ||||||||||||||||||||||
| for context_id in interpreter.used_context_ids: | ||||||||||||||||||||||
| commands = [] | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.