Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Idea: Inline includes? #36

Closed
shazow opened this issue Feb 24, 2013 · 6 comments
Closed

Idea: Inline includes? #36

shazow opened this issue Feb 24, 2013 · 6 comments

Comments

@shazow
Copy link

shazow commented Feb 24, 2013

In Python-land, it's not uncommon to include subsections of an INI file from another INI file. (Especially in Paste-style INI files.)

So I could have

# development.ini
[app]
database = "sqlite://whatevs.db"
# [... lots of other things]

And in my unit testing environment, I'd override just one key...

# testing.ini
[app]
use = config:development.ini#app
database = "sqlite:///:memory:"

TOML proposal

As for how this would look like in TOML if we wanted to support it, perhaps some variation of...

# Assign to section?
[app] = development.ini#app
database = "override value"

Or perhaps...

# Non-assignments are treated as includes?
[app]
development.ini#app
database = "override value"

# Could even support multiple includes
[app]
app_defaults.ini
development.ini#app
somekey = "foo"
someotherkey = "bar"
override_keys.ini#app

Quite possibly out of scope for TOML, but an interesting thought experiment.

@robn
Copy link

robn commented Feb 24, 2013

Then you have a runtime requirement. Bad. If you want includes, use some specially-named key that has meaning for your application, and sort it out yourself.

include = [ "foo.ini", "bar.ini", "baz.ini" ]

@mojombo
Copy link
Member

mojombo commented Feb 24, 2013

@shazow It's a cool idea, but you're right, I think it's outside the scope of TOML. @robn's solution is a decent one, I think.

@mojombo mojombo closed this as completed Feb 24, 2013
@shazow
Copy link
Author

shazow commented Feb 24, 2013

Agreed all around.

@Artoria2e5
Copy link

Artoria2e5 commented May 24, 2021

I am definitely not proposing to add this to TOML, but just for a better format in case someone wants to do a little dialect:

In TOML the unquoted keys can only be alphanumeric or -_ (see unquoted-key in ABNF). This leaves us a lot of space to expand using the symbols, so we can have:

%include "foo.toml"
%include-dir "conf.d"

... which could be described more concretely as:

preprocessor = %x25 preprocessor-key ws string
preprocessor-key = "include" / "include-dir"

I am calling it "preprocessor" as integrating this stuff into the expression tree is not something I want to look at at all, although for the top level you can just go with expression =/ preprocessor.

And this clearly lacks the flexibility to just include a part of some other file -- you should probably hack up a variant of JSONPath for that and handle it in the application after all. (Yeah, nothing stops you from putting that in the percent-PP-statement too, but doing so would bring about even more cursed changes as you begin to put it in the core syntax.)

@dgutson
Copy link

dgutson commented Sep 28, 2022

What happened to this feature, why was closed? %include was very cool!

@pradyunsg
Copy link
Member

See the closing note: #36 (comment)

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

No branches or pull requests

6 participants