1#!/usr/bin/env python3
2
3"""Main CHART code module."""
4
5# Filename where we store version info, to keep it out of git where it causes merging fiddlyness
6VERSIONS_FILENAME = 'VERSIONS'
7
8# Prefix for all version information about the framework
9FRAMEWORK_ID = 'chart'
10
11def version_info():
12 """Look for VERSION files in the framework and project directories.
13
14 These are created by the Dockerfile.
15
16 Or someone could write a script to make them manually for development.
17 """
18 # In python 3.7 there are module level properties so we could re-instate "chart.__version__"
19 # But it's not really worth it as we're retrning a pretty verbose data structure
20 # which is not what someone would really expect from a __version__ attribute.
21 from chart import settings
22 versions_file = settings.CORE_ROOT_DIR.joinpath(VERSIONS_FILENAME)
23 if versions_file.exists():
24 for line in versions_file.open().read().split():
25 yield '{framework}.{prop}'.format(framework=FRAMEWORK_ID, prop=line)
26
27 proj_versions_file = settings.PROJECT_ROOT_DIR.joinpath(VERSIONS_FILENAME)
28 if proj_versions_file.exists():
29 # just make up a name to show - could we use $CHART_REPO_NAME or $CHART_PROJ_NAME
30 # from packaging?
31 projname = settings.APPNAME.lower().replace('-','').replace('_','').partition(' ')[0]
32 for line in proj_versions_file.open().read().split():
33 yield '{proj}.{prop}'.format(proj=projname, prop=line)
34
35
36def project_version():
37 """Do not use, call version_info() instead. Function preserved for RESTAPI compatibility."""
38 return 'not implemented'
39
40def version():
41 """Do not use, call version_info() instead. Function preserved for RESTAPI compatibility."""
42 return 'not implemented'