version.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. import datetime
  4. import os
  5. import time
  6. from warnings import warn
  7. __author__ = 'cnheider'
  8. __version__ = 0.1
  9. def get_version():
  10. version = os.getenv('VERSION', __version__)
  11. now = datetime.datetime.utcnow()
  12. date_version = now.strftime('%Y%m%d%H%M%S')
  13. #date_version = time.time()
  14. if version:
  15. # Most git tags are prefixed with 'v' (example: v1.2.3) this is
  16. # never desirable for artifact repositories, so we strip the
  17. # leading 'v' if it's present.
  18. version = version[1:] if type(version) is str and version.startswith('v') else version
  19. else:
  20. # Default version is an ISO8601 compiliant datetime. PyPI doesn't allow
  21. # the colon ':' character in its versions, and time is required to allow
  22. # for multiple publications to master in one day. This datetime string
  23. # uses the 'basic' ISO8601 format for both its date and time components
  24. # to avoid issues with the colon character (ISO requires that date and
  25. # time components of a date-time string must be uniformly basic or
  26. # extended, which is why the date component does not have dashes.
  27. #
  28. # Publications using datetime versions should only be made from master
  29. # to represent the HEAD moving forward.
  30. warn(f'Environment variable VERSION is not set, only using datetime: {date_version}')
  31. version = '0.0'
  32. #warn(f'Environment variable VERSION is not set, only using timestamp: {version}')
  33. version = f'{version}.{date_version}'
  34. return version
  35. if __version__ is None:
  36. __version__ = get_version()
  37. _debug = False
  38. @property
  39. def debug():
  40. return _debug