bacon icon indicating copy to clipboard operation
bacon copied to clipboard

Allow storing config in Cargo.toml

Open alerque opened this issue 1 year ago • 3 comments

Cargo manifests have a standardized way to store TOML data that configures third party tooling. The [package.metadata.bacon] space in Cargo.toml could be used to hold Bacon configs instead of a stand alone bacon.toml file. This is supported by many developer tools that are used in Rust or Rust adjacent projects, e.g. ruff, typos, git-cliff, and many more.

Obviously this should be optional, but checking that key in the manifest for config data in addition to the default stand alone config location would be appreciated by projects that already have enough clutter in the project root file space and prefer to group tooling configs together.

alerque avatar Oct 13 '24 11:10 alerque

Interesting.

A problem is the bacon.toml file is neither small nor flat. This would probably be quite ugly.

Also, the need to prefix all keys would make it harder to copy paste between config files.

Did you try writing a Cargo.toml file with bacon config inside to see how it would look ?

Canop avatar Oct 14 '24 10:10 Canop

Yes I am aware of exactly how it would look, and yes the extra prefix to the namespace adds verbosity. But "that would be ugly" sees like a subjective metric that should be left up to the end user. I'm not suggesting making it the default or taking away the current stand alone config option. I work on projects that go both ways and there are pros and cons for both. As far as Bacon's side goes all you have to do is load the TOML and query the correct namespace, then remove the prefix from everything. It shouldn't be too much trouble to implement or maintain and it lets projects manage their tooling however they want to along with many other tools that work the same way.

alerque avatar Oct 14 '24 11:10 alerque

It shouldn't be too much trouble to implement

Exact.

then remove the prefix from everything

This won't be necessary if the TOML file is deserialized into the right struct.

Can you build a complete example file to serve as example and as test ?

Canop avatar Oct 14 '24 11:10 Canop

Currently working bacon.toml:

default_job = "build"

[jobs.build]
command = [
  "cargo", "build",
  "--features", "luajit",
  "--color", "always"
]

Proposed lines to enable the same behavior in Cargo.toml:

[package.metadata.bacon]
default_job = "build"

[package.metadata.bacon.jobs.build]
command = [
  "cargo", "build",
  "--features", "luajit",
  "--color", "always"
]

alerque avatar Nov 19 '24 09:11 alerque

@alerque Can you check https://github.com/Canop/bacon/pull/270 ?

Canop avatar Dec 01 '24 19:12 Canop

Nice! I'll try to give it a test drive, possibly tomorrow.

In the mean time it wasn't relevant when I opened this issue since bacon was Rust only then, but Python projects can have something similar with pyproject.toml housing config data for Python tooling (e.g. typos, ruff, etc.). Since you're coming out with new config places and now Bacon supports Pylint, it might be worth pre-empting the requests for that while you are at it. It works the same way.

alerque avatar Dec 01 '24 19:12 alerque

I saw you mentionned it in the other issue, and it's a good point.

But there doesn't seem to be any Python+bacon user yet, so I'll wait before investing more time on Python support.

Canop avatar Dec 01 '24 19:12 Canop