-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Simplify version parsing example #571
Conversation
This removes regexp and adds `import os`. File is read in `cp437` because this encoding has no missing code points while converting to `utf-8` string. Only ASCII set is used anyways.
Thanks for doing this, @techtonik, but I find the new one much more difficult to read. Would it be possible to reduce the amount of nesting? |
@theacodes nothing I can think of. It is either flatness or simplicity. For people who haven't learn what a regular expression is, this is already an advantage. |
On the second thought my similar improvement for |
Yeah, let's go with pip's version. |
There's a few changes we should make there IMO like using os.path.join and I think that currently (untested) that'll gives us the the string with quotes, so those have to be trimmed. I'm super short on time, so can't write proper review comments on the PR, sorry! |
@pradyunsg why use |
@theacodes can you explain what encoding is used by |
I honestly have no idea. I don't think it's possible for us to specify a general solution that'll work in every single case, so we should probably just use utf-8 but note that you might need to change it. |
As it's only intended as example code, and it's reading a file that you create yourself, I think it's reasonable to not worry too much about encodings. If you're only supporting Python 3.2+, If you're not comfortable writing your own code based on the supplied example, I'd argue that you should probably be sticking to the simpler technique of just maintaining the version number in Basically, I agree, this change isn't much of an improvement, so I'd prefer to stick with what we have. |
Ok. Let me tell you what happens with this code if it is run on Greek Windows when my version file contains Russian comment. The code from this guide will fail. https://bitbucket.org/techtonik/hexdump/pull-requests/1/since-the-input-file-is-a-specific/diff Needless to say that having a guide with magic that writers themselves don't understand says something about the language. Explicit |
So if you want to use a Russian comment, modify the code to handle it. Just add an explicit encoding to Regarding "writers themselves don't understand", frankly few of us still recall all the bizarre contortions needed for Python 2/3 compatibility. I'd happily say replace |
The problem is that it is very hard to debug, non-intuitive and requires a sacred knowledge that doesn't hold in ones head as this thread shows. Python doesn't give any hints to make the inference process easier.
It is only about Python 3. Python 2 is irrelevant, because it does not autoconvert files with occassional system encoding on reading. Replacing |
The simplest and most appropriate clarification here is to just pass an explicit A comment could also be included saying that builtin |
To avoid problems with unknown encoding, file with __version__ is processed as binary and the final number is converted to string just before the function returns.
Until |
I'm so sorry for letting this PR languish for so long.
I'm not completely comfortable with this. I do like @ncoghlan's suggestion of using |
@theacodes I am not comfortable with undocumented |
Help me understand what undocumented behavior
|
@theacodes the undocumented behavior is what happens if a person left Behind the scenes |
This allows people who use setuptools to maintain project versions in a single place, for example as attributes in their Python source. Closes pypa#1316 Closes pypa/pip#6004 Closes pypa/packaging.python.org#571
I submitted the function to Spent 2 more hours polishing the code that I thought is final. If merged, it would be the most simple way to fetch version string, because I believe |
This removes regexp and adds
import os
.File is read in
cp437
because this encoding has no missing code points while converting toutf-8
string. Only ASCII set is used anyways.