Skip to content

fix: Preserve existing config.toml entries that are not managed by this tool#39

Open
lyinch wants to merge 3 commits intocolcon:mainfrom
lyinch:fix/concatenate_config_toml
Open

fix: Preserve existing config.toml entries that are not managed by this tool#39
lyinch wants to merge 3 commits intocolcon:mainfrom
lyinch:fix/concatenate_config_toml

Conversation

@lyinch
Copy link

@lyinch lyinch commented Dec 24, 2025

I am working in a cargo workspace and want to use rclrs in some of the packages. The current implementation however takes strong ownership of this, and in particular replaces existing .cargo/config.toml files. I have:

[target.aarch64-unknown-linux-gnu]
linker = "aarch64-linux-gnu-gcc"

after running this tool, it is replaced with:

[patch.crates-io.rclrs]
path = "/home/foo/install/rclrs/share/rclrs/rust"
...

This PR changes the behaviour of write_cargo_config_toml() to keep existing entries that are not part of a [patch.crates-io] section, while replacing all of the existing [patch.crates-io]. Replacing (instead of appending) keeps the functionality identical with the current implementation.

The PR additionally introduces unit tests for the specific function.

This PR can be reviewed commit-by-commit. The first commit adds a unit test to test the existing behaviour, the second commit introduces the change and modifies the unit test to verify the new behaviour.

Note: AI was used for this PR

I didn't use a code formatter for build.py as I couldn't find any guidelines or config for common tooling. Using ruff heavily modifies it so I raw-dogged it.

Comment on lines +119 to +120
with cargo_config_toml_out.open('r') as toml_file:
content = toml.load(toml_file)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we wrap this in a try except so the tool doesn't crash if the file being loaded is malformed?

@luca-della-vedova
Copy link
Member

The CI failure points out the formatting issues, mainly in the test file

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Format this file with flake8. CI is failing on this test specifically

def test_flake8():

I think this answers your question in the description as well

I didn't use a code formatter for build.py as I couldn't find any guidelines or config for common tooling.

def temp_workspace(tmp_path):
"""Create a temporary workspace directory."""
original_cwd = os.getcwd()
os.chdir(tmp_path)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixture expects a tmp_path variable, but the usage of it doesn't ever fill this value. I don't think this will run as os.chdir does expect a value

>>> import os
>>> os.chdir(None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: chdir: path should be string, bytes, os.PathLike or integer, not NoneType
>>> os.chdir("")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
FileNotFoundError: [Errno 2] No such file or directory: ''

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants