Skip to content
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

Closed
qwcode opened this issue Jan 20, 2014 · 6 comments
Closed

why "find_version"? #1

qwcode opened this issue Jan 20, 2014 · 6 comments

Comments

@qwcode
Copy link
Contributor

qwcode commented Jan 20, 2014

why "find_version" (that parses the file) vs just importing your package and using package.__version__.

I'm honestly unclear on that myself.

@pfmoore
Copy link
Member

pfmoore commented Jan 20, 2014

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

@jcjf
Copy link

jcjf commented Jan 23, 2014

Is it necessarily the case that init.py will be Latin-1 encoded? The version string itself will be Latin-1 nonetheless.

@pfmoore
Copy link
Member

pfmoore commented Jan 23, 2014

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.

@pfmoore
Copy link
Member

pfmoore commented Jan 23, 2014

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.

@jcjf
Copy link

jcjf commented Jan 23, 2014

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.

@qwcode qwcode closed this as completed Feb 23, 2014
@qwcode
Copy link
Contributor Author

qwcode commented Feb 23, 2014

I added a link to the pypa discussion in the comment above find_version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants