App: Move project.conf parsing into lib.ProjectConf #43

Merged
Jan Lindemann merged 5 commits from jan/feature/20260630-app-get-section-remove-method into master 2026-06-30 14:04:35 +02:00 AGit

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:

  • ini-style sections with header comments
  • Key-value pairs with backslash line continuation
  • Quoted values preserving spaces and comment delimiters (#) inside
  • Inline comments outside of quotes
  • Comma-separated list values with quoted commas
  • Cached section parsing to avoid re-parsing the same section
  • .get_section() to return an entire section unparsed

test: ProjectConf: Add unit tests

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.

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.

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: - ini-style sections with header comments - Key-value pairs with backslash line continuation - Quoted values preserving spaces and comment delimiters (#) inside - Inline comments outside of quotes - Comma-separated list values with quoted commas - Cached section parsing to avoid re-parsing the same section - .get_section() to return an entire section unparsed #### test: ProjectConf: Add unit tests 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`. #### 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.

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.

Signed-off-by: Jan Lindemann <jan@janware.com>

Introduce ProjectConf module to cleanly parse make/project.conf ini-like configuration files. The new class supports:

- ini-style sections with header comments - Key-value pairs with backslash line continuation - Quoted values preserving spaces and comment delimiters (#) inside - Inline comments outside of quotes - Comma-separated list values with quoted commas - Cached section parsing to avoid re-parsing the same section - .get_section() to return an entire section unparsed

Signed-off-by: Jan Lindemann <jan@janware.com>

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 method
All checks were successful
CI / Packaging - Kali Linux (pull_request) Successful in 4m24s
CI / Packaging - OpenSUSE Tumbleweed (pull_request) Successful in 5m5s
CI / Packaging test (pull_request) Successful in 0s
CI / Packaging - Kali Linux (push) Successful in 3m59s
CI / Packaging - OpenSUSE Tumbleweed (push) Successful in 4m12s
CI / Packaging test (push) Successful in 0s
9fa617cfc8

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.

Signed-off-by: Jan Lindemann <jan@janware.com>
Jan Lindemann scheduled this pull request to auto merge when all checks succeed 2026-06-30 13:55:00 +02:00
Jan Lindemann changed title from App.get_section(): Remove method to App: Move inifile parsing into lib.ProjectConf 2026-06-30 13:57:15 +02:00
Jan Lindemann changed title from App: Move inifile parsing into lib.ProjectConf to App: Move project.conf parsing into lib.ProjectConf 2026-06-30 13:58:18 +02:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
janware/jw-pkg!43
No description provided.