Skip to content

Commit

Permalink
ci(typecheck): Add return types for existing methods
Browse files Browse the repository at this point in the history
  • Loading branch information
mrwilson committed Aug 28, 2023
1 parent f805c98 commit bd40e14
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions adr_viewer/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import List, Iterator, Optional, Dict

import glob
from jinja2.loaders import FileSystemLoader
import mistune
Expand All @@ -8,7 +10,7 @@
from bottle import Bottle, run


def extract_statuses_from_adr(page_object):
def extract_statuses_from_adr(page_object) -> Iterator[str]:
status_section = page_object.find('h2', text='Status')

if status_section and status_section.nextSibling:
Expand All @@ -25,20 +27,20 @@ def extract_statuses_from_adr(page_object):
continue


def parse_adr_to_config(path):
def parse_adr_to_config(path) -> Optional[Dict]:
adr_as_html = mistune.markdown(open(path).read())

soup = BeautifulSoup(adr_as_html, features='html.parser')

status = list(extract_statuses_from_adr(soup))
statuses = list(extract_statuses_from_adr(soup))

if any([line.startswith("Amended by") for line in status]):
if any([line.startswith("Amended by") for line in statuses]):
status = 'amended'
elif any([line.startswith("Accepted") for line in status]):
elif any([line.startswith("Accepted") for line in statuses]):
status = 'accepted'
elif any([line.startswith("Superseded by") for line in status]):
elif any([line.startswith("Superseded by") for line in statuses]):
status = 'superseded'
elif any([line.startswith("Proposed") or line.startswith("Pending") for line in status]):
elif any([line.startswith("Proposed") or line.startswith("Pending") for line in statuses]):
status = 'pending'
else:
status = 'unknown'
Expand All @@ -55,7 +57,7 @@ def parse_adr_to_config(path):
return None


def render_html(config, template_dir_override=None):
def render_html(config, template_dir_override=None) -> str:

env = Environment(
loader=PackageLoader('adr_viewer', 'templates') if template_dir_override is None else FileSystemLoader(template_dir_override),
Expand All @@ -67,20 +69,20 @@ def render_html(config, template_dir_override=None):
return template.render(config=config)


def get_adr_files(path):
def get_adr_files(path) -> List[str]:
files = glob.glob(path)
files.sort()
return files


def run_server(content, port):
def run_server(content, port) -> None:
print(f'Starting server at http://localhost:{port}/')
app = Bottle()
app.route('/', 'GET', lambda: content)
run(app, host='localhost', port=port, quiet=True)


def generate_content(path, template_dir_override=None, title=None):
def generate_content(path, template_dir_override=None, title=None) -> str:

files = get_adr_files("%s/*.md" % path)

Expand Down Expand Up @@ -110,7 +112,7 @@ def generate_content(path, template_dir_override=None, title=None):
@click.option('--serve', default=False, help='Serve content at http://localhost:8000/', is_flag=True)
@click.option('--port', default=8000, help='Change port for the server', show_default=True)
@click.option('--template-dir', default=None, help='Template directory.', show_default=True)
def main(adr_path, output, title, serve, port, template_dir):
def main(adr_path, output, title, serve, port, template_dir) -> None:
content = generate_content(adr_path, template_dir, title)

if serve:
Expand Down

0 comments on commit bd40e14

Please sign in to comment.