Skip to content

Support file substitutions#73

Merged
zanieb merged 1 commit intozanieb:mainfrom
samypr100:support-substitutions
Aug 26, 2025
Merged

Support file substitutions#73
zanieb merged 1 commit intozanieb:mainfrom
samypr100:support-substitutions

Conversation

@samypr100
Copy link
Contributor

@samypr100 samypr100 commented Aug 12, 2025

In order to support astral-sh/uv#15196

This adds initial support to rooster for file substitutions.

Replace old version with new version in README.md using the special substitution string rooster.previous.

[tool.rooster]
...
substitution_files = { "README.md"  = ["rooster.previous"] }

or

Replace FOO and BAR with the new version on all md files.

[tool.rooster]
...
substitution_files = { "**/*.md"  = ["FOO", "BAR"] }

@zanieb
Copy link
Owner

zanieb commented Aug 12, 2025

I might prefer something like

substitution-files = ["README.md", {file = "**/*.md", replace = "foo"}]

So we don't need to add the special rooster.previous string? wdyt?

@samypr100
Copy link
Contributor Author

samypr100 commented Aug 12, 2025

I might prefer something like

substitution-files = ["README.md", {file = "**/*.md", replace = "foo"}]

So we don't need to add the special rooster.previous string? wdyt?

We can also assume the behavior of "rooster.previous" if the substitution array is empty? Since right now this also works:

[tool.rooster]
...
substitution_files = { "**/*.md"  = ["rooster.previous", "FOO", "BAR"], "README.md"  = ["BAZ"] }

I didn't add single file support because I feel that's covered by version_files, or is your intent to supersede it by this?

@samypr100
Copy link
Contributor Author

I do get rooster.previous may feel weird though 😅

@zanieb
Copy link
Owner

zanieb commented Aug 12, 2025

Oh I see — sorry I don't know my own APIs here. Yeah, I think I'd replace version_files? Or at least, I wouldn't have two settings that do such similar things. I think if we did a generic substitution I'd expect more like..

substitutions = [ {find = "rooster.previous", replace = "rooster.next", files = "**/*.md"} ]

I don't know if I really want that yet though, so maybe we should just add some functionality to version_files?

@samypr100
Copy link
Contributor Author

samypr100 commented Aug 12, 2025

I ended up going ahead and adding support to replacements to the existing version_files like you proposed originally.

This will work now:

version_files = [ 
    "README.md", # Existing functionality
    { target = "**/*.md" },  # Replaces all prev versions with new version on all matches
    { target = "**/*.md", replace = "FOO" } # Replaces all instances of FOO with new version on all matches
]

@samypr100 samypr100 force-pushed the support-substitutions branch from 7eacf63 to 90fcdb4 Compare August 12, 2025 03:31
@samypr100
Copy link
Contributor Author

Note, I chose target over file for the glob as it felt weird to name a glob pattern parameter file but I can switch to file if that's preferred.

@samypr100
Copy link
Contributor Author

Sorry for the ping as you're very busy; thoughts here? 😄

@zanieb zanieb merged commit 4fa5caf into zanieb:main Aug 26, 2025
4 checks passed
@samypr100 samypr100 deleted the support-substitutions branch August 26, 2025 16:22
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.

2 participants