summaryrefslogtreecommitdiff
path: root/kconfiglib.py
AgeCommit message (Collapse)Author
2017-11-27Fix typo in comment: s/T_IF/_T_IF/Ulf Magnusson
2017-11-26Fix _lookup_sym() docstring typoUlf Magnusson
s/_parsing_configs/_parsing_kconfigs/
2017-11-24Simplify _T_IF choice checkUlf Magnusson
Already have the parent in 'parent'.
2017-11-18Fix typo in commentUlf Magnusson
Rephrase it a bit too.
2017-11-18Tokenize in _next_line()Ulf Magnusson
Fetching the next line is always followed by tokenization in practice (outside of help texts), so things can be simplified a bit. Return True/False to indicate EOF instead of returning the line.
2017-11-17Check for type first when parsing propertiesUlf Magnusson
Most common case. Make it cheap by storing the list of type tokens separately instead of building the tuple each time through. Shaves a few % off the runtime for property parsing.
2017-11-17Simplify _parse_properties() loopUlf Magnusson
2017-11-13Micro-optimize Symbol.__init__() a bitUlf Magnusson
Chained assignments turn a bunch of LOAD_CONSTs into DUP_TOPs. Shaves ~10% off the runtime of _lookup_sym(). Do the same for Choice.__init__(), just for consistency. Remove an accidental duplicated assigment to 'defaults' too.
2017-11-13Add a Choice._get_selection() helperUlf Magnusson
Similar to _get_assignable(). Cleaner than setting the cached value at every 'return'.
2017-11-12Simplify licensingUlf Magnusson
IANAL, but hopefully this should be enough. Don't bundle the license file. Might be easier to work with if just kconfiglib.py is copied.
2017-11-12Make 'option env' parsing sanerUlf Magnusson
The previous version would accept stuff like 'option env defconfig_list', due to how the tests were laid out.
2017-11-11Remove more accidental RST formatting in docstringUlf Magnusson
2017-11-11Remove outdated choice invalidation commentUlf Magnusson
The invalidation is necessary now that no global invalidation is done before loading a .config.
2017-11-11Micro-optimize write_config() a bitUlf Magnusson
Shaves a few % in line_profiler with no loss in readability. Menus and comments are rare relatively speaking (~10% of all items written out for alldefconfig), so optimize for the symbol case.
2017-11-11Rename _already_written to _writtenUlf Magnusson
Bit less redundant.
2017-11-11Get rid of _get_config_strings()Ulf Magnusson
Not needed anymore. Just write the .config lines out directly. Saves creating the temporary list. No detectable performance difference, positive or negative.
2017-11-10Remove accidental RST formatting in docstringUlf Magnusson
2017-11-10Fix misleading invalidation commentUlf Magnusson
Avoiding global invalidation is much faster. There was just a lot of redundant invalidation for promptless symbols going on when the comment was first written.
2017-11-10Fix a few typosUlf Magnusson
Clean up some formatting a bit too.
2017-11-10Simplify m->y visibility promotionUlf Magnusson
Can use the magic .type attribute to check for modules being disabled. Also remove note about infinite recursion. Pretty sure anything that would cause infinite recursion here would be a proper circular dependency (like MODULES depending on m).
2017-11-09Reenable accidentally disabled no-prompt warningUlf Magnusson
Warnings for assignments to promptless symbols should be enabled directly after Kconfig parsing. Braino from inverting the meaning of the flag earlier. The flag got properly reset after loading a .config.
2017-11-09Remove left-over misleading property commentUlf Magnusson
Versions of properties without parent dependencies propagated aren't saved anymore (though it'd be easy to add back if needed).
2017-11-07Update documentation to sync. with updated READMEUlf Magnusson
2017-11-07s/overriden/overridden/Ulf Magnusson
Add test coverage for that Choice.__repr__() path too.
2017-11-07Polish Symbol, Choice, and MenuNode docsUlf Magnusson
2017-11-06Simplify n/m/y to constant symbol translationUlf Magnusson
Hit way too seldomly for it to make a performance difference, but a bit neater. We know n, m, and y already exist since they're precreated.
2017-11-06Get rid of Choice.default_selectionUlf Magnusson
Was only used by allyesconfig.py. Easy to add back if needed at any point.
2017-11-06Polish some Symbol and Choice docsUlf Magnusson
2017-11-06Polish the module documentationUlf Magnusson
Doing a (hopefully) final pass through the docs before release.
2017-11-06Rename _RELATION_TO_STR to _REL_TO_STRUlf Magnusson
Consistent with e.g. _TOKEN_TO_REL.
2017-11-06Use 'sym' instead of 'item' in choice-related loopUlf Magnusson
Only symbols appear in choice.syms. Clearer.
2017-11-06Remove redundant n/m/y._cached_str_val assignmentsUlf Magnusson
Will be automatically calculated and cached as needed. Less magic code.
2017-11-06Remove redundant 'is not None' testUlf Magnusson
Always a MenuNode or None. Can be tested simpler.
2017-11-06Rename variable from 'add_fn' to 'append'Ulf Magnusson
2017-11-05Add invalidation warning to Choice.selectionUlf Magnusson
Now in all paths that cache values.
2017-11-05Simplify redundant 'is (not) None' testsUlf Magnusson
Menu node pointers and .choice in particular is always either an object or None. Prompts are always either a (text, cond) tuple or None. Some other things could (though unlikely) be empty strings, and some things use symbolic constants that might be 0, so keep the None tests there. Cleaner, especially for menu nodes. Also remove redundant 'node2.dep is None' test. Expressions are never None. Also fix node.prompt == "" comparison in _flatten(). Should be node.prompt[0] == "". Not sure why the C implementation checks for an existing but empty prompt to begin with. It's just cosmetic menu stuff at least.
2017-11-04Optimize tri_value() a bitUlf Magnusson
- Detect a 0 weak reverse dependency earlier. Being implied is rare, and the direct deps don't need to be calculated for symbols that aren't. Bit cleaner too, and closer to the rev. dep code. Shaves a few % off the time spent in tri_value() while writing a .config. - Look at the symbol's visibility to determine the choice mode instead of going to the choice itself. Works since the mode acts as an upper bound on the visibility of choice symbols. No detectable performance difference, but a bit cleaner anyway. Piggyback some nits.
2017-11-04Add menuconfig example/proof of conceptUlf Magnusson
Still needs documentation and some cleanup. Interface deliberately kept super simple/clunky to focus on the concepts. Not something you'd actually want to use. Sample session: $ python Kconfiglib/examples/menuconfig.py Kconfiglib/examples/Kmenuconfig ======== Example Kconfig configuration ======== [*] Enable loadable module support (MODULES) Bool and tristate symbols [*] Bool symbol (BOOL) [ ] Dependent bool symbol (BOOL_DEP) < > Dependent tristate symbol (TRI_DEP) [ ] First prompt (TWO_MENU_NODES) < > Tristate symbol (TRI) [ ] Second prompt (TWO_MENU_NODES) *** These are selected by TRI_DEP *** < > Tristate selected by TRI_DEP (SELECTED_BY_TRI_DEP) < > Tristate implied by TRI_DEP (IMPLIED_BY_TRI_DEP) String, int, and hex symbols (foo) String symbol (STRING) (747) Int symbol (INT) (0xABC) Hex symbol (HEX) Various choices -*- Bool choice (BOOL_CHOICE) --> Bool choice sym 1 (BOOL_CHOICE_SYM_1) Bool choice sym 2 (BOOL_CHOICE_SYM_2) {M} Tristate choice (TRI_CHOICE) < > Tristate choice sym 1 (TRI_CHOICE_SYM_1) < > Tristate choice sym 2 (TRI_CHOICE_SYM_2) [ ] Optional bool choice (OPT_BOOL_CHOICE) Enter a symbol/choice name, "load_config", or "write_config" (or press CTRL+D to exit): BOOL Value for BOOL (available: n, y): n ======== Example Kconfig configuration ======== [*] Enable loadable module support (MODULES) Bool and tristate symbols [ ] Bool symbol (BOOL) < > Tristate symbol (TRI) [ ] Second prompt (TWO_MENU_NODES) *** These are selected by TRI_DEP *** < > Tristate selected by TRI_DEP (SELECTED_BY_TRI_DEP) < > Tristate implied by TRI_DEP (IMPLIED_BY_TRI_DEP) String, int, and hex symbols (foo) String symbol (STRING) (747) Int symbol (INT) (0xABC) Hex symbol (HEX) Various choices -*- Bool choice (BOOL_CHOICE) --> Bool choice sym 1 (BOOL_CHOICE_SYM_1) Bool choice sym 2 (BOOL_CHOICE_SYM_2) {M} Tristate choice (TRI_CHOICE) < > Tristate choice sym 1 (TRI_CHOICE_SYM_1) < > Tristate choice sym 2 (TRI_CHOICE_SYM_2) [ ] Optional bool choice (OPT_BOOL_CHOICE) Enter a symbol/choice name, "load_config", or "write_config" (or press CTRL+D to exit): MODULES Value for MODULES (available: n, y): n ======== Example Kconfig configuration ======== [ ] Enable loadable module support (MODULES) Bool and tristate symbols [ ] Bool symbol (BOOL) [ ] Tristate symbol (TRI) [ ] Second prompt (TWO_MENU_NODES) *** These are selected by TRI_DEP *** [ ] Tristate selected by TRI_DEP (SELECTED_BY_TRI_DEP) [ ] Tristate implied by TRI_DEP (IMPLIED_BY_TRI_DEP) String, int, and hex symbols (foo) String symbol (STRING) (747) Int symbol (INT) (0xABC) Hex symbol (HEX) Various choices -*- Bool choice (BOOL_CHOICE) --> Bool choice sym 1 (BOOL_CHOICE_SYM_1) Bool choice sym 2 (BOOL_CHOICE_SYM_2) -*- Tristate choice (TRI_CHOICE) --> Tristate choice sym 1 (TRI_CHOICE_SYM_1) Tristate choice sym 2 (TRI_CHOICE_SYM_2) [ ] Optional bool choice (OPT_BOOL_CHOICE) Enter a symbol/choice name, "load_config", or "write_config" (or press CTRL+D to exit): ^D Unsetting modules demonstrates one reason why it makes sense to have .type be magic and change from TRISTATE to BOOL without modules (<> = tristate, [] = bool). The C implementation uses the same trick. (The original type is still available in .orig_type though.) Piggyback printing of tristates as n, m, y in the warning for invalid values in set_value().
2017-11-04Don't put 0 in .assignable for y-mode choice symsUlf Magnusson
Just return (2,). More intuitive, and makes y-mode choices just work in the menuconfig example. Turns out to be simple to implement with choice symbol visibility depending on the Choice.
2017-11-04Return False from set_value() for invalid valuesUlf Magnusson
Usability improvement discovered while putting together menuconfig example. Would have to duplicate validity checking otherwise. Also reject negative values for HEX symbols, just to be compatible with the C implementation. Keep TRI_TO_STR and STR_TO_TRI public. They're pretty handy even if they're trivial.
2017-11-03Test Choice.assignable, fix for optional choicesUlf Magnusson
Could never return 0 as a valid assignable value previously.
2017-11-03Add initial selftests for .assignableUlf Magnusson
Comprehensive selftests are important here, because the allno/yesconfig.py scripts only check the upper and lower bound, and allnoconfig disables modules. Found a bug for non-selected m-visible tristates, where n didn't show up in sym.assignable. Everything matches menuconfig after fixing that. Still need to test symbols in choices with different modes, imply, and .assignable for choices.
2017-11-02Always save user values if they're validUlf Magnusson
Can just skip the invalidation for promptless symbols. Makes things less magic and more intuitive while still being fast. Means no docs need to be rewritten too. Now the warning gets printed for unset_value() as well.
2017-11-02Don't set promptless symbols when loading .configUlf Magnusson
Return braino. Harmless but inconsistent (since the user value wasn't set for promptless symbols when manually calling set_value()). Also caused a lot of redundant invalidation. Cuts test_defconfig() down to 2m32s from 3m00s with CPython, so skipping global invalidation definitely pays off now. Downside is you lose information on what value the .config had for the symbol. Not sure if anyone would ever need that information (and it should be simple to add if needed). It would usually match the actual value of the symbol.
2017-11-02Do not invalidate everything when loading .configsUlf Magnusson
In replace mode, only unset symbols that didn't get set. Get rid of _set_value_no_invalidate() and just do a normal set_value() with invalidation. It's speedy with the new invalidation algorithm, and simpler. Not a big performance boost (but a small one), but means that invalidation must be even more rock solid for the test suite to pass (no global invalidations to hide behind), which is nice. Also make y assignments to choice symbol update just the choice user value. Gives nicer behavior when the choice mode is changed.
2017-11-01Emulate 'range' internals closerUlf Magnusson
Dug into the C implementation to check exactly what's going on in those weird corner cases. Improves compatibility slightly for defaults with invalid values (though those are pretty clearly a bug and generate a warning anyway).
2017-11-01Clean up printing code a bitUlf Magnusson
2017-11-01Documentation nitsUlf Magnusson
2017-11-01Switch to a much faster invalidation algorithmUlf Magnusson
_cached_vis is always calculated as a side effect of calculating any other cached value, and so doubles as a flag for whether an item (symbol or choice) has any cached values. If _cached_vis is None for some item, it also indirectly means that no other item can have any cached values that (actually) depend on the item, because _cached_vis would have gotten calculated as a side effect of calculating any such cached value. Therefore, it's safe to stop recursive invalidation at an item that has _cached_vis None. Huge speedup for the allyes/noconfig*.py scripts. allnoconfig_simpler.py went from 2.671 seconds to 1.067 seconds. The dependency selftests need to be updated too now that _get_dependent() is gone. The kernel defconfig tests pass even if all global invalidation is disabled at least (except for the few defconfigs that don't set MODULES=y), and that's a huge invalidation test. Seems pretty speedy too, even though there's some redundant work, so maybe things could be simplified a bit...
2017-10-31Require manual mode setting for choicesUlf Magnusson
Do not change the mode if y is assigned to a choice symbol inside a choice in m mode, for example. Require Choice.set_value() to be called instead. This makes choices way less magical and more menuconfig-like. It would also be confusing to be able to assign y to a choice symbol when y is not in sym.assignable. Set the mode manually in load_config() (y assigned to a choice symbol => y mode, and ditto for m). Change the warning for inconsistent values to one that's probably less confusing, though the old one was closer to the warning printed by the C implementation. Need to fix a bunch of tests too...