summaryrefslogtreecommitdiff
path: root/kconfiglib.py
AgeCommit message (Collapse)Author
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...
2017-10-31Handle choices more like the C implementationUlf Magnusson
Choice symbols get the choice itself propagated to the conditions of their properties. This works since the Symbol/Choice value interfaces are compatible now. Simplifies value calculations and makes .assignable work automagically for choice symbols in choices in any mode. One drawback is that a '&& <choice>' now shows up on conditions when printing choice symbols, which is not valid Kconfig. That should be easy to work around if needed at least.
2017-10-30Rename _TYPENAME to TYPE_TO_STRUlf Magnusson
Make it public. Piggyback some unrelated comment stuff due to git fails.
2017-10-30Add missing docstringsUlf Magnusson
Also make the format in the code a bit more consistent.
2017-10-30Documentation fixesUlf Magnusson
Add some more details to the intro and various docstrings.
2017-10-30Docstring and comment fixesUlf Magnusson
2017-10-30Explain how to get the integer value for int/hexUlf Magnusson
2017-10-30Merge user_str/tri_value into user_valueUlf Magnusson
user_str_value isn't justified any more with the other API improvements. user_value now stores 0, 1, 2 for bool/tristate symbols, and a string for other symbol types. Much simpler and more intuitive. Also avoid printing quotes around tristate values in __repr__(). This was inconsistent too as it was only done for the value and user value. Should be getting close to final API.
2017-10-30Comment nitUlf Magnusson
2017-10-30Have printing a menu node print the itemUlf Magnusson
Handy and intuitive. Avoids having to go to .item all the time when experimenting, and provides Kconfig output for menus and comments. >>> print c.top_node menu "Linux/$ARCH $KERNELVERSION Kernel Configuration" >>> print c.top_node.list config SRCARCH string option env="SRCARCH" default "x86" >>> print c.top_node.list.next config 64BIT bool prompt "64-bit kernel" if ARCH = "x86" default ARCH != "i386" help Say yes to build a 64-bit kernel - formerly known as x86_64 Say no to build a 32-bit kernel - formerly known as i386 Piggyback escaping when printing the prompt of symbols and choices. They can contain " and \ as well.
2017-10-30Move __str__() after __repr__()Ulf Magnusson
2017-10-30Doc nitsUlf Magnusson
2017-10-30Rename Symbol/Choice/MenuNode.config to kconfigUlf Magnusson
To be consistent with the renamed class. Piggyback docstring fixes.
2017-10-30Fix outdated set_value() documentationUlf Magnusson
Not worthwhile to confuse the API by allowing strings for bool/tristate. Things works out nicely anyway with the other updated APIs.
2017-10-30Consistently use 0/1/2 for tristate valuesUlf Magnusson
Easier to work with, allowing e.g. direct comparisons with < and >. Make set_value() take 0, 1, 2 for bool and tristate symbols, and fix other APIs to match. Also: - Add introductions to various concepts in the module docstring. Document some more attributes. Still TODOs. - Rename the Config class to Kconfig. - Escape " and \ in the name of constant symbols when printing them. Also make the (un)escaping 100% consistent with how the C tools do it (\ before non-magic character should be unescaped too). - Clean up the escaping/unescaping code and provide two public escape()/unescape() functions. - Export the original MODULES-independent type in orig_type. It's needed for printing symbols in the reparsable __str__() Kconfig format with just public APIs. - Lots of other minor reorganizing and nits all over.
2017-10-28Add uncommitted test filesUlf Magnusson
2017-10-28Test suite work, cleanup, const sym invalidation fixUlf Magnusson
2017-10-28Nearly finalize APIUlf Magnusson
Probably just some usability tweaks left. Having to do STR_TO_TRI[] for comparisons against 'assignable' values is kinda ugly and confusing.
2017-10-27BackupUlf Magnusson
2017-10-27BackupUlf Magnusson
2017-10-25BackupUlf Magnusson
2017-10-25BackupUlf Magnusson
2017-10-24Kconfiglib 2 backupUlf Magnusson
WIP