Skip to content

Commit dac6017

Browse files
committed
switch to ruff for linting
1 parent c57b009 commit dac6017

File tree

7 files changed

+194
-171
lines changed

7 files changed

+194
-171
lines changed

pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ homepage = "https://sphinxcontribdatatemplates.readthedocs.io/en/latest/"
3737
repository = "http://github.com/sphinx-contrib/datatemplates"
3838

3939
[project.optional-dependencies]
40-
linter = ["flake8"]
40+
linter = ["ruff"]
4141
test = ["pytest", "beautifulsoup4"]
4242
build = ["twine"]
4343

@@ -62,7 +62,8 @@ features = ["test", "linter", "build"]
6262
dependencies = ["check-python-versions"]
6363
[tool.hatch.envs.test.scripts]
6464
test = "pytest tests"
65-
lint = "flake8 sphinxcontrib"
65+
lint = ["ruff check sphinxcontrib", "ruff format --check sphinxcontrib"]
66+
lint-fix = ["ruff format sphinxcontrib"]
6667
pkglint = [
6768
"hatch build",
6869
"twine check dist/*.tar.gz",

sphinxcontrib/datatemplates/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77

88

99
def setup(app):
10-
LOG.info('initializing sphinxcontrib.datatemplates')
11-
app.add_directive('datatemplate', directive.DataTemplateLegacy)
10+
LOG.info("initializing sphinxcontrib.datatemplates")
11+
app.add_directive("datatemplate", directive.DataTemplateLegacy)
1212
app.add_domain(domain.DataTemplateDomain)
1313

1414
return {
15-
'version': version.__version__,
16-
'parallel_read_safe': True,
17-
'parallel_write_safe': True,
15+
"version": version.__version__,
16+
"parallel_read_safe": True,
17+
"parallel_write_safe": True,
1818
}

sphinxcontrib/datatemplates/cli.py

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -14,50 +14,50 @@
1414
def main():
1515
parser = argparse.ArgumentParser()
1616
parser.add_argument(
17-
'--config-file',
18-
help='the path to conf.py',
17+
"--config-file",
18+
help="the path to conf.py",
1919
)
2020
subparsers = parser.add_subparsers(
21-
title='commands',
22-
description='valid commands',
23-
dest='command',
21+
title="commands",
22+
description="valid commands",
23+
dest="command",
2424
)
2525

2626
do_render = subparsers.add_parser(
27-
'render',
28-
help='render a template to stdout',
27+
"render",
28+
help="render a template to stdout",
2929
)
3030
do_render.add_argument(
31-
'--option',
32-
'-o',
33-
action='append',
31+
"--option",
32+
"-o",
33+
action="append",
3434
default=[],
35-
help='options given as key:value passed through to loader and template'
35+
help="options given as key:value passed through to loader and template",
3636
)
3737
do_render.add_argument(
38-
'template',
39-
help='the path to the template file',
38+
"template",
39+
help="the path to the template file",
4040
)
4141
do_render.add_argument(
42-
'source',
43-
help='the path to the data file',
42+
"source",
43+
help="the path to the data file",
4444
)
4545
do_render.set_defaults(func=render)
4646

4747
do_dump = subparsers.add_parser(
48-
'dump',
49-
help='dump the data to stdout without a template',
48+
"dump",
49+
help="dump the data to stdout without a template",
5050
)
5151
do_dump.add_argument(
52-
'--option',
53-
'-o',
54-
action='append',
52+
"--option",
53+
"-o",
54+
action="append",
5555
default=[],
56-
help='options given as key:value passed through to loader and template'
56+
help="options given as key:value passed through to loader and template",
5757
)
5858
do_dump.add_argument(
59-
'source',
60-
help='the path to the data file',
59+
"source",
60+
help="the path to the data file",
6161
)
6262
do_dump.set_defaults(func=dump)
6363

@@ -69,7 +69,7 @@ def main():
6969

7070
conf = {}
7171
if args.config_file:
72-
with io.open(args.config_file, 'r', encoding='utf-8-sig') as f:
72+
with io.open(args.config_file, "r", encoding="utf-8-sig") as f:
7373
config_body = f.read()
7474
exec(config_body, conf)
7575

@@ -82,58 +82,58 @@ def _parse_options(options):
8282
# treat the option as a flag.
8383
results = {}
8484
for opt in options:
85-
if ':' in opt:
86-
k, _, v = opt.partition(':')
85+
if ":" in opt:
86+
k, _, v = opt.partition(":")
8787
else:
8888
k = opt
8989
v = True
90-
results[k.replace('-', '_')] = v
90+
results[k.replace("-", "_")] = v
9191
return results
9292

9393

9494
def render(args, conf):
9595
conf.update(_parse_options(args.option))
96-
conf.update({
97-
"source": args.source,
98-
"template": args.template,
99-
"absolute_resolved_path": os.path.abspath(args.source)
100-
})
96+
conf.update(
97+
{
98+
"source": args.source,
99+
"template": args.template,
100+
"absolute_resolved_path": os.path.abspath(args.source),
101+
}
102+
)
101103

102104
load = loaders.loader_for_source(args.source)
103105
if load is None:
104-
print('Could not find loader for {}'.format(args.source))
106+
print("Could not find loader for {}".format(args.source))
105107
return 1
106108

107-
with io.open(args.template, 'r', encoding='utf-8-sig') as f:
109+
with io.open(args.template, "r", encoding="utf-8-sig") as f:
108110
template_body = f.read()
109111

110112
template = jinja2.Template(template_body)
111113
with load(**conf) as data:
112114
rendered = template.render(
113115
make_list_table=helpers.make_list_table,
114-
make_list_table_from_mappings=helpers.
115-
make_list_table_from_mappings,
116+
make_list_table_from_mappings=helpers.make_list_table_from_mappings,
116117
data=data,
117-
**conf
118+
**conf,
118119
)
119120
print(rendered)
120121

121122

122123
def dump(args, conf):
123124
conf.update(_parse_options(args.option))
124-
conf.update({
125-
"source": args.source,
126-
"absolute_resolved_path": os.path.abspath(args.source)
127-
})
125+
conf.update(
126+
{"source": args.source, "absolute_resolved_path": os.path.abspath(args.source)}
127+
)
128128

129129
load = loaders.loader_for_source(args.source)
130130
if load is None:
131-
print('Could not find loader for {}'.format(args.source))
131+
print("Could not find loader for {}".format(args.source))
132132
return 1
133133

134134
with load(**conf) as data:
135135
pprint.pprint(data)
136136

137137

138-
if __name__ == '__main__':
138+
if __name__ == "__main__":
139139
main()

0 commit comments

Comments
 (0)