mirror of
https://github.com/astral-sh/uv.git
synced 2025-11-03 13:14:41 +00:00
This PR tweaks uv to support reading `requirements.txt` regardless of whether it is encoded as UTF-8 or UTF-16. This is particularly relevant on Windows where `uv pip freeze > requirements.txt` will likely write a UTF-16 encoded `requirements.txt` file. There is some discussion on #1666 where it's suggested that perhaps we should explicitly not support this. I didn't see that until I had already put this PR together, but even so, I think it's worth considering this. UTF-16 is predominant on Windows. It is very easy to produce a UTF-16 encoded file. Moreover, there is an easy and well specified way to recognize and transcode UTF-16 encoded data to UTF-8. I think the downside of this is that it could encourage the use UTF-16 encoded `requirements.txt` files *in addition* to UTF-8 encoded files, and it would probably be nice to converge and standardize on one encoding. One possible alternative to this PR is that we provide a better error message. Another alternative is to ensure that a `-o/--output` flag exists for all commands (neither `uv pip freeze` nor `pip freeze` have such a flag) so that users can always write output to a file without relying on their environment's piping behavior. (Although this last alternative seems a little sad to me.) It's also worth noting the [PEP-0508] doesn't seem to mention file encoding at all. So I think from a "do the standards allow this" perspective, this change is OK. Finally, `pip` itself seems to work with UTF-16 encoded `requirements.txt` files. I think I personally overall lean towards supporting UTF-16 for `requirements.txt` files. In part because I think it smoothes out the UX a little bit, in part because there is no obvious specification (that I'm aware of) that mandates that these files are UTF-8, and finally in part because `pip` supports it too. Fixes #1666, Fixes #2276 [PEP-0508]: https://peps.python.org/pep-0508/ |
||
|---|---|---|
| .. | ||
| src | ||
| test-data/requirements-txt | ||
| Cargo.toml | ||