SimpleParsing icon indicating copy to clipboard operation
SimpleParsing copied to clipboard

Alias prefix suppression

Open idoby opened this issue 3 years ago • 6 comments

Allow to suppress the prefix defined for a field if used through an alias, for extra-short aliases for often-used command line switches.

idoby avatar Aug 20 '22 16:08 idoby

@lebrice Something seems to be wrong with the 3.6 check. Didn't you drop support for 3.6?

idoby avatar Aug 22 '22 15:08 idoby

Yeah support was dropped for python 3.6, and ~~I'm not quite sure why it still shows up here...~~ Fixed!

lebrice avatar Aug 22 '22 18:08 lebrice

Hey @idoby, wouldn't passing field(alias="--out")be sufficient here? If not, would you mind clarifying why this is required?

lebrice avatar Aug 22 '22 18:08 lebrice

Hey @idoby, wouldn't passing field(alias="--out")be sufficient here? If not, would you mind clarifying why this is required?

I'm using prefixes, so specifying aliases still keeps the prefix (e.g. "--experiment_label" becomes "-experiment_l" instead of "-l") and I got tired of typing out the entire thing. So I made a way to drop the prefix for often used cmdline switches.

idoby avatar Aug 22 '22 19:08 idoby

How would you deal with a dataclass with an "Alias" field being used in two different places?

lebrice avatar Aug 25 '22 20:08 lebrice

How would you deal with a dataclass with an "Alias" field being used in two different places?

That would be a conflict. I didn't really get into the details of how AP/SP does conflict resolution, just assumed it would throw an error or something. Do you think this will be a problem?

idoby avatar Aug 26 '22 07:08 idoby

Wait, @idoby , I'm not sure you answered my question:

wouldn't passing field(alias="--out") be sufficient here? (iirc it doesn't use a prefix in that case, right?)

lebrice avatar Oct 05 '22 00:10 lebrice

wouldn't passing field(alias="--out") be sufficient here? (iirc it doesn't use a prefix in that case, right?)

No, because I'm using a dataclass called ExperimentConfig which is sent to SP with a prefix, namely "experiment". This DC contains a "label" field with alias "-l", which then becomes "-experiment_l" instead of "-l" like I wanted.

I've included examples in test_aliases_with_suppressed_prefix() in test/test_aliases.py.

idoby avatar Oct 15 '22 12:10 idoby

I'm not convinced yet that this is a feature worth adding. Closing for now.

lebrice avatar Mar 01 '23 17:03 lebrice