# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import errno
import os
import subprocess
import sys

# Append src directory to path so that autodoc can find the python module
sys.path.append("src")


extensions = [
    'sphinx.ext.autodoc',
    'sphinx.ext.autosummary',
    'sphinx.ext.coverage',
    'sphinx.ext.doctest',
    'sphinx.ext.extlinks',
    'sphinx.ext.ifconfig',
    'sphinx.ext.napoleon',
    'sphinx.ext.todo',
    'sphinx.ext.viewcode',
    'sphinxcontrib.plantuml',
]
if os.getenv('SPELLCHECK'):
    extensions.append('sphinxcontrib.spelling')
    spelling_show_suggestions = True
    spelling_lang = 'en_US'

source_suffix = '.rst'
master_doc = 'index'
project = 'warning-plugin'
year = '2017-2019'
author = 'Bavo Van Achte'
copyright = '{0}, {1}'.format(year, author)

# The full version, including alpha/beta/rc tags.
from setuptools_scm import get_version
version = release = get_version(root="..")
# The short X.Y version.
#version = '.'.join(release.split('.')[:3])

pygments_style = 'trac'
templates_path = ['.']
extlinks = {
    'issue': ('https://github.com/melexis/warnings-plugin/issues/%s', '#'),
    'pr': ('https://github.com/melexis/warnings-plugin/pull/%s', 'PR #'),
}
import sphinx_py3doc_enhanced_theme
html_theme = "sphinx_py3doc_enhanced_theme"
html_theme_path = [sphinx_py3doc_enhanced_theme.get_html_theme_path()]
html_theme_options = {
    'githuburl': 'https://github.com/melexis/warnings-plugin'
}

html_use_smartypants = True
html_last_updated_fmt = '%b %d, %Y'
html_split_index = False
html_sidebars = {
    '**': ['searchbox.html', 'globaltoc.html', 'sourcelink.html'],
}
html_short_title = '%s-%s' % (project, version)

napoleon_use_ivar = True
napoleon_use_rtype = False
napoleon_use_param = False

try:
    plantuml = os.environ['PLANTUML']
except KeyError: # There is no such environment variable. Try to find it in the path
    # Point to plantuml jar file
    # confirm we have plantuml in the path
    if 'nt' in os.name:
        plantuml_path = subprocess.check_output(["where", "/F", "plantuml.jar"])
        if not plantuml_path:
            print("Can't find 'plantuml.jar' file.")
            print("You need to add path to 'plantuml.jar' file to your PATH variable.")
            sys.exit(os.strerror(errno.EPERM))
        plantuml = plantuml_path.decode("utf-8")
        plantuml = plantuml.rstrip('\n\r')
        plantuml = plantuml.replace('"', '')
        plantuml = plantuml.replace('\\', '//')
        plantuml = 'java -jar' + ' ' + plantuml
    else:
        plantuml_path = subprocess.check_output(["whereis", "-u", "plantuml"])
        if not plantuml_path:
            print("Can't find 'plantuml.jar' file.")
            print("You need to add path to 'plantuml.jar' file to your PATH variable.")
            sys.exit(os.strerror(errno.EPERM))

@@ -1762,140 +1762,8 @@
 se%0A%0A
-try:%0A    plantuml = os.environ%5B'PLANTUML'%5D%0Aexcept KeyError: # There is no such environment variable. Try to find it in the path%0A    
 # Po
@@ -1787,20 +1787,16 @@
 ar file%0A
-    
 # confir
@@ -1826,20 +1826,16 @@
 he path%0A
-    
 if 'nt' 
@@ -1846,28 +1846,24 @@
 s.name:%0A    
- 
-   
 plantuml_pat
@@ -1919,36 +1919,32 @@
 tuml.jar%22%5D)%0A    
-   
- 
 if not plantuml_
@@ -1941,36 +1941,32 @@
  plantuml_path:%0A
-    
         print(%22C
@@ -1998,36 +1998,32 @@
 file.%22)%0A        
- 
-   
 print(%22You need 
@@ -2074,36 +2074,32 @@
 ATH variable.%22)%0A
-    
         sys.exit
@@ -2125,20 +2125,16 @@
 EPERM))%0A
-    
     plan
@@ -2170,28 +2170,24 @@
 utf-8%22)%0A    
-  
-  
 plantuml = p
@@ -2209,28 +2209,24 @@
 '%5Cn%5Cr')%0A    
-  
-  
 plantuml = p
@@ -2250,28 +2250,24 @@
 %22', '')%0A    
- 
-   
 plantuml = p
@@ -2294,28 +2294,24 @@
 , '//')%0A    
-   
- 
 plantuml = '
@@ -2342,22 +2342,14 @@
 uml%0A
-    
 else:%0A
-    
     
@@ -2419,20 +2419,16 @@
 tuml%22%5D)%0A
-    
     if n
@@ -2449,28 +2449,24 @@
 th:%0A        
-    
 print(%22Can't
@@ -2490,28 +2490,24 @@
 ar' file.%22)%0A
-    
         prin
@@ -2574,28 +2574,24 @@
 variable.%22)%0A
-    
         sys.

Revert "Search for PLANTUML in os.environ first"