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/23 14:32:17 UTC

[GitHub] [avro] masatana opened a new pull request #865: AVRO-2814: Add __version to __init__.py (PEP396)

masatana opened a new pull request #865:
URL: https://github.com/apache/avro/pull/865


   Make sure you have checked _all_ steps below.
   
   ### Jira
   
   - [x] My PR addresses the following [Avro Jira](https://issues.apache.org/jira/browse/AVRO/) issues and references them in the PR title. For example, "AVRO-1234: My Avro PR"
     - https://issues.apache.org/jira/browse/AVRO-2814
   
   ### Tests
   
   - [x] My PR adds the following unit tests
     - lang/py/test/test_init.py
     - lang/py3/test/test_init.py
   
   ### Commits
   
   - [x] My commits all reference Jira issues in their subject lines. In addition, my commits follow the guidelines from "[How to write a good git commit message](https://chris.beams.io/posts/git-commit/)":
     1. Subject is separated from body by a blank line
     1. Subject is limited to 50 characters (not including Jira issue reference)
     1. Subject does not end with a period
     1. Subject uses the imperative mood ("add", not "adding")
     1. Body wraps at 72 characters
     1. Body explains "what" and "why", not "how"
   
   ### Documentation
   
   - [ ] In case of new functionality, my PR adds documentation that describes how to use it.
     - All the public functions and the classes in the PR contain Javadoc that explain what it does
   


----------------------------------------------------------------
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



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

Posted by GitBox <gi...@apache.org>.
masatana commented on a change in pull request #865:
URL: https://github.com/apache/avro/pull/865#discussion_r416704537



##########
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:
       Thanks for the review! I refactored the code with your suggestd code.




----------------------------------------------------------------
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



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

Posted by GitBox <gi...@apache.org>.
masatana commented on pull request #865:
URL: https://github.com/apache/avro/pull/865#issuecomment-621652418


   Thanks @kojiromike !


----------------------------------------------------------------
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



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

Posted by GitBox <gi...@apache.org>.
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



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

Posted by GitBox <gi...@apache.org>.
kojiromike commented on pull request #865:
URL: https://github.com/apache/avro/pull/865#issuecomment-620064783


   I'll try to look at this in depth after work. This kind of change has been on my mind, and I'm happy someone is taking it on. That said, I'm concerned of effects with interacting with the way the avro project copies files like VERSION.txt into the py subdir. So I want to make sure it doesn't get in the way of different folks' workflows.
   
   What I'd _really_ like to do is use a tool like [setuptools-scm](https://pypi.org/project/setuptools-scm/) to derive the version from git and avoid having to modify files outside of version control; however, with Avro's svn history and approach to branching, I never was able to get setuptools-scm to do what I wanted.


----------------------------------------------------------------
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



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

Posted by GitBox <gi...@apache.org>.
masatana commented on pull request #865:
URL: https://github.com/apache/avro/pull/865#issuecomment-619524276


   Thanks @Fokko , I updated my commit.


----------------------------------------------------------------
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



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

Posted by GitBox <gi...@apache.org>.
Fokko commented on pull request #865:
URL: https://github.com/apache/avro/pull/865#issuecomment-619517195


   Looks like an unrelated error, can you pull in latest master @masatana ?


----------------------------------------------------------------
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