Conversation
This change allows programs and other packages to do: import typed_ast if typed_ast.version_info < (1, 1): print(typed_ast.__version__) currently the only way to get that version number is by doing import pkg_resources pkg_resources.require('typed-ast')[0].version)
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA). Unfortunately we couldn't find an account corresponding to your GitHub username on bugs.python.org (b.p.o) to verify you have signed the CLA (this might be simply due to a missing "GitHub Name" entry in your b.p.o account settings). This is necessary for legal reasons before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue. Thanks again to your contribution and we look forward to looking at it! |
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.
no changes, just updated Details on b.p.o, CLA had already been signed. Please rerun the bot
Thanks for this PR, and sorry about the long wait for review! We'd prefer to avoid doing manual parsing of the version -- is there some reason you're avoiding importing the file directly? |
It is just my experience that it leads to problems if you import directly. Maybe not in your case now, but if Now you might be sure such a dependency will never happen. and that you will notice, but why run the risk? It is not as if the performance of |
The worry is imagined, but the complexity introduced to avoid this potential future problem is real. Let's do the simple thing (import typed_ast.version). |
I settled on doing the following in all my packages: _version_re = re.compile(r'__version__\s+=\s+(?P<version>.*)')
with open(os.path.join(current_dir, 'retype.py'), 'r', encoding='utf8') as f:
version = _version_re.search(f.read()).group('version')
version = str(ast.literal_eval(version)) This is what Flask, Click and a few other very popular packages are also doing. |
Yes, but that is due to concerns about importing packages that may not exist at runtime. I cant see this happening for typed_ast so I agree with Guido, I see no reason for unnecessary complexity. |
Thanks, that's a nice compromise, and I like that we then won't be
reinventing this particular wheel but just following best practice.
|
@ddfisher I am not sure if I understand where this code goes and what it helps if the version is in a file As my PR already has 2 revisions more than should have been necessary, I suggest you just directly put that code in at some point instead of me proposing another revision, that might not be acceptable because I don't understand where the Don't forget to import |
retype is one of my packages, I just copy-pasta'd the snippet from its setup.py to show how it works. |
I took a swing at it in #48. (Closing in favor of that.) |
This change allows programs and other packages to do:
currently the only way to get that version number is by doing
(pr on mypy, rejected at least partly, because of the difficulty of extracting the typed_ast version number)