RustPython / Parser

MIT License
77 stars 29 forks source link

Add `format` and `cformat` modules from `RustPython` #24

Closed MichaReiser closed 1 year ago

MichaReiser commented 1 year ago

This PR moves the format and cformat modules fromRustPython into the new format crate. I'm not sure if this is the right crate to add. Please let me know if I should move it to another crate and/or add it behind a feature flag.

The format implementation has an optimized path for BorrowedStr. I kept that path by introducing a new CharLen trait that BorrowedStr can implement in RustPython.

The goal of this is that format and cformat are the last two modules from RustPython that ruff depends on. Moving them into this repository would allow us to cut that dependency.

youknowone commented 1 year ago

I feel a bit awkward to put format functions to parser directory. But that will be fine if it helps to maintaining Ruff in practice. rustpython-common has too many dependencies to handling platform/threading stuff. To make future contributors not being confused, could you add comments to format.rs and cformat.rs that it doesn't look like parser component but added to support common parser user scenario?

MichaReiser commented 1 year ago

I feel a bit awkward to put format functions to parser directory. But that will be fine if it helps to maintaining Ruff in practice. rustpython-common has too many dependencies to handling platform/threading stuff. To make future contributors not being confused, could you add comments to format.rs and cformat.rs that it doesn't look like parser component but added to support common parser user scenario?

I understand. Would it help if we move the logic into a new rustpython-format crate?

youknowone commented 1 year ago

Either way will be good to me.

MichaReiser commented 1 year ago

I added a new crate and updated the repository URLs.

youknowone commented 1 year ago

Thank you!