Update write_pyproject to use toml_edit
Description
This PR updates the write_pyproject to handle existing [tool.pyrefly] sections by allowing the project to be re-initialized. It also fixes a bug where newlines were not properly inserted, depending on the formatting of the existing pyproject.toml file.
Testing Instructions
Run pyrefly init in the following cases and confirm that the initialization looks correct:
- No
pyproject.tomlin the project. - Existing
pyproject.tomlwith no[tool.pyrefly]section. - Existing
pyproject.tomlwith an existing[tool.pyrefly]section.
@pt2302 Thanks so much for the diff! Tagging @MaggieMoss @connernilsen who have more experience with the init and config flows.
@yangdanny97 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.
@yangdanny97 I can't see the Facebook Internal linter warning (https://github.com/facebook/pyrefly/pull/336/checks?check_run_id=42963354645) but if you let me know what it is, I would be glad to address it.
@pt2302 Oh, your cargo changes didn't sync to our internal build tool. I'm not sure if there's a way to get it to work automatically, so we probably just have to go in and make that change when importing it.
Sorry for not checking this sooner, I was out for most of last week 😅
@yangdanny97 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.
Hey @pt2302, are your changes still in progress, or are you ready for review? Just want to check in to make sure I'm not delaying a review if you're ready. Feel free to also hit "Re-request review" on my name under Reviewers on this page when you're ready.
@connernilsen Thanks! I believe that I've addressed your feedback and the PR is now ready for re-review. I've also updated the tests to reflect some of the other changes in functionality since I originally put up the PR, such as making the configs use kebab-case by default (3c7cd487cbdead4466d43f5816eba63eb8ccd546).
@yangdanny97 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.
@connernilsen Thank you for the detailed review and comments! Do you handle merging?
Yep, we'll get this merged.
@yangdanny97 merged this pull request in facebook/pyrefly@0c304693e6a8cc0cb02dee7613544819d49305a8.