Skip to content

Commit d2c9e55

Browse files
committed
Formatting
1 parent 78400ed commit d2c9e55

File tree

7 files changed

+32
-26
lines changed

7 files changed

+32
-26
lines changed

logya/core.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,5 +113,5 @@ def update_collections(self, doc: dict):
113113
'docs': [doc],
114114
'title': value,
115115
'template': coll['template'],
116-
'url': url
116+
'url': url,
117117
}

logya/docparser.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def parse(content, content_type=None):
1616
header_start = lines.index('---') + 1
1717
header_end = lines[header_start:].index('---') + 1
1818
header = '\n'.join(lines[header_start:header_end])
19-
body = '\n'.join(lines[header_end + 1:]).strip()
19+
body = '\n'.join(lines[header_end + 1 :]).strip()
2020
parsed = load(header, Loader=Loader) # noqa: S506
2121

2222
# Parse body if not HTML/XML.
@@ -26,8 +26,9 @@ def parse(content, content_type=None):
2626
extensions=[
2727
'markdown.extensions.attr_list',
2828
'markdown.extensions.def_list',
29-
'markdown.extensions.fenced_code'
30-
])
29+
'markdown.extensions.fenced_code',
30+
],
31+
)
3132

3233
parsed['body'] = body
3334
return parsed

logya/main.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,29 @@
1010
def main():
1111
parent = argparse.ArgumentParser(add_help=False)
1212
parent.add_argument('--verbose', '-v', action='store_true', help='Print info messages during execution.')
13-
parent.add_argument('--dir-site', '-d', default='.', help='Path to site directory, absolute or relative to current working directory.')
13+
parent.add_argument(
14+
'--dir-site',
15+
'-d',
16+
default='.',
17+
help='Path to site directory, absolute or relative to current working directory.',
18+
)
1419

1520
parser = argparse.ArgumentParser(description='Logya a static site generator.')
1621
parser.add_argument('--version', '-V', action='version', version=__version__)
1722
subparsers = parser.add_subparsers()
1823

1924
# create a basic site with the given name
20-
p_create = subparsers.add_parser('create', parents=[parent], help='Create a starter site in the specified directory.')
25+
p_create = subparsers.add_parser(
26+
'create', parents=[parent], help='Create a starter site in the specified directory.'
27+
)
2128
p_create.add_argument('name', help='name of the directory to create.')
2229
p_create.set_defaults(func=create)
2330
p_create.add_argument('--site', '-s', default='base', help='Name one of the available sites.')
2431

2532
# generate a site in public directory, generate and gen sub commands do the same
26-
p_generate = subparsers.add_parser('generate', aliases=('gen',), parents=[parent], help='Generate site in public directory.')
33+
p_generate = subparsers.add_parser(
34+
'generate', aliases=('gen',), parents=[parent], help='Generate site in public directory.'
35+
)
2736
p_generate.set_defaults(func=generate)
2837
hlp_keep = 'Keep existing `public` directory, by default it is removed.'
2938
p_generate.add_argument('--keep', '-k', action='store_true', default=False, help=hlp_keep)

logya/template.py

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
import sys
12
from datetime import datetime
23
from operator import itemgetter
34
from pathlib import Path
45
from string import ascii_lowercase
5-
import sys
66
from typing import Any
77

88
from jinja2 import Environment, FileSystemLoader
@@ -13,15 +13,13 @@
1313
env = Environment(
1414
autoescape=False, # noqa: S701 # Disable autoescaping to allow raw HTML in templates.
1515
lstrip_blocks=True,
16-
trim_blocks=True
16+
trim_blocks=True,
1717
)
1818

1919

2020
def _alpha_index(
21-
items: list,
22-
non_ascii_key: str = '_',
23-
sort_attr: str = 'title',
24-
sort_order: str = 'ascending') -> dict:
21+
items: list, non_ascii_key: str = '_', sort_attr: str = 'title', sort_order: str = 'ascending'
22+
) -> dict:
2523
"""Return an alphabetical index for a list of dicts. All strings that do not start with an ASCII letter are stored
2624
in `non_ascii_key`.
2725
"""
@@ -35,7 +33,7 @@ def _alpha_index(
3533
key = non_ascii_key
3634
index[key] = [*index.get(key, []), item]
3735

38-
reverse = (sort_order != 'ascending')
36+
reverse = sort_order != 'ascending'
3937
keys = sorted(index.keys(), reverse=reverse)
4038
return {key: sorted(index[key], key=itemgetter(sort_attr)) for key in keys}
4139

@@ -80,7 +78,7 @@ def _get_docs(L, url: str, sort_attr: str = 'created', sort_order: str = 'descen
8078
if doc_url.startswith(url):
8179
docs.append(content['doc'])
8280

83-
reverse = (sort_order == 'descending')
81+
reverse = sort_order == 'descending'
8482
return sorted((d for d in docs if sort_attr in d), key=lambda item: _sort_docs(item, sort_attr), reverse=reverse)
8583

8684

@@ -126,4 +124,4 @@ def render(variables: dict) -> str:
126124
try:
127125
return env.get_template(variables['template']).render(variables)
128126
except TypeError as err:
129-
sys.exit(f'Error rendering: {variables}\n{err}\nExiting.')
127+
sys.exit(f'Error rendering: {variables}\n{err}\nExiting...')

logya/util.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from string import punctuation, whitespace
55
from typing import NamedTuple
66

7-
from yaml import dump, load, YAMLError
7+
from yaml import YAMLError, dump, load
88

99
try:
1010
from yaml import CDumper as Dumper
@@ -17,6 +17,7 @@
1717
forbidden = (set(punctuation) - set('+-_.,@')) | set(whitespace)
1818
re_forbidden = re.compile(f'[{re.escape("".join(forbidden))}]+')
1919

20+
2021
# For accessing site paths.
2122
class Paths(NamedTuple):
2223
root: Path
@@ -36,6 +37,7 @@ def f(*args, **kwargs):
3637
if key not in mapping:
3738
mapping[key] = func(*args, **kwargs)
3839
return mapping[key]
40+
3941
return f
4042

4143

@@ -51,8 +53,7 @@ def load_yaml(text: str) -> dict:
5153
try:
5254
return load(text, Loader=Loader) # noqa: S506
5355
except YAMLError as err:
54-
sys.exit(f'Error loading YAML:\n{text}\n{err}')
55-
56+
sys.exit(f'Error loading YAML:\n{text}\n{err}\nExiting...')
5657

5758

5859
def paths(dir_site: str) -> Paths:
@@ -62,7 +63,7 @@ def paths(dir_site: str) -> Paths:
6263
content=root.joinpath('content'),
6364
templates=root.joinpath('templates'),
6465
static=root.joinpath('static'),
65-
public=root.joinpath('public')
66+
public=root.joinpath('public'),
6667
)
6768

6869

setup.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,9 @@
3737
'Programming Language :: Python :: 3.9',
3838
'Topic :: Internet :: WWW/HTTP :: Dynamic Content :: News/Diary',
3939
'Topic :: Internet :: WWW/HTTP :: Site Management',
40-
'Topic :: Text Processing :: Markup :: HTML'
40+
'Topic :: Text Processing :: Markup :: HTML',
4141
],
42-
entry_points={
43-
'console_scripts': [
44-
'logya = logya.main:main'
45-
]
46-
},
42+
entry_points={'console_scripts': ['logya = logya.main:main']},
4743
test_suite='tests',
4844
tests_require=['pytest', 'tox'],
4945
)

tests/test_template.py

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
env_globals = logya.template.env.globals
88
env_filters = logya.template.env.filters
99

10+
1011
@pytest.fixture
1112
def L():
1213
L = logya.core.Logya(dir_site='logya/sites/docs/')

0 commit comments

Comments
 (0)