Skip to content

refactor: add write_job_sh helper to PEcAn.utils to reduce duplicated job.sh logic#3921

Open
KrupaShah20 wants to merge 18 commits intoPecanProject:developfrom
KrupaShah20:fix/job-sh-shared-helper
Open

refactor: add write_job_sh helper to PEcAn.utils to reduce duplicated job.sh logic#3921
KrupaShah20 wants to merge 18 commits intoPecanProject:developfrom
KrupaShah20:fix/job-sh-shared-helper

Conversation

@KrupaShah20
Copy link
Copy Markdown

@KrupaShah20 KrupaShah20 commented Apr 7, 2026

Summary

Closes #3887

This PR adds a shared helper function write_job_sh() to PEcAn.utils
and refactors all 17 model couplers to use it instead of duplicated
job.sh writing logic.

Problem

Every write.config.* function duplicated these same lines:

  • writeLines(jobsh, con = file.path(...))
  • Sys.chmod(file.path(...))

This pattern was repeated across 17 different model packages making
the codebase harder to maintain and extend.

Solution

  • Added base/utils/R/write_job_sh.R with a fully documented helper function
  • Refactored all 17 model couplers to use PEcAn.utils::write_job_sh()
  • Added unit tests in base/utils/tests/testthat/test.write_job_sh.R
  • Maintained backward compatibility throughout

Models Refactored

template, sipnet, rothc, sibcasa, ed, ed2-restart, fates, gday,
jules, ldndc, linkages, lpjguess, maat, maespa, peprmt, preles, stics

Testing

Added unit tests covering:

  • File creation verification
  • File content correctness
  • chmod parameter behavior

@github-actions github-actions bot added the tests label Apr 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

write.config.* functions duplicate job.sh setup logic — candidate for shared helper

1 participant