Last active
April 8, 2018 02:13
-
-
Save m-x-k/26fbf4ee032cef3995b7c53c2004602d to your computer and use it in GitHub Desktop.
Python version support
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from pathlib import Path | |
current_dir = os.path.dirname(__file__) | |
version_file_full_path = os.path.join(current_dir, "VERSION.txt") | |
""" | |
Create and obtain version information based on environment variables: | |
* APP_MAJOR_VERSION | |
* APP_BUILD_VERSION | |
""" | |
def get_version(): | |
if Path(version_file_full_path).is_file(): | |
with open(version_file_full_path) as version_file: | |
return version_file.read() | |
else: | |
return "UNKNOWN VERSION" | |
def create_version(): | |
version = "{0}.{1}".format( | |
os.environ.get('APP_MAJOR_VERSION', 0), | |
os.environ.get('APP_BUILD_VERSION', '0') | |
) | |
_create_version_file(version) | |
return version | |
def _create_version_file(version): | |
with open(version_file_full_path, 'w') as version_file: | |
version_file.write(version) | |
__version__ = get_version() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment