Skip to content
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

Download and manage gdtoolkit when it is not found #7

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
15 changes: 15 additions & 0 deletions addons/format_on_save/format_on_save.gd
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,21 @@ func on_resource_saved(resource: Resource):
if current_script == script:
var filepath: String = ProjectSettings.globalize_path(resource.resource_path)

# Download and manage gdtoolkit when it is not found globally
var exec_path: String = "gdformat"
if OS.execute(exec_path, ["--version"]) != SUCCESS:
var major_version: int = Engine.get_version_info().major
var python_path: String = (
"%s/python"
% ProjectSettings.globalize_path(get_script().resource_path.get_base_dir())
)
exec_path = "%s/bin/gdformat" % python_path
if not FileAccess.file_exists(exec_path):
OS.execute(
"pip3",
["install", "gdtoolkit==%d.*" % major_version, "--target=%s" % python_path]
)

# Run gdformat
var exit_code = OS.execute("gdformat", [filepath])

Expand Down