hgvers.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # Copyright 2008 Lime Nest LLC
  2. # Licensed under the Apache License, Version 2.0 (the "License");
  3. # you may not use this file except in compliance with the License.
  4. # You may obtain a copy of the License at
  5. # http://www.apache.org/licenses/LICENSE-2.0
  6. # Unless required by applicable law or agreed to in writing, software
  7. # distributed under the License is distributed on an "AS IS" BASIS,
  8. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. # See the License for the specific language governing permissions and
  10. # limitations under the License.
  11. import re
  12. repo = None
  13. version = None
  14. try:
  15. import hgversion as hgv
  16. except ImportError:
  17. # either we couldn't find hgversion or
  18. # hgversion couldn't find mercurial libraries
  19. pass
  20. else:
  21. repo = hgv.repository # could be None if we're not in an hg repository
  22. if repo is None:
  23. try:
  24. f = open('PKG-INFO')
  25. except IOError:
  26. pass
  27. else:
  28. regex = re.compile('^Version:\s+(\S+)')
  29. for line in f:
  30. mo = regex.match(line)
  31. if mo is not None:
  32. version = mo.group(1)
  33. break
  34. else:
  35. version = hgv.version()
  36. if __name__ == '__main__':
  37. print version