Skip to content

Commit

Permalink
Add Rust reshim (#11848)
Browse files Browse the repository at this point in the history
  • Loading branch information
ericholscher authored Dec 12, 2024
1 parent 0c556f5 commit cff4f15
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 3 deletions.
18 changes: 15 additions & 3 deletions readthedocs/doc_builder/director.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,14 +434,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 @@ -450,18 +452,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()):
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 @@ -1467,6 +1467,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

0 comments on commit cff4f15

Please sign in to comment.