Skip to content

630:P3 [Data Clumps / Argument Spaghetti] in generation flow -> refactor toward Parameter Object#4

Open
not-sure-ksharma12 wants to merge 16 commits into
tbrumbaugh5396:mainfrom
not-sure-ksharma12:p3/issue-35-parameter-object
Open

630:P3 [Data Clumps / Argument Spaghetti] in generation flow -> refactor toward Parameter Object#4
not-sure-ksharma12 wants to merge 16 commits into
tbrumbaugh5396:mainfrom
not-sure-ksharma12:p3/issue-35-parameter-object

Conversation

@not-sure-ksharma12

Copy link
Copy Markdown

Closes #35

Summary

  • Introduced internal dataclass _ProjectGenerationContext to group repeated generation-flow parameters.
  • Updated internal methods to receive context instead of repeating the same argument bundle:
    • _apply_optional_scripts
    • _apply_common_docs
    • _update_package_references
  • Constructed context internally in _customize_project and _generate_builtin_project.

Why

This reduces argument clumps and makes internal generation flow easier to maintain without changing public APIs.

Behavior compatibility

  • Public API (generate_project) unchanged.
  • CLI/GUI behavior unchanged.
  • Generation outputs unchanged.

Verification

  • ./venv/bin/python -m pytest tests/test_project_generator.py -q
  • ./venv/bin/python -m pytest tests/test_feature_flags.py -q
  • ./venv/bin/python -m pytest -q

Closes #3

- Runs pytest with coverage on push to main, PRs, and manual dispatch
- Tests across Python 3.8, 3.9, 3.10, 3.11, 3.12
- Uploads coverage report as artifact for the 3.12 run
- Includes self-review documentation
Closes #2

- Tests for --version, --help, --cli, --gui flag parsing
- Tests for CLI flag routing to project_generator.main()
- Tests for argument forwarding to the CLI module
- Tests for graceful handling when wxPython is unavailable
- Tests for module execution and callable verification
Closes #6

- Tests that each feature flag (cli, tests, pypi_packaging, readme, etc.) creates expected files
- Tests that disabled flags do not create files
- Tests for feature combinations working together
- Tests for metadata injection (author, email, version, description)
- Tests for no unresolved placeholder patterns in generated output
Closes #5

- Parametrized tests verify every template generates successfully
- Parametrized tests verify every template creates a non-empty project directory
- Parametrized tests verify every template has required metadata fields
- Template-specific structure tests for Flask, FastAPI, data-science, CLI tool,
  binary-extension, namespace-package, and plugin-framework
- project_generator.py coverage improved from 31% to 53%
## Summary of changes
- Validate paths in `_update_file_content` with `resolve()` and containment under the project root (`relative_to`) before read/write.
- Pass `project_path` from `_update_package_references` for both text files and `*.py` updates.
- Added tests: a traversal-style path must not be written; an in-tree file still gets replacements.
## Verification
- `PYTHONPATH=src pytest tests/ -q` — all tests pass.
## Evidence
- Addresses Sonar **pythonsecurity:S2083** by refusing I/O when the resolved path leaves the project directory.
- Regression tests document safe vs unsafe paths.
* Harden _update_file_content against path traversal (S2083)

- Resolve project root and target; require target under root via relative_to
- Rebuild I/O path as root_resolved.joinpath(*rel.parts) after containment (Sonar S2083)
- Skip updates with warning when path escapes project directory
- Add regression tests for outside vs in-tree paths

* Refine safe path handling for _update_file_content

- Replace joinpath(*rel.parts) with stepwise root/segment joins; reject '..'
- Perform read/write via path.open() after containment check
Closes #20

## Summary of changes
- Replaced bare `except:` around `ImageFont.truetype` with `except Exception:` so `SystemExit` and `KeyboardInterrupt` are not swallowed (python:S5754).

## Verification
- `PYTHONPATH=src pytest tests/ -q` — all tests pass.
- `pip install pillow` then `python scripts/create_icon.py` — icon generation runs; falls back to default font if the macOS font path is missing.

## Evidence
- Matches python:S5754: no blanket `BaseException` handler for this block.
Early returns plus _clear_template_info_display and _apply_template_detailed_info;
same widget updates and layout behavior as before.
Move core tree and scripts/ preview lines into _log_preview_core_structure
and _log_preview_scripts_section; same log output order and strings.
Single module-level function; add test that import and calls do not raise.
Module dict maps template_id to ProjectGenerator method name; dispatch uses
registry before the elif chain. Stub _generate_django_template kept for
compat. Tests cover registry entry and generation.
- Add optional templates_cache_dir to TemplateManager; default unchanged
  (Path.home()/.python-project-generator/templates).
- Forward optional templates_cache_dir from ProjectGenerator.
- Add tests for default path, injected temp dir, and forwarding.

Closes #36
- Add frozen _FeatureRemovalRule entries and _FEATURE_REMOVAL_POLICY
- Drive _remove_unwanted_features from the rule table only
- Preserve patterns, dirs, order, and features.get defaults

Closes #37
Import Union used by TemplateManager and ProjectGenerator type annotations to restore test collection.
Introduce _ProjectGenerationContext to group repeated internal generation parameters and pass context through core helper methods while preserving public API behavior.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant