App: Move project.conf parsing into lib.ProjectConf #43
Loading…
Reference in a new issue
No description provided.
Delete branch "jan/feature/20260630-app-get-section-remove-method"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
jw-pkg reads project metadata from INI-style make/project.conf files. They are currently parsed by the App class, which is too crowded and badly testable. This PR removes the parsing task from the App class, and has it use the new class lib.ProjectConf instead, a step toward cleaner caching, and to providing a better place for unit testing.
App: Replace @lru_cache() with @cache
Replace the @functools.lru_cache(maxsize=None) decorator with @functools.cache throughout App. functools.cache is a shorthand for functools.lru_cache(maxsize=None) introduced in Python 3.9 and is more concise and readable with identical behaviour.
lib.ProjectConf: Add module
Introduce ProjectConf module to cleanly parse make/project.conf ini-like configuration files. The new class supports:
test: ProjectConf: Add unit tests
Add unit tests for the new ProjectConf module covering:
Also include a Makefile for running tests via
make test.App: Use ProjectConf
Refactor App to use the new ProjectConf module for parsing make/project.conf files.
This commit
removes the inline ad-hoc read_value() method and its nested helper functions, replacing them with ProjectConf's get_str_or_none() API.
introduces two cached helper methods (__read_project_conf() and __get_project_conf()) to read and cache ProjectConf instances per project.
updates get_value() to delegate to ProjectConf and moves the proj_dir lookup to only run in the version branch where it is needed.
updates the topdir init to use __read_project_conf() with a FileNotFoundError catch for optional config files.
App.get_section(): Remove method
Remove App.get_section() which parses raw file sections by scanning for section headers and accumulating lines. This method is no longer needed since ProjectConf now handles all config file parsing.
Add unit tests for the new ProjectConf module covering: - Basic string and list value retrieval (get_str(), get_str_or_none(), get_list(), get_list_or_none()) - Quoted values with preserved spaces and comment delimiters - Inline comments outside quotes - Comma-separated lists with quoted commas - Line continuations - Multiple sections - Error cases: empty key, missing key/section, malformed sections, unfinished continuations, unclosed quotes - Error class is a subclass of ValueError Also include a Makefile for running tests via `make test`. Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL and pi.dev Signed-off-by: Jan Lindemann <jan@janware.com>Refactor App to use the new ProjectConf module for parsing make/project.conf files. This commit - removes the inline ad-hoc read_value() method and its nested helper functions, replacing them with ProjectConf's get_str_or_none() API. - introduces two cached helper methods (__read_project_conf() and __get_project_conf()) to read and cache ProjectConf instances per project. - updates get_value() to delegate to ProjectConf and moves the proj_dir lookup to only run in the version branch where it is needed. - updates the topdir init to use __read_project_conf() with a FileNotFoundError catch for optional config files. Signed-off-by: Jan Lindemann <jan@janware.com>App.get_section(): Remove methodto App: Move inifile parsing into lib.ProjectConfApp: Move inifile parsing into lib.ProjectConfto App: Move project.conf parsing into lib.ProjectConf