Skip to content

Commit cff4f15

Browse files
authored
Add Rust reshim (#11848)
1 parent 0c556f5 commit cff4f15

File tree

2 files changed

+65
-3
lines changed

2 files changed

+65
-3
lines changed

readthedocs/doc_builder/director.py

+15-3
Original file line numberDiff line numberDiff line change
@@ -434,14 +434,16 @@ def check_old_output_directory(self):
434434
def run_build_commands(self):
435435
"""Runs each build command in the build environment."""
436436

437-
reshim_commands = (
437+
python_reshim_commands = (
438438
{"pip", "install"},
439439
{"conda", "create"},
440440
{"conda", "install"},
441441
{"mamba", "create"},
442442
{"mamba", "install"},
443443
{"poetry", "install"},
444444
)
445+
rust_reshim_commands = ({"cargo", "install"},)
446+
445447
cwd = self.data.project.checkout_path(self.data.version.slug)
446448
environment = self.build_environment
447449
for command in self.data.config.build.commands:
@@ -450,18 +452,28 @@ def run_build_commands(self):
450452
# Execute ``asdf reshim python`` if the user is installing a
451453
# package since the package may contain an executable
452454
# See https://github.com/readthedocs/readthedocs.org/pull/9150#discussion_r882849790
453-
for reshim_command in reshim_commands:
455+
for python_reshim_command in python_reshim_commands:
454456
# Convert tuple/list into set to check reshim command is a
455457
# subset of the command itself. This is to find ``pip install``
456458
# but also ``pip -v install`` and ``python -m pip install``
457-
if reshim_command.issubset(command.split()):
459+
if python_reshim_command.issubset(command.split()):
458460
environment.run(
459461
*["asdf", "reshim", "python"],
460462
escape_command=False,
461463
cwd=cwd,
462464
record=False,
463465
)
464466

467+
# Do same for Rust
468+
for rust_reshim_command in rust_reshim_commands:
469+
if rust_reshim_command.issubset(command.split()):
470+
environment.run(
471+
*["asdf", "reshim", "rust"],
472+
escape_command=False,
473+
cwd=cwd,
474+
record=False,
475+
)
476+
465477
html_output_path = os.path.join(cwd, BUILD_COMMANDS_OUTPUT_PATH_HTML)
466478
if not os.path.exists(html_output_path):
467479
raise BuildUserError(BuildUserError.BUILD_COMMANDS_WITHOUT_OUTPUT)

readthedocs/projects/tests/test_build_tasks.py

+50
Original file line numberDiff line numberDiff line change
@@ -1467,6 +1467,56 @@ def test_build_commands(self, load_yaml_config):
14671467
]
14681468
)
14691469

1470+
@mock.patch("readthedocs.doc_builder.director.load_yaml_config")
1471+
def test_reshim_rust(self, load_yaml_config):
1472+
config = BuildConfigV2(
1473+
{
1474+
"version": 2,
1475+
"build": {
1476+
"os": "ubuntu-22.04",
1477+
"tools": {
1478+
"rust": "latest",
1479+
},
1480+
"commands": [
1481+
"cargo install mdbook",
1482+
"mdbook build",
1483+
],
1484+
},
1485+
},
1486+
source_file="readthedocs.yml",
1487+
)
1488+
config.validate()
1489+
load_yaml_config.return_value = config
1490+
1491+
self._trigger_update_docs_task()
1492+
1493+
rust_version = settings.RTD_DOCKER_BUILD_SETTINGS["tools"]["rust"]["latest"]
1494+
self.mocker.mocks["environment.run"].assert_has_calls(
1495+
[
1496+
mock.call("asdf", "install", "rust", rust_version),
1497+
mock.call("asdf", "global", "rust", rust_version),
1498+
mock.call("asdf", "reshim", "rust", record=False),
1499+
mock.call(
1500+
"cargo install mdbook",
1501+
escape_command=False,
1502+
cwd=mock.ANY,
1503+
),
1504+
mock.call(
1505+
"asdf",
1506+
"reshim",
1507+
"rust",
1508+
escape_command=False,
1509+
record=False,
1510+
cwd=mock.ANY,
1511+
),
1512+
mock.call(
1513+
"mdbook build",
1514+
escape_command=False,
1515+
cwd=mock.ANY,
1516+
),
1517+
]
1518+
)
1519+
14701520
@mock.patch("readthedocs.doc_builder.director.load_yaml_config")
14711521
def test_requirements_from_config_file_installed(self, load_yaml_config):
14721522
load_yaml_config.return_value = get_build_config(

0 commit comments

Comments
 (0)