-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
why "find_version"? #1
Comments
There was a big thread about precisely this on pypa-dev. I went with the recommendation people made there, although I can't say I fully followed all of the points made. The thread is at https://groups.google.com/d/topic/pypa-dev/0PkjVpcxTzQ/discussion and Carl's post that recommended not importing is at https://groups.google.com/d/msg/pypa-dev/0PkjVpcxTzQ/lHp1C9KuayMJ |
Is it necessarily the case that init.py will be Latin-1 encoded? The version string itself will be Latin-1 nonetheless. |
No, but who cares? Latin-1 will ensure no decoding errors, and the version string line will be findable. This is a classic case of "don't want to care about encoding". We could look for the encoding token in the file, but that's unnecessarily hard. We could assume ASCII or UTF8, but that runs the risk of failing if we guessed wrong. Probably better would be using ascii, errors="surrogateescape", but that's Python 3 only. Practicality beats purity and all that. |
BTW, that's what the comment "Open in Latin-1 so that we avoid encoding errors." was intended to convey. If you can suggest better wording (without turning it into an essay, that chunk of code is too long for what it does already :-() then that'd be great. |
Thanks for clarifying and the little Python lesson, it makes sense now. The comment describing the intention of the code confused me a little. I haven't really had to workaround encoding problems as my native language is English. I've always just added .encode('utf-8') or decode('utf-8') in Python 3 as needed. |
I added a link to the pypa discussion in the comment above |
why "find_version" (that parses the file) vs just importing your package and using
package.__version__
.I'm honestly unclear on that myself.
The text was updated successfully, but these errors were encountered: