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

Add Rust reshim #11848

Merged
merged 3 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
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
18 changes: 15 additions & 3 deletions readthedocs/doc_builder/director.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,14 +442,16 @@ def check_old_output_directory(self):
def run_build_commands(self):
"""Runs each build command in the build environment."""

reshim_commands = (
python_reshim_commands = (
{"pip", "install"},
{"conda", "create"},
{"conda", "install"},
{"mamba", "create"},
{"mamba", "install"},
{"poetry", "install"},
)
rust_reshim_commands = ({"cargo", "install"},)

cwd = self.data.project.checkout_path(self.data.version.slug)
environment = self.build_environment
for command in self.data.config.build.commands:
Expand All @@ -458,18 +460,28 @@ def run_build_commands(self):
# Execute ``asdf reshim python`` if the user is installing a
# package since the package may contain an executable
# See https://github.com/readthedocs/readthedocs.org/pull/9150#discussion_r882849790
for reshim_command in reshim_commands:
for python_reshim_command in python_reshim_commands:
# Convert tuple/list into set to check reshim command is a
# subset of the command itself. This is to find ``pip install``
# but also ``pip -v install`` and ``python -m pip install``
if reshim_command.issubset(command.split()):
if python_reshim_command.issubset(command.split()):
environment.run(
*["asdf", "reshim", "python"],
escape_command=False,
cwd=cwd,
record=False,
)

# Do same for Rust
for rust_reshim_command in rust_reshim_commands:
if rust_reshim_command.issubset(command.split()):
ericholscher marked this conversation as resolved.
Show resolved Hide resolved
environment.run(
*["asdf", "reshim", "rust"],
escape_command=False,
cwd=cwd,
record=False,
)

html_output_path = os.path.join(cwd, BUILD_COMMANDS_OUTPUT_PATH_HTML)
if not os.path.exists(html_output_path):
raise BuildUserError(BuildUserError.BUILD_COMMANDS_WITHOUT_OUTPUT)
Expand Down
50 changes: 50 additions & 0 deletions readthedocs/projects/tests/test_build_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1468,6 +1468,56 @@ def test_build_commands(self, load_yaml_config):
]
)

@mock.patch("readthedocs.doc_builder.director.load_yaml_config")
def test_reshim_rust(self, load_yaml_config):
config = BuildConfigV2(
{
"version": 2,
"build": {
"os": "ubuntu-22.04",
"tools": {
"rust": "latest",
},
"commands": [
"cargo install mdbook",
"mdbook build",
],
},
},
source_file="readthedocs.yml",
)
config.validate()
load_yaml_config.return_value = config

self._trigger_update_docs_task()

rust_version = settings.RTD_DOCKER_BUILD_SETTINGS["tools"]["rust"]["latest"]
self.mocker.mocks["environment.run"].assert_has_calls(
[
mock.call("asdf", "install", "rust", rust_version),
mock.call("asdf", "global", "rust", rust_version),
mock.call("asdf", "reshim", "rust", record=False),
mock.call(
"cargo install mdbook",
escape_command=False,
cwd=mock.ANY,
),
mock.call(
"asdf",
"reshim",
"rust",
escape_command=False,
record=False,
cwd=mock.ANY,
),
mock.call(
"mdbook build",
escape_command=False,
cwd=mock.ANY,
),
]
)

@mock.patch("readthedocs.doc_builder.director.load_yaml_config")
def test_requirements_from_config_file_installed(self, load_yaml_config):
load_yaml_config.return_value = get_build_config(
Expand Down