Skip to content

Commit b907ff2

Browse files
committed
Merge branch 'release/v0.2.5'
2 parents ada83e6 + bdc4133 commit b907ff2

5 files changed

Lines changed: 138 additions & 20 deletions

File tree

aku/aku.py

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -130,57 +130,56 @@ def run(self, namespace: Namespace = None):
130130
if isinstance(namespace, Namespace):
131131
namespace = namespace.__dict__
132132

133-
curry, literal = {}, {}
133+
partial, literal = {}, {}
134134
for key, value in namespace.items():
135135

136-
curry_co = curry
136+
partial_co = partial
137137
literal_co = literal
138138
*names, key = key.split('.')
139139
for name in names:
140-
curry_co = curry_co.setdefault(name, {})
140+
partial_co = partial_co.setdefault(name, {})
141141
literal_co = literal_co.setdefault(name, {})
142142
if key == AKU_FN:
143-
curry_co[key], literal_co[key] = value
143+
partial_co[key], literal_co[key] = value
144144
else:
145-
curry_co[key] = literal_co[key] = value
145+
partial_co[key] = literal_co[key] = value
146146

147-
def recur_curry(item):
147+
def recur_partial(item):
148148
if isinstance(item, dict):
149149
if AKU_FN in item:
150150
func = item.pop(AKU_FN)
151-
kwargs = {k: recur_curry(v) for k, v in item.items()}
151+
kwargs = {k: recur_partial(v) for k, v in item.items()}
152152
return functools.partial(func, **kwargs)
153153
else:
154-
return {k: recur_curry(v) for k, v in item.items()}
154+
return {k: recur_partial(v) for k, v in item.items()}
155155
else:
156156
return item
157157

158-
def abbreviate_literal(item):
158+
def recur_literal(item):
159159
out, keys, values = {}, [], []
160160

161-
def recur(prefixes, k, v):
161+
def recur(prefixes, domain, v):
162162
nonlocal keys, values
163163

164164
if isinstance(v, dict):
165165
for x, y in v.items():
166166
if x == AKU_FN:
167-
out['-'.join(prefixes[1:] + (k,))] = y
168-
elif k.endswith('_'):
169-
recur(prefixes + (k[:-1],), x, y)
167+
out['-'.join((*prefixes[1:], domain.removesuffix('_')))] = y
168+
elif domain.endswith('_'):
169+
recur(prefixes + (domain.removesuffix('_'),), x, y)
170170
else:
171171
recur(prefixes, x, y)
172172
else:
173-
out['-'.join(prefixes[1:] + (k,))] = v
173+
out['-'.join(prefixes + (domain,))] = v
174174

175175
recur((), '', item)
176176
return out
177177

178-
curry = recur_curry(curry)
179-
literal = abbreviate_literal(literal)
178+
partial = recur_partial(partial)
180179

181-
assert len(curry) == 1
182-
for _, fn in curry.items():
180+
assert len(partial) == 1
181+
for _, fn in partial.items():
183182
if inspect.getfullargspec(fn).varkw is None:
184183
return fn()
185184
else:
186-
return fn(**{AKU: literal})
185+
return fn(**{AKU: recur_literal(literal)})

cliff.toml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# configuration file for git-cliff (0.1.0)
2+
3+
[changelog]
4+
# changelog header
5+
header = """
6+
# Changelog\n
7+
All notable changes to this project will be documented in this file.\n
8+
"""
9+
# template for the changelog body
10+
# https://tera.netlify.app/docs/#introduction
11+
body = """
12+
{% if version %}\
13+
## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }}
14+
{% else %}\
15+
## [unreleased]
16+
{% endif %}\
17+
{% for group, commits in commits | group_by(attribute="group") %}
18+
### {{ group | upper_first }}
19+
{% for commit in commits %}
20+
- {% if commit.breaking %}[**breaking**] {% endif %}{{ commit.message | upper_first }}\
21+
{% endfor %}
22+
{% endfor %}\n
23+
"""
24+
# remove the leading and trailing whitespace from the template
25+
trim = true
26+
# changelog footer
27+
footer = """
28+
<!-- generated by git-cliff -->
29+
"""
30+
31+
[git]
32+
# parse the commits based on https://www.conventionalcommits.org
33+
conventional_commits = true
34+
# filter out the commits that are not conventional
35+
filter_unconventional = true
36+
# process each line of a commit as an individual commit
37+
split_commits = false
38+
# regex for preprocessing the commit messages
39+
commit_preprocessors = [
40+
{ pattern = '\((\w+\s)?#([0-9]+)\)', replace = "([#${2}](https://github.com/orhun/git-cliff/issues/${2}))"},
41+
]
42+
# regex for parsing and grouping commits
43+
commit_parsers = [
44+
{ message = "^feat", group = "Features"},
45+
{ message = "^fix", group = "Bug Fixes"},
46+
{ message = "^doc", group = "Documentation"},
47+
{ message = "^perf", group = "Performance"},
48+
{ message = "^refactor", group = "Refactor"},
49+
{ message = "^style", group = "Styling"},
50+
{ message = "^test", group = "Testing"},
51+
{ message = "^chore\\(release\\): prepare for", skip = true},
52+
{ message = "^chore", group = "Miscellaneous Tasks"},
53+
{ body = ".*security", group = "Security"},
54+
]
55+
# filter out the commits that are not matched by commit parsers
56+
filter_commits = false
57+
# glob pattern for matching git tags
58+
tag_pattern = "v[0-9]*"
59+
# regex for skipping tags
60+
skip_tags = "v0.1.0-beta.1"
61+
# regex for ignoring tags
62+
ignore_tags = ""
63+
# sort the tags chronologically
64+
date_order = false
65+
# sort the commits inside sections by oldest/newest order
66+
sort_commits = "oldest"

examples/reduplicated.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from typing import Type
2+
3+
from aku import Aku
4+
5+
app = Aku()
6+
7+
8+
def foo(name: str = 'first'):
9+
print(f'{foo.__name__}.name => {name}')
10+
11+
12+
def bar(name: str = 'second'):
13+
print(f'{bar.__name__}.name => {name}')
14+
15+
16+
def baz(name: str = 'third'):
17+
print(f'{baz.__name__}.name => {name}')
18+
19+
20+
@app.option
21+
def reduplicated(fn1_: Type[foo] = foo, fn2_: Type[bar] = bar, fn3: Type[baz] = baz, **kwargs):
22+
print(kwargs['@aku'])
23+
fn1_()
24+
fn2_()
25+
fn3()
26+
27+
28+
if __name__ == '__main__':
29+
app.run()

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
setup(
66
name=name,
77
description='An interactive annotation-driven ArgumentParser generator',
8-
version='0.2.4',
8+
version='0.2.5',
99
packages=[package for package in find_packages() if package.startswith(name)],
1010
url='https://github.com/speedcell4/aku',
1111
license='MIT',

tests/assertion.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
def assert_equal(actual, excepted):
2+
if isinstance(excepted, list):
3+
assert isinstance(actual, list)
4+
for a, e in zip(actual, excepted):
5+
assert_equal(a, e)
6+
7+
elif isinstance(excepted, tuple):
8+
assert isinstance(actual, tuple)
9+
for a, e in zip(actual, excepted):
10+
assert_equal(a, e)
11+
12+
elif isinstance(excepted, (set, frozenset)):
13+
assert isinstance(actual, (set, frozenset))
14+
assert frozenset(actual) == frozenset(excepted), f'{frozenset(actual)} != {frozenset(excepted)}'
15+
16+
elif isinstance(excepted, dict):
17+
assert isinstance(actual, dict)
18+
assert_equal(actual=frozenset(actual.keys()), excepted=frozenset(excepted.keys()))
19+
20+
for key in excepted.keys():
21+
assert_equal(actual=actual[key], excepted=excepted[key])
22+
23+
else:
24+
assert actual == excepted, f'{actual} != {excepted}'

0 commit comments

Comments
 (0)