# -*- coding: utf-8 -*-
import sys, os, re, yaml
from datetime import date

def load_properties(filepath, sep='=', comment_char='#'):
    """
    Read the file passed as parameter as a properties file.
    """
    props = {}
    with open(filepath, 'rt') as f:
        for line in f:
            l = line.strip()
            if l and not l.startswith(comment_char):
                key_value = l.split(sep)
                key = key_value[0].strip()
                value = sep.join(key_value[1:]).strip().strip('"')
                props[key] = value
    return props

def load_yaml(filepath):
    with open(filepath, 'r') as f:
        return yaml.load(f)

# Load the gradle.properties and dependencies.yml.
rootDir = os.path.dirname(os.path.abspath(__file__)) + '/../../..'
properties = load_properties(rootDir + '/gradle.properties')
dependencies = load_yaml(rootDir + '/dependencies.yml')

# Set the basic project information.
project = 'Armeria'
project_short = 'Armeria'
copyright = properties['inceptionYear'] + '-' + str(date.today().year) + ', LINE Corporation'

# Set the project version and release.
# Use the last known stable release if the current version ends with '-SNAPSHOT'.
if re.match(r'^.*-SNAPSHOT$', properties['version']):
    release = '0.53.0'
else:
    release = properties['version']
version = re.match(r'^[0-9]+\.[0-9]+', release).group(0)

# Export the loaded properties and some useful values into epilogs
rst_epilog = '\n'
rst_epilog += '.. |baseurl| replace:: https://line.github.io/armeria/\n'
for k in properties.keys():
    v = properties[k]
    if k in [ 'release', 'version' ]:
        continue
    rst_epilog += '.. |' + k + '| replace:: ' + v + '\n'
for groupId in dependencies.keys():
    for artifactId in dependencies[groupId]:
        k = groupId + ':' + artifactId + ':version'
        v = dependencies[groupId][artifactId]['version']
        rst_epilog += '.. |' + k + '| replace:: ' + v + '\n'
rst_epilog += '\n'

needs_sphinx = '1.0'
extensions = ['sphinx.ext.autodoc']
templates_path = ['_templates']
source_suffix = '.rst'
source_encoding = 'utf-8-sig'
master_doc = 'index'
exclude_trees = ['.build']
add_function_parentheses = True
pygments_style = 'tango'
master_doc = 'index'

sys.path.append(os.path.abspath('_themes'))
html_theme = 'sphinx_rtd_theme'
html_theme_path = ['_themes']
html_short_title = project_short
html_static_path = ['_static']
html_use_index = True
html_show_sourcelink = False
htmlhelp_basename = project_short

# -*- coding: utf-8 -*-
import sys, os, re, yaml
from datetime import date

def load_properties(filepath, sep='=', comment_char='#'):
    """
    Read the file passed as parameter as a properties file.
    """
    props = {}
    with open(filepath, 'rt') as f:
        for line in f:
            l = line.strip()
            if l and not l.startswith(comment_char):
                key_value = l.split(sep)
                key = key_value[0].strip()
                value = sep.join(key_value[1:]).strip().strip('"')
                props[key] = value
    return props

def load_yaml(filepath):
    with open(filepath, 'r') as f:
        return yaml.load(f)

# Load the gradle.properties and dependencies.yml.
rootDir = os.path.dirname(os.path.abspath(__file__)) + '/../../..'
properties = load_properties(rootDir + '/gradle.properties')
dependencies = load_yaml(rootDir + '/dependencies.yml')

# Set the basic project information.
project = 'Armeria'
project_short = 'Armeria'
copyright = properties['inceptionYear'] + '-' + str(date.today().year) + ', LINE Corporation'

# Set the project version and release.
# Use the last known stable release if the current version ends with '-SNAPSHOT'.
if re.match(r'^.*-SNAPSHOT$', properties['version']):
    release = '0.53.1'
else:
    release = properties['version']
version = re.match(r'^[0-9]+\.[0-9]+', release).group(0)

# Export the loaded properties and some useful values into epilogs
rst_epilog = '\n'
rst_epilog += '.. |baseurl| replace:: https://line.github.io/armeria/\n'
for k in properties.keys():
    v = properties[k]
    if k in [ 'release', 'version' ]:
        continue
    rst_epilog += '.. |' + k + '| replace:: ' + v + '\n'
for groupId in dependencies.keys():
    for artifactId in dependencies[groupId]:
        k = groupId + ':' + artifactId + ':version'
        v = dependencies[groupId][artifactId]['version']
        rst_epilog += '.. |' + k + '| replace:: ' + v + '\n'
rst_epilog += '\n'

needs_sphinx = '1.0'
extensions = ['sphinx.ext.autodoc']
templates_path = ['_templates']
source_suffix = '.rst'
source_encoding = 'utf-8-sig'
master_doc = 'index'
exclude_trees = ['.build']
add_function_parentheses = True
pygments_style = 'tango'
master_doc = 'index'

sys.path.append(os.path.abspath('_themes'))
html_theme = 'sphinx_rtd_theme'
html_theme_path = ['_themes']
html_short_title = project_short
html_static_path = ['_static']
html_use_index = True
html_show_sourcelink = False
htmlhelp_basename = project_short

Update the project version to 0.54.0-SNAPSHOT