You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by GitBox <gi...@apache.org> on 2020/04/28 01:49:48 UTC

[GitHub] [avro] kojiromike commented on a change in pull request #865: AVRO-2814: Add __version__ to __init__.py (PEP396)

kojiromike commented on a change in pull request #865:
URL: https://github.com/apache/avro/pull/865#discussion_r416268022



##########
File path: lang/py/avro/__init__.py
##########
@@ -19,4 +19,14 @@
 
 from __future__ import absolute_import, division, print_function
 
+import os
+
 __all__ = ['schema', 'io', 'datafile', 'protocol', 'ipc', 'constants', 'timezones', 'codecs']
+
+def LoadResource(name):
+  dir_path = os.path.dirname(__file__)
+  rsrc_path = os.path.join(dir_path, name)
+  with open(rsrc_path, 'r') as f:
+    return f.read()
+
+__version__ = LoadResource('VERSION.txt').strip()

Review comment:
       Consider using [`pkgutil.get_data`](https://docs.python.org/3/library/pkgutil.html) here:
   
   ```
   import pkgutil
   
   __version__ = (pkgutil.get_data(__name__, 'VERSION.txt') or b'0.0.1+unknown').decode().strip()
   ```
   
   pkgutil.get_data pretty much does what your LoadResource does, but it's zip-safe. On the flip side, it returns `Optional[bytes]`, so we need a little code to ensure there's a usable value if VERSION.txt is not found.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org