-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
shorter and faster version extraction from __init__.py #2518
Conversation
if you think readability has been tampered too much, I'll make a pull request with this less-pure-but-softer version:
|
No objections from me. 👍 |
Do you have benchmarks? Also, why are we optimizing something that is run at most once by a user (during pip install)? |
It's not optimizing. It's making it simpler. And thus that it's simpler also makes faster. |
if m: | ||
version = m.group(1) | ||
break | ||
version = re.search(r'__version__\s*=\s*[\'"]([^\'"]*)[\'"]', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we're not splitting on line terminators anymore and lazily ejecting when we've found what we're looking for, the regular expression needs to be updated. We want to make sure we don't grab any cruft from a separate line that has version in it.
match
will automatically add the equivalent of ^
to the beginning of the regular expression. search
does not. We don't want anything where there's a line that looks like
# We want __version__ = "some string"
...
__version__ = "2.6.1"
Because we'll get the wrong result. Please fix the expression to check for line beginnings and endings.
Either way, this change is incomplete in its current form. I've left feedback on what is necessary to fix it. |
Yeah, sorry for the cardet, I thought about it and forgot. |
No one asked for you to add anything other than the Thanks for fixing this up. Any further feedback @Lukasa? |
Nope. Fine by me. =) |
The
misled me :) |
shorter and faster version extraction from __init__.py
I misspoke twice then! Sorry for the confusion @deronnax. Thanks for the contribution! 🍰 |
You're welcome :) |
@sigmavirus24 I though it could be improved a bit. Tell me what you think.